Skip to content

Commit

Permalink
Adding tests to make sure that custom autofixture classes are used wh…
Browse files Browse the repository at this point in the history
…en creating m2m instances.
  • Loading branch information
gregmuellegger committed Jun 26, 2015
1 parent 7afb5dc commit 36b6d65
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 5 additions & 0 deletions autofixture_tests/models.py
Expand Up @@ -196,3 +196,8 @@ class DummyStorage(FileSystemStorage):
class ImageModel(models.Model):
imgfield = models.ImageField(upload_to='_autofixtures',
storage=dummy_storage)


class RelationWithCustomAutofixtureModel(models.Model):
user = models.ForeignKey('auth.User', related_name='user1+')
users = models.ManyToManyField('auth.User', related_name='user2+')
18 changes: 17 additions & 1 deletion autofixture_tests/tests/test_base.py
Expand Up @@ -16,7 +16,10 @@
M2MModel, ThroughModel, M2MModelThrough, SelfReferencingModel,
UniqueNullFieldModel, UniqueTogetherNullFieldModel,
MultipleUniqueTogetherNullFieldModel, SelfReferencingModelNoNull, GFKModel,
GRModel)
GRModel, RelationWithCustomAutofixtureModel)


autofixture.autodiscover()


if sys.version_info[0] < 3:
Expand Down Expand Up @@ -256,6 +259,19 @@ def test_generate_m2m(self):
self.assertEqual(SimpleModel.objects.count(), len(all_m2m))
self.assertEqual(OtherSimpleModel.objects.count(), len(all_secondm2m))

def test_generate_m2m_with_custom_autofixture(self):
filler = AutoFixture(RelationWithCustomAutofixtureModel,
generate_fk=True,
generate_m2m=(1, 1))
instance = filler.create_one()
self.assertEqual(instance.users.count(), 1)
user = instance.users.get()

# Detect that the UserFixture was used.
self.assertTrue(' ' not in user.username)
self.assertTrue(' ' not in user.first_name)
self.assertTrue(' ' not in user.last_name)

def test_generate_only_some_m2m(self):
filler = AutoFixture(
M2MModel,
Expand Down

0 comments on commit 36b6d65

Please sign in to comment.