Skip to content

Commit

Permalink
Fixed django#373 - Fix assertTrue/assertFalse.
Browse files Browse the repository at this point in the history
  • Loading branch information
csirmazbendeguz committed Aug 26, 2024
1 parent b401ebc commit 6249ffd
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 32 deletions.
4 changes: 2 additions & 2 deletions tests/composite_pk/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def test_get_or_create_user(self):
with self.subTest(fields=fields):
count = User.objects.count()
user, created = User.objects.get_or_create(**fields)
self.assertTrue(created)
self.assertIs(created, True)
self.assertIsNotNone(user.id)
self.assertEqual(user.pk, (self.tenant.id, user.id))
self.assertEqual(user.tenant_id, self.tenant.id)
Expand Down Expand Up @@ -134,7 +134,7 @@ def test_update_or_create_user(self):
with self.subTest(fields=fields):
count = User.objects.count()
user, created = User.objects.update_or_create(**fields)
self.assertTrue(created)
self.assertIs(created, True)
self.assertIsNotNone(user.id)
self.assertEqual(user.pk, (self.tenant.id, user.id))
self.assertEqual(user.tenant_id, self.tenant.id)
Expand Down
30 changes: 15 additions & 15 deletions tests/composite_pk/test_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ def test_delete_tenant_by_pk(self):
),
)

self.assertFalse(Tenant.objects.filter(pk=self.tenant_1.pk).exists())
self.assertTrue(Tenant.objects.filter(pk=self.tenant_2.pk).exists())
self.assertFalse(User.objects.filter(pk=self.user_1.pk).exists())
self.assertTrue(User.objects.filter(pk=self.user_2.pk).exists())
self.assertFalse(Comment.objects.filter(pk=self.comment_1.pk).exists())
self.assertTrue(Comment.objects.filter(pk=self.comment_2.pk).exists())
self.assertTrue(Comment.objects.filter(pk=self.comment_3.pk).exists())
self.assertIs(Tenant.objects.filter(pk=self.tenant_1.pk).exists(), False)
self.assertIs(Tenant.objects.filter(pk=self.tenant_2.pk).exists(), True)
self.assertIs(User.objects.filter(pk=self.user_1.pk).exists(), False)
self.assertIs(User.objects.filter(pk=self.user_2.pk).exists(), True)
self.assertIs(Comment.objects.filter(pk=self.comment_1.pk).exists(), False)
self.assertIs(Comment.objects.filter(pk=self.comment_2.pk).exists(), True)
self.assertIs(Comment.objects.filter(pk=self.comment_3.pk).exists(), True)

def test_delete_user_by_pk(self):
result = User.objects.filter(pk=self.user_1.pk).delete()
Expand All @@ -58,20 +58,20 @@ def test_delete_user_by_pk(self):
result, (2, {"composite_pk.User": 1, "composite_pk.Comment": 1})
)

self.assertFalse(User.objects.filter(pk=self.user_1.pk).exists())
self.assertTrue(User.objects.filter(pk=self.user_2.pk).exists())
self.assertFalse(Comment.objects.filter(pk=self.comment_1.pk).exists())
self.assertTrue(Comment.objects.filter(pk=self.comment_2.pk).exists())
self.assertTrue(Comment.objects.filter(pk=self.comment_3.pk).exists())
self.assertIs(User.objects.filter(pk=self.user_1.pk).exists(), False)
self.assertIs(User.objects.filter(pk=self.user_2.pk).exists(), True)
self.assertIs(Comment.objects.filter(pk=self.comment_1.pk).exists(), False)
self.assertIs(Comment.objects.filter(pk=self.comment_2.pk).exists(), True)
self.assertIs(Comment.objects.filter(pk=self.comment_3.pk).exists(), True)

def test_delete_comments_by_user(self):
result = Comment.objects.filter(user=self.user_2).delete()

self.assertEqual(result, (2, {"composite_pk.Comment": 2}))

self.assertTrue(Comment.objects.filter(pk=self.comment_1.pk).exists())
self.assertFalse(Comment.objects.filter(pk=self.comment_2.pk).exists())
self.assertFalse(Comment.objects.filter(pk=self.comment_3.pk).exists())
self.assertIs(Comment.objects.filter(pk=self.comment_1.pk).exists(), True)
self.assertIs(Comment.objects.filter(pk=self.comment_2.pk).exists(), False)
self.assertIs(Comment.objects.filter(pk=self.comment_3.pk).exists(), False)

def test_delete_without_pk(self):
msg = (
Expand Down
4 changes: 2 additions & 2 deletions tests/composite_pk/test_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ def test_filter_comments_by_user_and_exclude_by_pk(self):
)

def test_filter_comments_by_user_and_contains(self):
self.assertTrue(
Comment.objects.filter(user=self.user_1).contains(self.comment_1)
self.assertIs(
Comment.objects.filter(user=self.user_1).contains(self.comment_1), True
)

def test_filter_users_by_comments_in(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/composite_pk/test_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def test_get_or_create_user(self):
with self.subTest(fields=fields):
count = User.objects.count()
user, created = User.objects.get_or_create(**fields)
self.assertFalse(created)
self.assertIs(created, False)
self.assertEqual(user.id, self.user_1.id)
self.assertEqual(user.pk, (self.tenant_1.id, self.user_1.id))
self.assertEqual(user.tenant_id, self.tenant_1.id)
Expand Down
2 changes: 1 addition & 1 deletion tests/composite_pk/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def test_update_or_create_user(self):
with self.subTest(fields=fields):
count = User.objects.count()
user, created = User.objects.update_or_create(**fields)
self.assertFalse(created)
self.assertIs(created, False)
self.assertEqual(user.id, self.user_1.id)
self.assertEqual(user.pk, (self.tenant_1.id, self.user_1.id))
self.assertEqual(user.tenant_id, self.tenant_1.id)
Expand Down
22 changes: 11 additions & 11 deletions tests/composite_pk/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,22 @@ def get_constraints(table):
def test_pk_updated_if_field_updated(self):
user = User.objects.get(pk=self.user.pk)
self.assertEqual(user.pk, (self.tenant.id, self.user.id))
self.assertTrue(user._is_pk_set())
self.assertIs(user._is_pk_set(), True)
user.tenant_id = 9831
self.assertEqual(user.pk, (9831, self.user.id))
self.assertTrue(user._is_pk_set())
self.assertIs(user._is_pk_set(), True)
user.id = 4321
self.assertEqual(user.pk, (9831, 4321))
self.assertTrue(user._is_pk_set())
self.assertIs(user._is_pk_set(), True)
user.pk = (9132, 3521)
self.assertEqual(user.tenant_id, 9132)
self.assertEqual(user.id, 3521)
self.assertTrue(user._is_pk_set())
self.assertIs(user._is_pk_set(), True)
user.id = None
self.assertEqual(user.pk, (9132, None))
self.assertEqual(user.tenant_id, 9132)
self.assertIsNone(user.id)
self.assertFalse(user._is_pk_set())
self.assertIs(user._is_pk_set(), False)

def test_hash(self):
self.assertEqual(hash(User(pk=(1, 2))), hash((1, 2)))
Expand Down Expand Up @@ -121,36 +121,36 @@ def test_get_constraints_postgresql(self):
user_constraints = self.get_constraints(User._meta.db_table)
user_pk = user_constraints["composite_pk_user_pkey"]
self.assertEqual(user_pk["columns"], ["tenant_id", "id"])
self.assertTrue(user_pk["primary_key"])
self.assertIs(user_pk["primary_key"], True)

comment_constraints = self.get_constraints(Comment._meta.db_table)
comment_pk = comment_constraints["composite_pk_comment_pkey"]
self.assertEqual(comment_pk["columns"], ["tenant_id", "comment_id"])
self.assertTrue(comment_pk["primary_key"])
self.assertIs(comment_pk["primary_key"], True)

@unittest.skipUnless(connection.vendor == "sqlite", "SQLite specific test")
def test_get_constraints_sqlite(self):
user_constraints = self.get_constraints(User._meta.db_table)
user_pk = user_constraints["__primary__"]
self.assertEqual(user_pk["columns"], ["tenant_id", "id"])
self.assertTrue(user_pk["primary_key"])
self.assertIs(user_pk["primary_key"], True)

comment_constraints = self.get_constraints(Comment._meta.db_table)
comment_pk = comment_constraints["__primary__"]
self.assertEqual(comment_pk["columns"], ["tenant_id", "comment_id"])
self.assertTrue(comment_pk["primary_key"])
self.assertIs(comment_pk["primary_key"], True)

@unittest.skipUnless(connection.vendor == "mysql", "MySQL specific test")
def test_get_constraints_mysql(self):
user_constraints = self.get_constraints(User._meta.db_table)
user_pk = user_constraints["PRIMARY"]
self.assertEqual(user_pk["columns"], ["tenant_id", "id"])
self.assertTrue(user_pk["primary_key"])
self.assertIs(user_pk["primary_key"], True)

comment_constraints = self.get_constraints(Comment._meta.db_table)
comment_pk = comment_constraints["PRIMARY"]
self.assertEqual(comment_pk["columns"], ["tenant_id", "comment_id"])
self.assertTrue(comment_pk["primary_key"])
self.assertIs(comment_pk["primary_key"], True)

@unittest.skipUnless(connection.vendor == "oracle", "Oracle specific test")
def test_get_constraints_oracle(self):
Expand Down

0 comments on commit 6249ffd

Please sign in to comment.