Skip to content
This repository has been archived by the owner on Oct 22, 2019. It is now read-only.

Commit

Permalink
Merge pull request #230 from romulocollopy/issue_213
Browse files Browse the repository at this point in the history
Adds tests to ensure ovewriting for AutoField's value.
  • Loading branch information
berinhard committed May 25, 2015
2 parents 6bd9610 + b3e8de1 commit 078828a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
2 changes: 2 additions & 0 deletions test/generic/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ class Store(models.Model):
employees = models.ManyToManyField(Person, related_name='employers')
suppliers = models.ManyToManyField(Person, related_name='suppliers', blank=True, null=True)

class DummyEmptyModel(models.Model):
pass

class DummyIntModel(models.Model):
int_field = models.IntegerField()
Expand Down
12 changes: 10 additions & 2 deletions test/generic/tests/test_filling_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.contrib.contenttypes.models import ContentType
from django.db.models.fields import CharField, TextField, SlugField
from django.db.models.fields import DateField, DateTimeField,TimeField, EmailField
from django.db.models.fields import IPAddressField
from django.db.models.fields import IPAddressField, AutoField
try:
from django.db.models.fields import GenericIPAddressField
except ImportError:
Expand All @@ -34,7 +34,7 @@
from test.generic.models import has_pil
from test.generic.models import Person
from test.generic.models import DummyIntModel, DummyPositiveIntModel
from test.generic.models import DummyNumbersModel
from test.generic.models import DummyNumbersModel, DummyEmptyModel
from test.generic.models import DummyDecimalModel, DummyEmailModel
from test.generic.models import DummyGenericForeignKeyModel
from test.generic.models import DummyFileFieldModel
Expand Down Expand Up @@ -341,3 +341,11 @@ def test_raises_unsupported_field_for_custom_field(self):
def test_uses_generator_defined_on_settings_for_custom_field(self):
obj = mommy.make(CustomFieldWithGeneratorModel)
self.assertEqual("value", obj.custom_value)

class FillingAutoFields(TestCase):

def test_filling_AutoField(self):
obj = mommy.make(DummyEmptyModel)
field = DummyEmptyModel._meta.get_field('id')
self.assertIsInstance(field, AutoField)
self.assertIsInstance(obj.id, int)
15 changes: 15 additions & 0 deletions test/generic/tests/test_mommy.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from test.generic.models import DummyNullFieldsModel, DummyBlankFieldsModel
from test.generic.models import DummyDefaultFieldsModel, DummyMultipleInheritanceModel
from test.generic.models import DummyGenericForeignKeyModel, NonAbstractPerson
from test.generic.models import DummyEmptyModel


class ModelFinderTest(TestCase):
Expand Down Expand Up @@ -399,6 +400,20 @@ def test_fill_optional_with_integer(self):
dummy = mommy.make(DummyBlankFieldsModel, _fill_optional=1)


class FillAutoFieldsTestCase(TestCase):

def test_fill_autofields_with_provided_value(self):
dummy = mommy.make(DummyEmptyModel, id=237)
saved_dummy = DummyEmptyModel.objects.get()
self.assertEqual(saved_dummy.id, 237)

def test_keeps_prepare_autovalues(self):
dummy = mommy.prepare(DummyEmptyModel, id=543)
self.assertEqual(dummy.id, 543)
dummy.save()
saved_dummy = DummyEmptyModel.objects.get()
self.assertEqual(saved_dummy.id, 543)

class SkipDefaultsTestCase(TestCase):
def test_skip_fields_with_default(self):
dummy = mommy.make(DummyDefaultFieldsModel)
Expand Down

0 comments on commit 078828a

Please sign in to comment.