Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F7163702
D109.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Subscribers
None
D109.diff
View Options
diff --git a/swh/web/ui/apidoc.py b/swh/web/ui/apidoc.py
--- a/swh/web/ui/apidoc.py
+++ b/swh/web/ui/apidoc.py
@@ -230,7 +230,8 @@
env['example'] = re.sub(r'(.*)\?.*', r'\1', example)
# Prepare and send to mimetype selector if it's not a doc request
- if re.match(route_re, request.url) and not kwargs['noargs']:
+ if re.match(route_re, request.url) and not kwargs['noargs'] \
+ and request.method == 'GET':
return app.response_class(
render_template('apidoc.html', **env),
content_type='text/html')
diff --git a/swh/web/ui/tests/test_apidoc.py b/swh/web/ui/tests/test_apidoc.py
--- a/swh/web/ui/tests/test_apidoc.py
+++ b/swh/web/ui/tests/test_apidoc.py
@@ -172,6 +172,7 @@
mock_api_urls.get_method_endpoints.return_value = self.stub_rule_list
mock_request.url = 'http://my-domain.tld/some/doc/route/'
+ mock_request.method = 'GET'
mock_url_for.return_value = 'http://my-domain.tld/meaningful_route/'
expected_env = {
@@ -253,6 +254,52 @@
@patch('swh.web.ui.apidoc.APIUrls')
@patch('swh.web.ui.apidoc.request')
@istest
+ def apidoc_returns_same_fun(self,
+ mock_request,
+ mock_api_urls,
+ mock_url_for,
+ mock_g):
+
+ # given
+ decorator = apidoc.returns(rettype=apidoc.rettypes.dict,
+ retdoc='a dict with amazing properties')
+ mock_fun = MagicMock(return_value=123)
+ mock_fun.__name__ = 'some_fname'
+ mock_fun.__doc__ = 'Some documentation'
+ decorated = decorator.__call__(mock_fun)
+
+ mock_api_urls.get_method_endpoints.return_value = [
+ {'rule': 'some/doc/route/',
+ 'methods': {'GET', 'HEAD', 'OPTIONS'}},
+ {'rule': 'some/doc/route/',
+ 'methods': {'POST'}}]
+ mock_request.url = 'http://my-domain.tld/some/doc/route/'
+ mock_request.method = 'POST'
+ doc_dict = {
+ 'urls': [{'rule': 'some/doc/route/',
+ 'methods': {'POST'}}],
+ 'docstring': 'Some documentation',
+ 'route': 'some/doc/route/',
+ 'return': {'type': apidoc.rettypes.dict.value,
+ 'doc': 'a dict with amazing properties'}
+ }
+
+ # when
+ decorated(
+ call_args=(('my', 'args'), {'kw': 'andkwargs'}),
+ doc_route='some/doc/route/',
+ noargs=False
+ )
+
+ # then
+ mock_fun.assert_called_once_with('my', 'args', kw='andkwargs')
+ self.assertEqual(mock_g.doc_env, doc_dict)
+
+ @patch('swh.web.ui.apidoc.g')
+ @patch('swh.web.ui.apidoc.url_for')
+ @patch('swh.web.ui.apidoc.APIUrls')
+ @patch('swh.web.ui.apidoc.request')
+ @istest
def apidoc_return_endpoint_call(self,
mock_request,
mock_api_urls,
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Jan 30, 1:35 PM (1 w, 12 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3223580
Attached To
D109: API: fix apidoc behaviour
Event Timeline
Log In to Comment