diff options
Diffstat (limited to 'tests/model_fields')
| -rw-r--r-- | tests/model_fields/test_foreignkey.py | 9 | ||||
| -rw-r--r-- | tests/model_fields/test_manytomanyfield.py | 28 |
2 files changed, 37 insertions, 0 deletions
diff --git a/tests/model_fields/test_foreignkey.py b/tests/model_fields/test_foreignkey.py index d30cca9b5c..0cd6d62a55 100644 --- a/tests/model_fields/test_foreignkey.py +++ b/tests/model_fields/test_foreignkey.py @@ -147,3 +147,12 @@ class ForeignKeyTests(TestCase): ) with self.assertRaisesMessage(FieldError, msg): Related._meta.get_field('child').related_fields + + def test_invalid_to_parameter(self): + msg = ( + "ForeignKey(1) is invalid. First parameter to ForeignKey must be " + "either a model, a model name, or the string 'self'" + ) + with self.assertRaisesMessage(TypeError, msg): + class MyModel(models.Model): + child = models.ForeignKey(1, models.CASCADE) diff --git a/tests/model_fields/test_manytomanyfield.py b/tests/model_fields/test_manytomanyfield.py index 5724fe9384..0ddf57ceaf 100644 --- a/tests/model_fields/test_manytomanyfield.py +++ b/tests/model_fields/test_manytomanyfield.py @@ -59,6 +59,34 @@ class ManyToManyFieldTests(SimpleTestCase): assert_app_model_resolved('model_fields') assert_app_model_resolved('tests') + def test_invalid_to_parameter(self): + msg = ( + "ManyToManyField(1) is invalid. First parameter to " + "ManyToManyField must be either a model, a model name, or the " + "string 'self'" + ) + with self.assertRaisesMessage(TypeError, msg): + class MyModel(models.Model): + m2m = models.ManyToManyField(1) + + @isolate_apps('model_fields') + def test_through_db_table_mutually_exclusive(self): + class Child(models.Model): + pass + + class Through(models.Model): + referred = models.ForeignKey(Child, on_delete=models.CASCADE) + referent = models.ForeignKey(Child, on_delete=models.CASCADE) + + msg = 'Cannot specify a db_table if an intermediary model is used.' + with self.assertRaisesMessage(ValueError, msg): + class MyModel(models.Model): + m2m = models.ManyToManyField( + Child, + through='Through', + db_table='custom_name', + ) + class ManyToManyFieldDBTests(TestCase): |
