connect db, bump ver, update releases

This commit is contained in:
collerek
2020-12-15 14:17:19 +01:00
parent daf47f891e
commit 98da0de603
2 changed files with 31 additions and 31 deletions

View File

@ -158,7 +158,6 @@ def create_and_append_m2m_fk(
model.Meta.tablename + "." + model.get_column_alias(model.Meta.pkname), model.Meta.tablename + "." + model.get_column_alias(model.Meta.pkname),
ondelete="CASCADE", ondelete="CASCADE",
onupdate="CASCADE", onupdate="CASCADE",
related_name=model_field.name,
), ),
) )
model_field.through.Meta.columns.append(column) model_field.through.Meta.columns.append(column)

View File

@ -60,40 +60,41 @@ def create_test_database():
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_add_students(): async def test_add_students():
for user_id in [1, 2, 3, 4, 5]: async with db:
await User.objects.create(name=f"User {user_id}") for user_id in [1, 2, 3, 4, 5]:
await User.objects.create(name=f"User {user_id}")
for name, some_text, some_other_text in [ for name, some_text, some_other_text in [
("Session 1", "Some text 1", "Some other text 1"), ("Session 1", "Some text 1", "Some other text 1"),
("Session 2", "Some text 2", "Some other text 2"), ("Session 2", "Some text 2", "Some other text 2"),
("Session 3", "Some text 3", "Some other text 3"), ("Session 3", "Some text 3", "Some other text 3"),
("Session 4", "Some text 4", "Some other text 4"), ("Session 4", "Some text 4", "Some other text 4"),
("Session 5", "Some text 5", "Some other text 5"), ("Session 5", "Some text 5", "Some other text 5"),
]: ]:
await Session( await Session(
name=name, some_text=some_text, some_other_text=some_other_text name=name, some_text=some_text, some_other_text=some_other_text
).save() ).save()
s1 = await Session.objects.get(pk=1) s1 = await Session.objects.get(pk=1)
s2 = await Session.objects.get(pk=2) s2 = await Session.objects.get(pk=2)
users = {} users = {}
for i in range(1, 6): for i in range(1, 6):
user = await User.objects.get(pk=i) user = await User.objects.get(pk=i)
users[f"user_{i}"] = user users[f"user_{i}"] = user
if i % 2 == 0: if i % 2 == 0:
await s1.students.add(user) await s1.students.add(user)
else: else:
await s2.students.add(user) await s2.students.add(user)
assert len(s1.students) > 0 assert len(s1.students) > 0
assert len(s2.students) > 0 assert len(s2.students) > 0
user = await User.objects.select_related("attending").get(pk=1) user = await User.objects.select_related("attending").get(pk=1)
assert user.attending is not None assert user.attending is not None
assert len(user.attending) > 0 assert len(user.attending) > 0
query = Session.objects.prefetch_related(["students", "teacher",]) query = Session.objects.prefetch_related(["students", "teacher",])
sessions = await query.all() sessions = await query.all()
assert len(sessions) == 5 assert len(sessions) == 5