Skip to content

Commit

Permalink
[3/3] Add contact information to Swagger UI (#6205)
Browse files Browse the repository at this point in the history
  • Loading branch information
hannes-ucsc authored and achave11-ucsc committed Jan 17, 2025
1 parent 11cfb07 commit 06a9d7a
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions test/test_openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,6 @@ def setUpModule():
configure_test_logging()


swagger_info_spec = {
'info': {
'description': '\n\n## Contact us\n\nFor technical support please file an '
'issue at\n[GitHub](https://github.com/DataBiosphere/azul/issues) or email\n'
'`azul-group@ucsc.edu`. To report a security concern or misconduct please '
'email\n`azul-group@ucsc.edu`.\n'
}
}


@patch('azul.chalice.AzulChaliceApp.base_url', furl('https://fake.url'))
class TestAppSpecs(AzulUnitTestCase):

Expand All @@ -51,7 +41,8 @@ def app(self, spec):
def test_top_level_spec(self):
spec = {'foo': 'bar'}
app = self.app(spec)
self.assertEqual({'foo': 'bar', 'paths': {}, **swagger_info_spec}, app._specs,
actual_spec = self._assert_info(app._specs)
self.assertEqual({'foo': 'bar', 'paths': {}}, actual_spec,
"Confirm 'paths' is added")
spec['new key'] = 'new value'
self.assertNotIn('new key', app.spec(),
Expand All @@ -70,12 +61,11 @@ def route():

expected = {
'foo': 'bar',
**swagger_info_spec,
'paths': {'/foo': {'get': {}, 'put': {}}},
'tags': [],
'servers': [{'url': 'https://fake.url/'}]
}
actual_spec = self._assert_default_method_spec(app.spec())
actual_spec = self._assert_default_method_spec(self._assert_info(app.spec()))
self.assertEqual(expected, actual_spec)

def test_just_method_spec(self):
Expand All @@ -87,7 +77,6 @@ def route():

expected_spec = {
'foo': 'bar',
**swagger_info_spec,
'paths': {
'/foo': {
'get': {'a': 'b'},
Expand All @@ -98,7 +87,7 @@ def route():
'servers': [{'url': 'https://fake.url/'}]
}

actual_spec = self._assert_default_method_spec(app.spec())
actual_spec = self._assert_default_method_spec(self._assert_info(app.spec()))
self.assertEqual(expected_spec, actual_spec)

def _assert_default_method_spec(self, actual_spec: JSON) -> JSON:
Expand All @@ -114,6 +103,13 @@ def _assert_default_method_spec(self, actual_spec: JSON) -> JSON:
self.assertEqual(({}, {}), (response, responses))
return actual_spec

def _assert_info(self, actual_spec: JSON) -> JSON:
actual_spec = copy_json(actual_spec)
info = actual_spec.pop('info')
self.assertIn('Contact us', info.pop('description'))
self.assertEqual({}, info)
return actual_spec

def test_fully_annotated_override(self):
app = self.app({'foo': 'bar'})
path_spec = {
Expand Down Expand Up @@ -149,10 +145,9 @@ def route():
}
},
'tags': [],
'servers': [{'url': 'https://fake.url/'}],
**swagger_info_spec
'servers': [{'url': 'https://fake.url/'}]
}
actual_spec = self._assert_default_method_spec(app.spec())
actual_spec = self._assert_default_method_spec(self._assert_info(app.spec()))
self.assertEqual(expected_specs, actual_spec)

def test_duplicate_method_specs(self):
Expand Down

0 comments on commit 06a9d7a

Please sign in to comment.