Permalink
Browse files

Created GeoDjango PointFieldGenerator

  • Loading branch information...
CarlosMart626 committed Jan 27, 2017
1 parent 01ba0c9 commit 85a6816e4e3771de9775aea6fa092d510e83b803
Showing with 27 additions and 0 deletions.
  1. +7 −0 autofixture/base.py
  2. +13 −0 autofixture/generators.py
  3. +1 −0 autofixture_tests/settings.py
  4. +6 −0 autofixture_tests/tests/test_generator.py
View
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
import warnings
from django.db.models import fields, ImageField
from django.conf import settings
from django.db.models.fields import related
from django.utils.six import with_metaclass
@@ -15,6 +16,9 @@
getargnames,
)
if 'django.contrib.gis' in settings.INSTALLED_APPS:
from django.contrib.gis.db.models import PointField
class CreateInstanceError(Exception):
pass
@@ -121,6 +125,9 @@ class IGNORE_FIELD(object):
if hasattr(fields, 'UUIDField'):
field_to_generator[fields.UUIDField] = generators.UUIDGenerator
if 'django.contrib.gis' in settings.INSTALLED_APPS:
field_to_generator[PointField] = generators.PointFieldGenerator
field_values = Values()
default_constraints = [
View
@@ -3,6 +3,7 @@
import uuid
from django.core.files.base import ContentFile
from django.core.files.storage import default_storage
from django.contrib.gis.geos import Point
try:
from django.utils import lorem_ipsum
except ImportError:
@@ -664,3 +665,15 @@ class UUIDGenerator(Generator):
def generate(self):
return uuid.uuid4()
# Geo
class PointFieldGenerator(Generator):
latitude = 19.99
longitude = 73.78
def generate(self):
dec_lat = random.random() / 100
dec_lon = random.random() / 100
return Point(self.longitude + dec_lat, self.latitude + dec_lon)
@@ -44,6 +44,7 @@
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'django.contrib.gis',
'autofixture',
'autofixture_tests',
@@ -148,3 +148,9 @@ def test_storage(self):
o = AutoFixture(ImageModel).create_one()
self.assertTrue(dummy_storage.exists(o.imgfield.name))
def test_point(self):
from django.contrib.gis.geos import Point
point = generators.PointFieldGenerator().generate()
self.assertIsInstance(point, Point)

0 comments on commit 85a6816

Please sign in to comment.