From 6249ffd7f5d1c6b9fbb15c84ba4aaf0a46a51670 Mon Sep 17 00:00:00 2001 From: Bendeguz Csirmaz Date: Mon, 26 Aug 2024 16:10:11 +0800 Subject: [PATCH] Fixed #373 - Fix assertTrue/assertFalse. --- tests/composite_pk/test_create.py | 4 ++-- tests/composite_pk/test_delete.py | 30 +++++++++++++++--------------- tests/composite_pk/test_filter.py | 4 ++-- tests/composite_pk/test_get.py | 2 +- tests/composite_pk/test_update.py | 2 +- tests/composite_pk/tests.py | 22 +++++++++++----------- 6 files changed, 32 insertions(+), 32 deletions(-) diff --git a/tests/composite_pk/test_create.py b/tests/composite_pk/test_create.py index 1a90cd83f7e71..42406ed6c46db 100644 --- a/tests/composite_pk/test_create.py +++ b/tests/composite_pk/test_create.py @@ -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) @@ -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) diff --git a/tests/composite_pk/test_delete.py b/tests/composite_pk/test_delete.py index 4f4f9a465898e..712a695de16b1 100644 --- a/tests/composite_pk/test_delete.py +++ b/tests/composite_pk/test_delete.py @@ -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() @@ -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 = ( diff --git a/tests/composite_pk/test_filter.py b/tests/composite_pk/test_filter.py index 578d1561272bc..aa974a452d226 100644 --- a/tests/composite_pk/test_filter.py +++ b/tests/composite_pk/test_filter.py @@ -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): diff --git a/tests/composite_pk/test_get.py b/tests/composite_pk/test_get.py index ae73bea6063d6..000f00d9153d7 100644 --- a/tests/composite_pk/test_get.py +++ b/tests/composite_pk/test_get.py @@ -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) diff --git a/tests/composite_pk/test_update.py b/tests/composite_pk/test_update.py index 71a2ed701e748..7c5b8c035dbdf 100644 --- a/tests/composite_pk/test_update.py +++ b/tests/composite_pk/test_update.py @@ -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) diff --git a/tests/composite_pk/tests.py b/tests/composite_pk/tests.py index 0b2afdb17549c..7237666477580 100644 --- a/tests/composite_pk/tests.py +++ b/tests/composite_pk/tests.py @@ -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))) @@ -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):