Refs #8467 -- Added test for RelatedManager.add()/remove() with an invalid type.

This commit is contained in:
Simon Charette 2019-11-22 08:39:54 +01:00 committed by Mariusz Felisiak
parent ee4a19053a
commit 8cc711999a
1 changed files with 6 additions and 0 deletions

View File

@ -104,6 +104,12 @@ class ManyToManyTests(TestCase):
a5.authors.remove(user_2.username) a5.authors.remove(user_2.username)
self.assertQuerysetEqual(a5.authors.all(), []) 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): def test_reverse_add(self):
# Adding via the 'other' end of an m2m # Adding via the 'other' end of an m2m
a5 = Article(headline='NASA finds intelligent life on Mars') a5 = Article(headline='NASA finds intelligent life on Mars')