Skip to content

Commit

Permalink
Add support for GenericIPAddressField field
Browse files Browse the repository at this point in the history
  • Loading branch information
paulocheque committed Jun 2, 2015
1 parent 3cffded commit c0254e3
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions django_dynamic_fixture/fixture_algorithms/default_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ def binaryfield_config(self, field, key):
def uuidfield_config(self, field, key):
return uuid.uuid4()

# Django >= 1.4
def genericipaddressfield_config(self, field, key):
return self.ipaddressfield_config(field, key)


# GIS/GeoDjango
class GeoDjangoDataFixture(object):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def emailfield_config(self, field, key):
def urlfield_config(self, field, key):
return six.text_type('http://dynamicfixture%s.com') % self.random_string(10)

# Deprecated in Django >= 1.7
def ipaddressfield_config(self, field, key):
a = random.randint(1, 255)
b = random.randint(1, 255)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ def emailfield_config(self, field, key):
def urlfield_config(self, field, key):
return six.text_type('http://dynamicfixture%s.com') % self.get_value(field, key)

# Deprecated in Django >= 1.7
def ipaddressfield_config(self, field, key):
# TODO: better workaround (this suppose ip field is not unique)
data = self.get_value(field, key)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import six
from six.moves import xrange

from django_dynamic_fixture.django_helper import django_greater_than


class DataFixtureTestCase(object):
def setUp(self):
Expand Down Expand Up @@ -51,6 +53,8 @@ def test_formatted_strings(self):
self.assertTrue(isinstance(self.fixture.generate_data(models.EmailField(max_length=100)), six.text_type))
self.assertTrue(isinstance(self.fixture.generate_data(models.URLField(max_length=100)), six.text_type))
self.assertTrue(isinstance(self.fixture.generate_data(models.IPAddressField(max_length=100)), six.text_type))
if django_greater_than('1.4'):
self.assertTrue(isinstance(self.fixture.generate_data(models.GenericIPAddressField(max_length=100)), six.text_type))

def test_files(self):
self.assertTrue(isinstance(self.fixture.generate_data(models.FilePathField(max_length=100)), six.text_type))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def emailfield_config(self, field, key):
def urlfield_config(self, field, key):
return six.text_type('http://dynamicfixture%s.com') % self.random_string(field, key)

# Deprecated in Django >= 1.7
def ipaddressfield_config(self, field, key):
MAX_IP = 2 ** 32 - 1

Expand Down
2 changes: 2 additions & 0 deletions django_dynamic_fixture/models_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class ModelWithFieldsWithCustomValidation(models.Model):
email = models.EmailField(null=True, unique=True)
url = models.URLField(null=True, unique=True)
ip = models.IPAddressField(null=True, unique=False)
if django_greater_than('1.4'):
ipv6 = models.GenericIPAddressField(null=True, unique=False)

class Meta:
verbose_name = 'Custom validation'
Expand Down
2 changes: 2 additions & 0 deletions django_dynamic_fixture/tests/test_ddf.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ def test_new_fill_formatted_strings_fields_with_basic_values(self):
self.assertTrue(isinstance(instance.email, six.text_type))
self.assertTrue(isinstance(instance.url, six.text_type))
self.assertTrue(isinstance(instance.ip, six.text_type))
if django_greater_than('1.4'):
self.assertTrue(isinstance(instance.ipv6, six.text_type))

def test_new_fill_file_fields_with_basic_strings(self):
instance = self.ddf.new(ModelWithFileFields)
Expand Down

0 comments on commit c0254e3

Please sign in to comment.