Skip to content

Commit 2ed2046

Browse files
author
Gaurav Singh
committed
Extracted schema outside the functions and added a separate function to validate it for read one operation
1 parent becf0d7 commit 2ed2046

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

tests/schema_test.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,26 @@
55

66
from config import BASE_URI
77

8+
schema = {
9+
"fname": {'type': 'string'},
10+
"lname": {'type': 'string'},
11+
"person_id": {'type': 'integer'},
12+
"timestamp": {'type': 'string'}
13+
}
814

9-
def test_read_all_operation_has_expected_schema():
10-
schema = {
11-
"fname": {'type': 'string'},
12-
"lname": {'type': 'string'},
13-
"person_id": {'type': 'integer'},
14-
"timestamp": {'type': 'string'}
15-
}
1615

16+
def test_read_one_operation_has_expected_schema():
17+
response = requests.get(f'{BASE_URI}/1')
18+
person = json.loads(response.text)
19+
20+
validator = Validator(schema)
21+
is_valid = validator.validate(person)
22+
23+
if not is_valid:
24+
print(validator.errors)
25+
26+
27+
def test_read_all_operation_has_expected_schema():
1728
response = requests.get(BASE_URI)
1829
persons = json.loads(response.text)
1930

0 commit comments

Comments
 (0)