Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Failing test for get_or_create with trait #810

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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