Skip to content

Commit 667c5fa

Browse files
committed
Added init of SwaggerSpec test
1 parent 72868fc commit 667c5fa

2 files changed

Lines changed: 22 additions & 6 deletions

File tree

odinweb/swagger.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ def get_swagger(self, request):
187187
"""
188188
api_base = self.parent
189189
if not api_base:
190-
raise HttpError(404, 40442, "Swagger not available.",
191-
"Swagger API is detached from a parent container.")
190+
raise HttpError(HTTPStatus.NOT_FOUND, 42, "Swagger not available.",
191+
"Swagger API is detached from a parent container.")
192192

193193
paths, definitions = self.parse_operations()
194194
return dict_filter({
@@ -208,17 +208,17 @@ def get_swagger(self, request):
208208

209209
def load_static(self, file_name):
210210
if not self.enable_ui:
211-
raise HttpError(404, 40401, "Not found")
211+
raise HttpError(HTTPStatus.NOT_FOUND, 42)
212212

213213
static_path = os.path.join(os.path.dirname(__file__), 'static')
214214
file_path = os.path.abspath(os.path.join(static_path, file_name))
215215
if not file_path.startswith(static_path):
216-
raise HttpError(404, 40401, "Not found")
216+
raise HttpError(HTTPStatus.NOT_FOUND, 42)
217217

218218
try:
219219
return open(file_path, 'rb').read()
220220
except OSError:
221-
raise HttpError(404, 40401, "Not found")
221+
raise HttpError(HTTPStatus.NOT_FOUND, 42)
222222

223223
@doc.response(HTTPStatus.OK, "HTML content")
224224
@doc.produces('text/html')
@@ -243,7 +243,7 @@ def get_static(self, _, file_name=None):
243243
'js': 'application/javascript',
244244
}.get(file_name[-2:])
245245
if not content_type:
246-
raise ImmediateHttpResponse("Not Found", 404)
246+
raise HttpError(HTTPStatus.NOT_FOUND, 42)
247247

248248
return HttpResponse(self.load_static(file_name), headers={
249249
'Content-Type': content_type,

tests/test_swagger.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
11
import pytest
22

33
from odinweb import swagger
4+
5+
6+
class TestSwaggerSpec(object):
7+
@pytest.mark.parametrize('options, title, enable_ui, host, schemes', (
8+
({'title': 'Test'}, 'Test', False, None, None),
9+
({'title': 'Test', 'enable_ui': True}, 'Test', True, None, None),
10+
({'title': 'Test', 'host': 'localhost'}, 'Test', False, 'localhost', None),
11+
({'title': 'Test', 'schemes': ('http', 'https')}, 'Test', False, None, ('http', 'https')),
12+
))
13+
def test_configure(self, options, title, enable_ui, host, schemes):
14+
target = swagger.SwaggerSpec(**options)
15+
16+
assert target.title == title
17+
assert target.enable_ui == enable_ui
18+
assert target.host == host
19+
assert target.schemes == schemes

0 commit comments

Comments
 (0)