Skip to content

Commit 67effab

Browse files
committed
test: model unit tests updated
1 parent 7669664 commit 67effab

File tree

1 file changed

+64
-50
lines changed

1 file changed

+64
-50
lines changed

tuttle_tests/test_model.py

Lines changed: 64 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -80,51 +80,6 @@ def test_user():
8080
assert icloud_account.user.name == "Archibald Tuttle"
8181

8282

83-
def test_project():
84-
project = model.Project(
85-
title="Heating Repair",
86-
tag="#heating-repair",
87-
start_date=datetime.date.today(),
88-
end_date=datetime.date.today() + datetime.timedelta(days=80),
89-
)
90-
assert store_and_retrieve(project)
91-
92-
93-
def test_contract():
94-
95-
the_client = model.Client(
96-
name="Central Services",
97-
invoicing_contact=model.Contact(
98-
first_name="Central",
99-
last_name="Services",
100-
company="Central Services",
101-
address=model.Address(
102-
street="Down the Road",
103-
number="55",
104-
city="Somewhere",
105-
postal_code="99999",
106-
country="Brazil",
107-
),
108-
109-
),
110-
)
111-
112-
the_contract = model.Contract(
113-
title="CS Q1 2022",
114-
client=the_client,
115-
start_date=datetime.date(2022, 1, 1),
116-
end_date=datetime.date(2022, 3, 31),
117-
signature_date=datetime.date(2021, 10, 31),
118-
rate=100,
119-
unit=time.TimeUnit.hour,
120-
currency="EUR",
121-
billing_cycle=time.Cycle.monthly,
122-
volume=3 * 8 * 8,
123-
units_per_workday=8,
124-
)
125-
assert store_and_retrieve(the_contract)
126-
127-
12883
class TestContact:
12984
def test_valid_contact_instantiation(self):
13085
contact = Contact(
@@ -148,24 +103,61 @@ def test_invalid_email_instantiation(self):
148103

149104

150105
class TestClient:
106+
"""Tests for the Client model."""
107+
151108
def test_valid_instantiation(self):
152109
invoicing_contact = Contact(
153110
first_name="Sam",
154111
last_name="Lowry",
155112
156113
company="Ministry of Information",
157114
)
158-
client = Client(
159-
name="Ministry of Information", invoicing_contact=invoicing_contact
115+
client = Client.validate(
116+
dict(
117+
name="Ministry of Information",
118+
invoicing_contact=invoicing_contact,
119+
)
160120
)
161121
assert store_and_retrieve(client)
162122

163123
def test_missing_fields_instantiation(self):
164124
with pytest.raises(ValidationError):
165-
Client() # type: ignore
125+
Client.validate(dict())
166126

167127

168128
class TestContract:
129+
"""Tests for the Contract model."""
130+
131+
def test_valid_instantiation(self):
132+
client = Client(name="Ministry of Information")
133+
contract = Contract.validate(
134+
dict(
135+
title="Project X Contract",
136+
client=client,
137+
signature_date=datetime.date(2022, 10, 1),
138+
start_date=datetime.date(2022, 10, 2),
139+
end_date=datetime.date(2022, 12, 31),
140+
rate=100,
141+
is_completed=False,
142+
currency="USD",
143+
VAT_rate=0.19,
144+
unit=TimeUnit.hour,
145+
units_per_workday=8,
146+
volume=100,
147+
term_of_payment=31,
148+
billing_cycle=Cycle.monthly,
149+
)
150+
)
151+
assert store_and_retrieve(contract)
152+
153+
def test_missing_fields_instantiation(self):
154+
with pytest.raises(ValidationError):
155+
Contract.validate(dict())
156+
157+
158+
class TestProject:
159+
"""Tests for the Project model."""
160+
169161
def test_valid_instantiation(self):
170162
client = Client(name="Ministry of Information")
171163
contract = Contract(
@@ -184,8 +176,30 @@ def test_valid_instantiation(self):
184176
term_of_payment=31,
185177
billing_cycle=Cycle.monthly,
186178
)
187-
assert store_and_retrieve(contract)
179+
project = Project.validate(
180+
dict(
181+
title="Project X",
182+
description="The description of Project X",
183+
tag="#project_x",
184+
start_date=datetime.date(2022, 10, 2),
185+
end_date=datetime.date(2022, 12, 31),
186+
contract=contract,
187+
)
188+
)
189+
assert store_and_retrieve(project)
188190

189191
def test_missing_fields_instantiation(self):
190192
with pytest.raises(ValidationError):
191-
Contract() # type: ignore
193+
Project.validate(dict())
194+
195+
def test_invalid_tag_instantiation(self):
196+
with pytest.raises(ValidationError):
197+
Project.validate(
198+
dict(
199+
title="Project X",
200+
description="The description of Project X",
201+
tag="project_x",
202+
start_date=datetime.date(2022, 10, 2),
203+
end_date=datetime.date(2022, 12, 31),
204+
)
205+
)

0 commit comments

Comments
 (0)