Skip to content

Commit e8c0016

Browse files
author
Gaurav Singh
committed
Updated schema tests to use assertpy fluent assertions to validate instead of printing on the console.
1 parent 2ed2046 commit e8c0016

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

tests/schema_test.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import json
22

33
import requests
4+
from assertpy import assert_that, soft_assertions
45
from cerberus import Validator
56

67
from config import BASE_URI
78

89
schema = {
910
"fname": {'type': 'string'},
1011
"lname": {'type': 'string'},
11-
"person_id": {'type': 'integer'},
12+
"person_id": {'type': 'number'},
1213
"timestamp": {'type': 'string'}
1314
}
1415

@@ -17,21 +18,19 @@ def test_read_one_operation_has_expected_schema():
1718
response = requests.get(f'{BASE_URI}/1')
1819
person = json.loads(response.text)
1920

20-
validator = Validator(schema)
21+
validator = Validator(schema, require_all=True)
2122
is_valid = validator.validate(person)
2223

23-
if not is_valid:
24-
print(validator.errors)
24+
assert_that(is_valid, description=validator.errors).is_true()
2525

2626

2727
def test_read_all_operation_has_expected_schema():
2828
response = requests.get(BASE_URI)
2929
persons = json.loads(response.text)
3030

31-
validator = Validator(schema)
31+
validator = Validator(schema, require_all=True)
3232

33-
for person in persons:
34-
is_valid = validator.validate(person)
35-
36-
if not is_valid:
37-
print(validator.errors)
33+
with soft_assertions():
34+
for person in persons:
35+
is_valid = validator.validate(person)
36+
assert_that(is_valid, description=validator.errors).is_true()

0 commit comments

Comments
 (0)