diff options
| author | Nick Pope <nick.pope@flightdataservices.com> | 2019-10-21 09:55:05 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-10-29 12:37:30 +0100 |
| commit | 7552de7866dcd270a0f353b007b4aceaa7f3ff3e (patch) | |
| tree | 2e84292833853d9659671ed304cb32d5acef5f90 /tests/schema | |
| parent | a6cb8ec3895a72bfb7f8e62d4b05dd5de6b738af (diff) | |
Used more specific unittest assertions in tests.
* assertIsNone()/assertIsNotNone() instead of comparing to None.
* assertLess() for < comparisons.
* assertIs() for 'is' expressions.
* assertIsInstance() for isinstance() expressions.
* rounding of assertAlmostEqual() for round() expressions.
* assertIs(..., True/False) instead of comparing to True/False.
* assertIs()/assertIsNot() for ==/!= comparisons.
* assertNotEqual() for == comparisons.
* assertTrue()/assertFalse() instead of comparing to True/False.
Diffstat (limited to 'tests/schema')
| -rw-r--r-- | tests/schema/tests.py | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/tests/schema/tests.py b/tests/schema/tests.py index 9a2195d1d5..b4d95c431c 100644 --- a/tests/schema/tests.py +++ b/tests/schema/tests.py @@ -468,7 +468,7 @@ class SchemaTests(TransactionTestCase): # Ensure the field is right afterwards columns = self.column_classes(Author) self.assertEqual(columns['age'][0], "IntegerField") - self.assertEqual(columns['age'][1][6], True) + self.assertTrue(columns['age'][1][6]) def test_add_field_remove_field(self): """ @@ -620,7 +620,7 @@ class SchemaTests(TransactionTestCase): # Ensure the field is right afterwards columns = self.column_classes(Author) self.assertEqual(columns['name'][0], "TextField") - self.assertEqual(columns['name'][1][6], True) + self.assertTrue(columns['name'][1][6]) # Change nullability again new_field2 = TextField(null=False) new_field2.set_attributes_from_name("name") @@ -2100,25 +2100,25 @@ class SchemaTests(TransactionTestCase): with connection.schema_editor() as editor: editor.create_model(Tag) # Ensure there's no index on the year/slug columns first - self.assertEqual( - False, + self.assertIs( any( c["index"] for c in self.get_constraints("schema_tag").values() if c['columns'] == ["slug", "title"] ), + False, ) # Alter the model to add an index with connection.schema_editor() as editor: editor.alter_index_together(Tag, [], [("slug", "title")]) # Ensure there is now an index - self.assertEqual( - True, + self.assertIs( any( c["index"] for c in self.get_constraints("schema_tag").values() if c['columns'] == ["slug", "title"] ), + True, ) # Alter it back new_field2 = SlugField(unique=True) @@ -2126,13 +2126,13 @@ class SchemaTests(TransactionTestCase): with connection.schema_editor() as editor: editor.alter_index_together(Tag, [("slug", "title")], []) # Ensure there's no index - self.assertEqual( - False, + self.assertIs( any( c["index"] for c in self.get_constraints("schema_tag").values() if c['columns'] == ["slug", "title"] ), + False, ) def test_index_together_with_fk(self): @@ -2161,13 +2161,13 @@ class SchemaTests(TransactionTestCase): with connection.schema_editor() as editor: editor.create_model(TagIndexed) # Ensure there is an index - self.assertEqual( - True, + self.assertIs( any( c["index"] for c in self.get_constraints("schema_tagindexed").values() if c['columns'] == ["slug", "title"] ), + True, ) @skipUnlessDBFeature('allows_multiple_constraints_on_same_fields') |
