Skip to content

Commit

Permalink
test: Failing test for get_or_create with trait
Browse files Browse the repository at this point in the history
  • Loading branch information
MRigal committed Nov 2, 2020
1 parent 1957bd3 commit 9ebdb03
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/test_django.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,18 @@ class Meta:
text = factory.Sequence(lambda n: "text%s" % n)


class WithMultipleGetOrCreateWithTraitFieldsFactory(factory.django.DjangoModelFactory):
class Meta:
model = models.MultifieldUniqueModel
django_get_or_create = ("slug", "text",)

slug = ''
text = factory.Sequence(lambda n: "text%s" % n)

class Params:
with_slug = factory.Trait(slug='bar')


class ModelTests(django_test.TestCase):
databases = {'default', 'replica'}

Expand Down Expand Up @@ -249,6 +261,11 @@ def test_unique_field_not_in_get_or_create(self):
with self.assertRaises(django.db.IntegrityError):
WithMultipleGetOrCreateFieldsFactory(title="Title")

def test_get_or_create_with_trait(self):
WithMultipleGetOrCreateWithTraitFieldsFactory(text='foo')
obj = WithMultipleGetOrCreateWithTraitFieldsFactory(text='foo', with_slug=True)
self.assertEqual(obj.slug, 'bar')


class DjangoPkForceTestCase(django_test.TestCase):
def setUp(self):
Expand Down

0 comments on commit 9ebdb03

Please sign in to comment.