diff --git a/tests/many_to_many/tests.py b/tests/many_to_many/tests.py index 8ff11858788..a60ea424309 100644 --- a/tests/many_to_many/tests.py +++ b/tests/many_to_many/tests.py @@ -104,6 +104,12 @@ class ManyToManyTests(TestCase): a5.authors.remove(user_2.username) self.assertQuerysetEqual(a5.authors.all(), []) + def test_add_remove_invalid_type(self): + msg = "Field 'id' expected a number but got 'invalid'." + for method in ['add', 'remove']: + with self.subTest(method), self.assertRaisesMessage(ValueError, msg): + getattr(self.a1.publications, method)('invalid') + def test_reverse_add(self): # Adding via the 'other' end of an m2m a5 = Article(headline='NASA finds intelligent life on Mars')