forked from automationhacks/course-api-framework-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema_test.py
More file actions
36 lines (25 loc) · 959 Bytes
/
schema_test.py
File metadata and controls
36 lines (25 loc) · 959 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import json
import requests
from assertpy import assert_that, soft_assertions
from cerberus import Validator
from config import BASE_URI
schema = {
"fname": {'type': 'string'},
"lname": {'type': 'string'},
"person_id": {'type': 'number'},
"timestamp": {'type': 'string'}
}
def test_read_one_operation_has_expected_schema():
response = requests.get(f'{BASE_URI}/1')
person = json.loads(response.text)
validator = Validator(schema, require_all=True)
is_valid = validator.validate(person)
assert_that(is_valid, description=validator.errors).is_true()
def test_read_all_operation_has_expected_schema():
response = requests.get(BASE_URI)
persons = json.loads(response.text)
validator = Validator(schema, require_all=True)
with soft_assertions():
for person in persons:
is_valid = validator.validate(person)
assert_that(is_valid, description=validator.errors).is_true()