Skip to content

Commit

Permalink
Change asserts in faulty test
Browse files Browse the repository at this point in the history
  • Loading branch information
a_bondar committed Apr 24, 2024
1 parent 8b97749 commit 614df57
Showing 1 changed file with 32 additions and 28 deletions.
60 changes: 32 additions & 28 deletions tests/test_bulk.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ async def test_bulk_create(self):
all_ = await UniqueName.all().values("id", "name")
inc = all_[0]["id"]
self.assertListSortEqual(
all_, [{"id": val + inc, "name": None} for val in range(1000)], sorted_key="id"
all_,
[{"id": val + inc, "name": None} for val in range(1000)],
sorted_key="id",
)

@test.requireCapability(dialect=NotEQ("mssql"))
Expand All @@ -37,7 +39,14 @@ async def test_bulk_create_more_that_one_update_fields(self):
)
all_ = await UniqueName.all().values("name", "optional", "other_optional")
self.assertListSortEqual(
all_, [{"name": "name", "optional": "optional", "other_optional": "other_optional"}]
all_,
[
{
"name": "name",
"optional": "optional",
"other_optional": "other_optional",
}
],
)

@test.requireCapability(dialect=NotEQ("mssql"))
Expand All @@ -47,51 +56,46 @@ async def test_bulk_create_with_batch_size(self):
)
all_ = await UniqueName.all().values("id", "name")
self.assertListSortEqual(
all_, [{"id": val + 1, "name": None} for val in range(1000)], sorted_key="id"
all_,
[{"id": val + 1, "name": None} for val in range(1000)],
sorted_key="id",
)

@test.requireCapability(dialect=NotEQ("mssql"))
async def test_bulk_create_with_specified(self):
await UniqueName.bulk_create([UniqueName(id=id_) for id_ in range(1000, 2000)])
all_ = await UniqueName.all().values("id", "name")
self.assertListSortEqual(
all_, [{"id": id_, "name": None} for id_ in range(1000, 2000)], sorted_key="id"
all_,
[{"id": id_, "name": None} for id_ in range(1000, 2000)],
sorted_key="id",
)

@test.requireCapability(dialect=NotEQ("mssql"))
async def test_bulk_create_mix_specified(self):
await UniqueName.bulk_create(
[UniqueName(id=id_) for id_ in range(10000, 11000)]
+ [UniqueName() for _ in range(1000)]
[UniqueName(id=id_) for id_ in range(1000, 1100)] + [UniqueName() for _ in range(100)]
)

all_ = await UniqueName.all().order_by("id").values("id", "name")
self.assertEqual(len(all_), 2000)
assert len(all_) == 200

if all_[0]["id"] == 10000:
self.assertListSortEqual(
all_[:1000],
[{"id": id_, "name": None} for id_ in range(10000, 11000)],
sorted_key="id",
)
if all_[0]["id"] == 1000:
assert sorted(all_[:100], key=lambda x: x["id"]) == [
{"id": id_, "name": None} for id_ in range(1000, 1100)
]
inc = all_[1000]["id"]
self.assertListSortEqual(
all_[1000:],
[{"id": val + inc, "name": None} for val in range(1000)],
sorted_key="id",
)
assert sorted(all_[100:], key=lambda x: x["id"]) == [
{"id": val + inc, "name": None} for val in range(1000, 1100)
]
else:
inc = all_[0]["id"]
self.assertListSortEqual(
all_[:1000],
[{"id": val + inc, "name": None} for val in range(1000)],
sorted_key="id",
)
self.assertListSortEqual(
all_[1000:],
[{"id": id_, "name": None} for id_ in range(10000, 11000)],
sorted_key="id",
)
assert sorted(all_[:100], key=lambda x: x["id"]) == [
{"id": val + inc, "name": None} for val in range(1000, 1100)
]
assert sorted(all_[100:], key=lambda x: x["id"]) == [
{"id": id_, "name": None} for id_ in range(1000, 1100)
]

async def test_bulk_create_uuidpk(self):
await UUIDPkModel.bulk_create([UUIDPkModel() for _ in range(1000)])
Expand Down

0 comments on commit 614df57

Please sign in to comment.