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

Commit

Permalink
Added tests for gen_ipv4() and gen_ipv6() methods
Browse files Browse the repository at this point in the history
  • Loading branch information
amatellanes committed Jan 15, 2014
1 parent a018939 commit f0c3f22
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions test/generic/forms.py
@@ -0,0 +1,8 @@
from django.forms import ModelForm

from test.generic.models import DummyIPAddressesFieldModel


class DummyIPAddressesFieldForm(ModelForm):
class Meta:
model = DummyIPAddressesFieldModel
4 changes: 4 additions & 0 deletions test/generic/models.py
Expand Up @@ -199,3 +199,7 @@ class CustomFieldWithoutGeneratorModel(models.Model):

class DummyUniqueIntegerFieldModel(models.Model):
value = models.IntegerField(unique=True)


class DummyIPAddressesFieldModel(models.Model):
ip = models.GenericIPAddressField()
16 changes: 16 additions & 0 deletions test/generic/tests/test_mommy.py
Expand Up @@ -8,6 +8,7 @@
from mock import patch, Mock

from model_mommy import mommy
from model_mommy import generators
from model_mommy.exceptions import ModelNotFound, AmbiguousModelName, InvalidQuantityException
from model_mommy.timezone import smart_datetime as datetime
from test.generic.models import Person, Dog, Store, LonelyPerson, School, SchoolEnrollment, ModelWithImpostorField, Classroom, GuardDog
Expand All @@ -16,6 +17,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.forms import DummyIPAddressesFieldForm


class ModelFinderTest(TestCase):
Expand Down Expand Up @@ -340,3 +342,17 @@ def test_skip_fields_with_default(self):
self.assertEqual(dummy.default_decimal_field, Decimal('0'))
self.assertEqual(dummy.default_email_field, 'foo@bar.org')
self.assertEqual(dummy.default_slug_field, 'a-slug')


class MommyGeneratesIPAdresses(TestCase):
def test_create_model_with_valid_ipv4(self):
form_data = {
'ip': generators.gen_ipv4(),
}
self.assertTrue(DummyIPAddressesFieldForm(form_data).is_valid())

def test_create_model_with_valid_ipv6(self):
form_data = {
'ip': generators.gen_ipv6(),
}
self.assertTrue(DummyIPAddressesFieldForm(form_data).is_valid())

0 comments on commit f0c3f22

Please sign in to comment.