Skip to content

Commit 819020d

Browse files
committed
MPT-18701 Improve base model tests (improvements)
1 parent aabb371 commit 819020d

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

tests/unit/models/test_model.py

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,11 @@ def test_append():
181181
agreement.parameters.ordering.append(new_param) # act
182182

183183
assert agreement.id == "AGR-123"
184-
assert agreement.parameters.ordering[0].external_id == "contact"
185-
assert agreement.parameters.ordering[1].external_id == "address"
186-
assert agreement.parameters.ordering[2].external_id == "email"
184+
assert [agr_param.external_id for agr_param in agreement.parameters.ordering] == [
185+
"contact",
186+
"address",
187+
"email",
188+
]
187189
agreement_data["parameters"]["ordering"].append(new_param)
188190
assert agreement.to_dict() == agreement_data
189191

@@ -202,8 +204,10 @@ def test_overwrite_list():
202204
agreement.parameters.ordering = ordering_parameters # act
203205

204206
assert agreement.id == "AGR-123"
205-
assert agreement.parameters.ordering[0].external_id == "contact"
206-
assert agreement.parameters.ordering[1].external_id == "address"
207+
assert [agr_param.external_id for agr_param in agreement.parameters.ordering] == [
208+
"contact",
209+
"address",
210+
]
207211
assert agreement.to_dict() == agreement_data
208212

209213

@@ -222,8 +226,10 @@ def test_advanced_mapping():
222226
agreement.parameters.ordering = ordering_parameters # act
223227

224228
assert isinstance(agreement.contact, ContactDummy)
225-
assert agreement.parameters.ordering[0].external_id == "contact"
226-
assert agreement.parameters.ordering[1].external_id == "address"
229+
assert [agr_param.external_id for agr_param in agreement.parameters.ordering] == [
230+
"contact",
231+
"address",
232+
]
227233
assert agreement.to_dict() == agreement_data
228234

229235

@@ -246,10 +252,7 @@ def test_model_list_insert():
246252

247253
ml.insert(1, {"id": "2"}) # act
248254

249-
assert len(ml) == 3
250-
assert ml[0].id == "1"
251-
assert ml[1].id == "2"
252-
assert ml[2].id == "3"
255+
assert [ml_item.id for ml_item in ml] == ["1", "2", "3"]
253256

254257

255258
def test_model_list_process_item_nested_list():
@@ -264,9 +267,7 @@ def test_model_list_process_item_nested_list():
264267
def test_model_list_process_item_scalar():
265268
ml = ModelList(["a", "b", "c"]) # act
266269

267-
assert ml[0] == "a"
268-
assert ml[1] == "b"
269-
assert ml[2] == "c"
270+
assert ml == ["a", "b", "c"]
270271

271272

272273
def test_base_model_getattr_from_dict():
@@ -298,10 +299,8 @@ def test_to_dict_excludes_private_attrs():
298299
def test_process_value_typed_list():
299300
container = TypedListContainerDummy(entries=[{"name": "one"}, {"name": "two"}]) # act
300301

301-
assert isinstance(container.entries[0], TypedListItemDummy)
302-
assert container.entries[0].name == "one"
303-
assert isinstance(container.entries[1], TypedListItemDummy)
304-
assert container.entries[1].name == "two"
302+
assert all(isinstance(entry, TypedListItemDummy) for entry in container.entries)
303+
assert [entry.name for entry in container.entries] == ["one", "two"]
305304

306305

307306
def test_process_value_existing_base_model():
@@ -326,5 +325,4 @@ def test_process_value_scalar_list_elements():
326325
container = ScalarListContainerDummy(tags=["a", "b", "c"]) # act
327326

328327
assert isinstance(container.tags, ModelList)
329-
assert container.tags[0] == "a"
330-
assert container.tags[1] == "b"
328+
assert list(container.tags) == ["a", "b", "c"]

0 commit comments

Comments
 (0)