-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathtest_contract.py
More file actions
32 lines (27 loc) · 1.29 KB
/
test_contract.py
File metadata and controls
32 lines (27 loc) · 1.29 KB
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
import json
import pytest
from pydantic import ValidationError
from tests.context import ConsumerCustomerModel
def instantiate_customer(schema_version):
"""utility method to instantiate customer model with business alidations"""
sample_event_file = f"events/customerCreated-event-{schema_version}.json"
with open(sample_event_file, "r", encoding="utf-8") as event:
new_schema_event = json.load(event)
return ConsumerCustomerModel(**new_schema_event)
def test_address_with_four_fields_compatible_with_business_logic():
"""
business validation for address field checks for 4 fields separated by ","
event generated with schema 1.1.0 satisfies this, so test passes
"""
customer = instantiate_customer("1.1.0")
assert customer.address == "2 Park St, Sydney, NSW 2000, Australia", "Full address compatible"
def test_street_name_for_address_not_compatible_with_business_logic():
"""
business validation for address field checks for 4 fields separated by ","
event generated with schema 1.4.0 does not satisfy this, so test fails
"""
with pytest.raises(Exception) as e_info:
customer = instantiate_customer("1.4.0")
assert e_info.type == ValidationError
assert "Address must have four fields separated by ','" in str(
e_info.value)