Skip to content
Snippets Groups Projects
Commit 75dd6460 authored by slobinger's avatar slobinger
Browse files

Merge branch '21-support--http-methods-for-app-urls' into 'master'

Resolve "Unterstützung von anderen HTTP-Methoden als GET innerhalb einer APP"

Closes #21

See merge request !16
parents 6d53c50e 10dc1391
Branches
No related tags found
1 merge request!16Resolve "Unterstützung von anderen HTTP-Methoden als GET innerhalb einer APP"
Pipeline #
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 #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 python3-sams-classes (1.0.0) unstable; urgency=medium
......
...@@ -47,7 +47,8 @@ class SAMSApp: ...@@ -47,7 +47,8 @@ class SAMSApp:
view_func = SAMSApp._get_attr(self.module, view['function']) view_func = SAMSApp._get_attr(self.module, view['function'])
self.__blueprint.add_url_rule( self.__blueprint.add_url_rule(
rule = self._generate_url(urlPart = view.get('url')), endpoint = endpoint, 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): def __add_proxy_urls(self):
i = 0 i = 0
......
...@@ -60,18 +60,40 @@ class TestSAMSApp(unittest.TestCase): ...@@ -60,18 +60,40 @@ class TestSAMSApp(unittest.TestCase):
manifest = { manifest = {
'default_language': 'en' 'default_language': 'en'
, 'views': [ , 'views': [
{'url': 'test/do_nothing' {'url': 'test/do_nothing',
, 'function': 'views.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 app = SAMSApp(name = 'test', manifest = manifest
, langDict = {'en':{}}) , langDict = {'en':{}})
flaskApp = Flask(__name__) flaskApp = Flask(__name__)
flaskApp.register_blueprint(app.blueprint) flaskApp.register_blueprint(app.blueprint)
self.assertGreater(len(list(flaskApp.url_map.iter_rules())), 1) with self.subTest('test url_map'):
client = flaskApp.test_client(self) self.assertGreater(len(list(flaskApp.url_map.iter_rules())), 1)
response = client.get('/test/do_nothing') thApp = FlaskInThread(flaskApp, host="localhost", port=5000)
self.assertIs(response.status_code, 200) 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): def test_app_lang(self):
"""App.lang(language) returns dict with requested language / default.""" """App.lang(language) returns dict with requested language / default."""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment