Skip to content

Commit

Permalink
Split spatial tests
Browse files Browse the repository at this point in the history
  • Loading branch information
caioariede committed Jan 29, 2016
1 parent f8fdaa0 commit a378571
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 29 deletions.
7 changes: 0 additions & 7 deletions tests/models.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
from django.db import models

from location_field.models.plain import PlainLocationField
from location_field.models.spatial import LocationField


class Place(models.Model):
parent_place = models.ForeignKey('self', blank=True, null=True)
city = models.CharField(max_length=255)
location = PlainLocationField(based_fields=['city'], zoom=7)


class SpatialPlace(models.Model):
parent_place = models.ForeignKey('self', blank=True, null=True)
city = models.CharField(max_length=255)
location = LocationField(based_fields=['city'], zoom=7)
9 changes: 9 additions & 0 deletions tests/spatial_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.db import models

from location_field.models.spatial import LocationField


class SpatialPlace(models.Model):
parent_place = models.ForeignKey('self', blank=True, null=True)
city = models.CharField(max_length=255)
location = LocationField(based_fields=['city'], zoom=7)
17 changes: 17 additions & 0 deletions tests/spatial_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from django.test import TestCase
from django.contrib.gis.geos import Point

from tests.spatial_models import SpatialPlace


class LocationFieldSpatialTest(TestCase):
def test_spatial(self):
vals = {
'city': 'Bauru',
'location': 'POINT(-22.2878573 -49.0905487)',
}

obj = SpatialPlace.objects.create(**vals)

self.assertEqual(obj.city, 'Bauru')
self.assertEqual(obj.location, Point(-22.2878573, -49.0905487))
18 changes: 5 additions & 13 deletions tests/test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from django.test import TestCase
from django.contrib.gis.geos import Point
from django.conf import settings

from tests.models import Place, SpatialPlace
from tests.models import Place
from tests.forms import LocationForm

from pyquery import PyQuery as pq
Expand All @@ -22,17 +21,6 @@ def test_plain(self):
self.assertEqual(obj.city, 'Bauru')
self.assertEqual(obj.location, '-22.2878573,-49.0905487')

def test_spatial(self):
vals = {
'city': 'Bauru',
'location': 'POINT(-22.2878573 -49.0905487)',
}

obj = SpatialPlace.objects.create(**vals)

self.assertEqual(obj.city, 'Bauru')
self.assertEqual(obj.location, Point(-22.2878573, -49.0905487))

def test_field_options(self):
form = LocationForm(initial={})
d = pq(str(form))
Expand All @@ -44,3 +32,7 @@ def test_field_options(self):

for key, value in location_field_opts.items():
self.assertEqual(value, opts[key])


if settings.TEST_SPATIAL:
from . import spatial_test
31 changes: 22 additions & 9 deletions tests/test_settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import sys
import os


TEST_SPATIAL = 'TEST_SPATIAL' in os.environ


SECRET_KEY = 'fake-key'
Expand All @@ -8,15 +12,24 @@
"tests",
]

DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.spatialite',
'NAME': 'db.sqlite3',
}
}

STATIC_URL = '/static/'


if sys.platform == 'darwin':
SPATIALITE_LIBRARY_PATH = '/usr/local/lib/mod_spatialite.dylib'
if TEST_SPATIAL:
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.spatialite',
'NAME': 'db.sqlite3',
}
}

if sys.platform == 'darwin':
SPATIALITE_LIBRARY_PATH = '/usr/local/lib/mod_spatialite.dylib'

else:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'db.sqlite3',
}
}

0 comments on commit a378571

Please sign in to comment.