Permalink
Browse files

Added tests for gen_ipv4() and gen_ipv6() methods

  • Loading branch information...
1 parent a018939 commit f0c3f22bc23a269a35b0f04e8a8f2ecc124bfd30 @amatellanes amatellanes committed Jan 15, 2014
Showing with 28 additions and 0 deletions.
  1. +8 −0 test/generic/forms.py
  2. +4 −0 test/generic/models.py
  3. +16 −0 test/generic/tests/test_mommy.py
@@ -0,0 +1,8 @@
+from django.forms import ModelForm
+
+from test.generic.models import DummyIPAddressesFieldModel
+
+
+class DummyIPAddressesFieldForm(ModelForm):
+ class Meta:
+ model = DummyIPAddressesFieldModel
@@ -199,3 +199,7 @@ class CustomFieldWithoutGeneratorModel(models.Model):
class DummyUniqueIntegerFieldModel(models.Model):
value = models.IntegerField(unique=True)
+
+
+class DummyIPAddressesFieldModel(models.Model):
+ ip = models.GenericIPAddressField()
@@ -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
@@ -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):
@@ -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.