mirror of
https://github.com/django/django.git
synced 2025-08-01 09:32:50 +00:00
Fixed #22640 -- Raised TypeError when instantiating model with keyword and positional args for the same field.
This commit is contained in:
parent
712fe12466
commit
73b1b225ce
2 changed files with 14 additions and 1 deletions
|
@ -68,6 +68,15 @@ class ModelInstanceCreationTests(TestCase):
|
|||
a.save()
|
||||
self.assertEqual(a.headline, 'Fourth article')
|
||||
|
||||
def test_positional_and_keyword_args_for_the_same_field(self):
|
||||
msg = "Article() got both positional and keyword arguments for field '%s'."
|
||||
with self.assertRaisesMessage(TypeError, msg % 'headline'):
|
||||
Article(None, 'Fifth article', headline='Other headline.')
|
||||
with self.assertRaisesMessage(TypeError, msg % 'headline'):
|
||||
Article(None, 'Sixth article', headline='')
|
||||
with self.assertRaisesMessage(TypeError, msg % 'pub_date'):
|
||||
Article(None, 'Seventh article', datetime(2021, 3, 1), pub_date=None)
|
||||
|
||||
def test_cannot_create_instance_with_invalid_kwargs(self):
|
||||
with self.assertRaisesMessage(TypeError, "Article() got an unexpected keyword argument 'foo'"):
|
||||
Article(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue