-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add django point field for factories (#19)
* add django point field for factories * fix flake8 * install gdal in github workflow * install spatialite github workflow * dont specify spatialite path, so github workflow hopefully works ... * inherit from proper test case ... * rename test case * mark explicitly for db, even though other test cases dont need it .. * threw in the towel trying to get osx to work, added simple dockerfile setup .. * run against many versions * try to also replace DRF in github workflow * terminate regex replace * fix replacing DRF version * debug prints * fix sed replace * fix drf ver ... * drop support for django < 2? * bump version -> 0.0.4
- Loading branch information
Showing
11 changed files
with
125 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
FROM python:3.9.2 | ||
|
||
# Spatial packages and such | ||
RUN apt-get update && apt-get install -y libgdal-dev libsqlite3-mod-spatialite | ||
|
||
# Python reqs | ||
ADD requirements.txt . | ||
RUN pip install -r requirements.txt | ||
|
||
# add all of our source + config | ||
ADD ckc/ /src/ckc/ | ||
ADD testproject/ /src/testproject | ||
ADD tests/ /src/tests | ||
ADD setup.cfg /src | ||
WORKDIR /src |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# We import here to run the faker factory add_provider stuff... | ||
from . import providers # noqa: F401 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Doing a try/except here so we don't force end users of the | ||
# django-ckc module to install factory boy. | ||
try: | ||
import factory | ||
from django.contrib.gis.geos import Point | ||
from faker.providers import BaseProvider | ||
|
||
class DjangoGeoPointProvider(BaseProvider): | ||
"""Custom helper class giving us the 'geo_point' provider, example: | ||
location = factory.Faker('geo_point', country_code='US') | ||
(note, you must call factory.Faker.add_provider(DjangoGeoPointProvider) to add | ||
this provider!) | ||
""" | ||
|
||
def geo_point(self, **kwargs): | ||
kwargs['coords_only'] = True | ||
faker = factory.faker.faker.Faker() | ||
|
||
# local_latlng returns something like: | ||
# ('40.72371', '-73.95097', 'Greenpoint', 'US', 'America/New_York') | ||
coords = faker.local_latlng(**kwargs) | ||
return Point(x=float(coords[1]), y=float(coords[0]), srid=4326) | ||
|
||
factory.Faker.add_provider(DjangoGeoPointProvider) | ||
except ImportError: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,7 @@ name = django-ckc | |
author = Eric Carmichael | ||
author_email = [email protected] | ||
description = tools, utilities, etc. we use across projects @ ckc | ||
version = 0.0.3 | ||
version = 0.0.4 | ||
url = https://github.com/ckcollab/django-ckc | ||
keywords = | ||
django | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import factory | ||
|
||
from factory.django import DjangoModelFactory | ||
|
||
from testapp.models import Location | ||
|
||
|
||
class LocationFactory(DjangoModelFactory): | ||
geo_point = factory.Faker('geo_point', country_code='US') | ||
|
||
class Meta: | ||
model = Location |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from django.test import TestCase | ||
|
||
from django.contrib.gis.geos import Point | ||
|
||
from testapp.factories import LocationFactory | ||
|
||
|
||
class TestFactories(TestCase): | ||
def test_location_factory_point_works(self): | ||
location = LocationFactory() | ||
assert location.geo_point.x | ||
assert location.geo_point.y | ||
|
||
location = LocationFactory(geo_point=Point(x=50, y=50)) | ||
assert location.geo_point.x == 50 | ||
assert location.geo_point.y == 50 |