Skip to content

Commit d9fe83a

Browse files
Modularise test_spec.py
1 parent 8e7fec0 commit d9fe83a

1 file changed

Lines changed: 14 additions & 16 deletions

File tree

tests/web_api/test_spec.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
1-
# -*- coding: utf-8 -*-
2-
3-
import json
4-
from http.client import OK
5-
61
import dpath
7-
from . import subject
2+
import json
3+
import pytest
4+
from http import client
85

96

107
def assert_items_equal(x, y):
118
assert sorted(x) == sorted(y)
129

1310

14-
openAPI_response = subject.get('/spec')
15-
16-
17-
def test_return_code():
18-
assert openAPI_response.status_code == OK
11+
def test_return_code(test_client):
12+
openAPI_response = test_client.get('/spec')
13+
assert openAPI_response.status_code == client.OK
1914

2015

21-
body = json.loads(openAPI_response.data.decode('utf-8'))
16+
@pytest.fixture(scope="module")
17+
def body(test_client):
18+
openAPI_response = test_client.get('/spec')
19+
return json.loads(openAPI_response.data.decode('utf-8'))
2220

2321

24-
def test_paths():
22+
def test_paths(body):
2523
assert_items_equal(
2624
body['paths'],
2725
["/parameter/{parameterID}",
@@ -35,15 +33,15 @@ def test_paths():
3533
)
3634

3735

38-
def test_entity_definition():
36+
def test_entity_definition(body):
3937
assert 'parents' in dpath.get(body, 'definitions/Household/properties')
4038
assert 'children' in dpath.get(body, 'definitions/Household/properties')
4139
assert 'salary' in dpath.get(body, 'definitions/Person/properties')
4240
assert 'rent' in dpath.get(body, 'definitions/Household/properties')
4341
assert 'number' == dpath.get(body, 'definitions/Person/properties/salary/additionalProperties/type')
4442

4543

46-
def test_situation_definition():
44+
def test_situation_definition(body):
4745
situation_input = body['definitions']['SituationInput']
4846
situation_output = body['definitions']['SituationOutput']
4947
for situation in situation_input, situation_output:
@@ -53,5 +51,5 @@ def test_situation_definition():
5351
assert "#/definitions/Person" == dpath.get(situation, '/properties/persons/additionalProperties/$ref')
5452

5553

56-
def test_host():
54+
def test_host(body):
5755
assert 'http' not in body['host']

0 commit comments

Comments
 (0)