diff --git a/debian/changelog b/debian/changelog index 34b8df893da005e5c125fa19522f19a6857cc429..b8f489efaa1dcaaccefa776b9bc14d790ee5febb 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,8 +1,10 @@ -python3-sams-classes (1.0.1~1) UNRELEASED; urgency=medium +python3-sams-classes (1.0.1~2) UNRELEASED; urgency=medium * fixed issue #20 "Basis-Pfad (/) bei API über Proxy nicht aufrufbar" + * fixed issue #21 "Unterstützung von anderen HTTP-Methoden als GET innerhalb + einer APP" - -- Lobinger <slobinger@justus.zib.de> Tue, 13 Jun 2017 15:28:43 +0200 + -- Sebastian Lobinger <sebastian.lobinger@zib.de> Wed, 14 Jun 2017 08:36:02 +0200 python3-sams-classes (1.0.0) unstable; urgency=medium diff --git a/sams_classes/sams_app.py b/sams_classes/sams_app.py index 26f203e3d55ce596ae83f9d3f2cd27ca09cfd194..c7e709f6e122f1d6d324918ce72ff5250fc1e0a0 100644 --- a/sams_classes/sams_app.py +++ b/sams_classes/sams_app.py @@ -47,7 +47,8 @@ class SAMSApp: view_func = SAMSApp._get_attr(self.module, view['function']) self.__blueprint.add_url_rule( rule = self._generate_url(urlPart = view.get('url')), endpoint = endpoint, - view_func = view_func) + view_func = view_func, + methods = view.get('methods', ['GET', 'HEAD', 'OPTIONS'])) def __add_proxy_urls(self): i = 0 diff --git a/test/test_sams_app.py b/test/test_sams_app.py index 3f70196207b0805c525f848a77403508b9c7c8c4..d49a68ed39c55eb570e26fb82ffdb48d73c06352 100644 --- a/test/test_sams_app.py +++ b/test/test_sams_app.py @@ -60,18 +60,40 @@ class TestSAMSApp(unittest.TestCase): manifest = { 'default_language': 'en' , 'views': [ - {'url': 'test/do_nothing' - , 'function': 'views.do_nothing'} + {'url': 'test/do_nothing', + 'function': 'views.do_nothing', + 'methods': [ + 'GET', 'POST', 'DELETE', 'PUT', 'UPDATE', 'HEAD', 'PATCH', + 'OPTIONS' + ] + }, + {'url': 'test/do_nothing_defaults', 'function': 'views.do_nothing'} ] } app = SAMSApp(name = 'test', manifest = manifest , langDict = {'en':{}}) flaskApp = Flask(__name__) flaskApp.register_blueprint(app.blueprint) - self.assertGreater(len(list(flaskApp.url_map.iter_rules())), 1) - client = flaskApp.test_client(self) - response = client.get('/test/do_nothing') - self.assertIs(response.status_code, 200) + with self.subTest('test url_map'): + self.assertGreater(len(list(flaskApp.url_map.iter_rules())), 1) + thApp = FlaskInThread(flaskApp, host="localhost", port=5000) + thApp.start() + time.sleep(0.01) + for method in manifest['views'][0]['methods']: + with self.subTest('do_nothing: ' + method): + response = requests.request( + method = method, url = 'http://localhost:5000/test/do_nothing') + self.assertIs(response.status_code, 200) + for method in ('GET', 'HEAD', 'OPTIONS'): + # Check that app follows flask 0.6 default behavior for no methods defined + with self.subTest('do_nothing_default: ' + method): + response = requests.request( + method = method, + url = 'http://localhost:5000/test/do_nothing_defaults') + self.assertIs(response.status_code, 200) + requests.request( + method = 'GET', url = 'http://localhost:5000/shutdown') + time.sleep(0.01) def test_app_lang(self): """App.lang(language) returns dict with requested language / default."""