Skip to content

Commit

Permalink
Fixes formatting issue caused by setting location_geometry to geoshape (
Browse files Browse the repository at this point in the history
  • Loading branch information
linzjax authored and ian-ross committed Sep 20, 2016
1 parent ef98bbf commit c20a4c7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cadasta/xforms/mixins/model_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.utils.translation import ugettext as _
from party.models import Party, TenureRelationship, TenureRelationshipType
from pyxform.xform2json import XFormToDict
from questionnaires.models import Questionnaire
from questionnaires.models import Questionnaire, Question
from resources.models import Resource
from spatial.models import SpatialUnit
from xforms.exceptions import InvalidXMLSubmission
Expand Down Expand Up @@ -75,7 +75,8 @@ def create_spatial_unit(self, data, project, questionnaire, party=None):
geoshape = True
else:
location_geometry = data['location_geometry']
geoshape = False
geoshape = Question.objects.filter(
questionnaire=questionnaire, type='GS').exists()
try:
location = SpatialUnit.objects.create(
project=project,
Expand Down
28 changes: 28 additions & 0 deletions cadasta/xforms/tests/files/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,33 @@
</meta>
</test_standard_questionnaire_2>'''.strip()

NEITHER_FORM = '''<?xml version=\'1.0\' ?>
<test_standard_questionnaire_2
id="test_standard_questionnaire_2" version="20160727122111">
<start>2016-07-07T16:38:20.310-04</start>
<end>2016-07-07T16:39:23.673-04</end>
<today>2016-07-07</today>
<deviceid>00:bb:3a:44:d0:fb</deviceid>
<title />
<party_type>IN</party_type>
<party_name>Natashia Romanoff</party_name>
<location_choice>neither</location_choice>
<location_geoshape>45.56342779158167 -122.67650283873081 0.0 0.0;
45.56176327330353 -122.67669159919024 0.0 0.0;
45.56151562182025 -122.67490658909082 0.0 0.0;
45.563479432877415 -122.67494414001703 0.0 0.0;
45.56176327330353 -122.67669159919024 0.0 0.0
</location_geoshape>
<location_type>MI</location_type>
<tenure_type>LH</tenure_type>
<location_attributes>
<name>Geoshape</name>
</location_attributes>
<meta>
<instanceID>uuid:b3f225d3-0fac-4a0b-80c7-60e6db4cc0ad</instanceID>
</meta>
</test_standard_questionnaire_2>'''.strip()

BAD_QUESTIONNAIRE = '''<?xml version=\'1.0\' ?>
<tax_return id="tax_return" version="20160727122110">
<start>2016-07-07T16:38:20.310-04</start>
Expand Down Expand Up @@ -273,6 +300,7 @@
'poly_form': POLY_FORM,
'missing_semi_form': MISSING_SEMI_FORM,
'geoshape_form': GEOSHAPE_FORM,
'location_geoshape_form': NEITHER_FORM,
'bad_questionnaire': BAD_QUESTIONNAIRE,
'bad_location_form': BAD_LOCATION_FORM,
'bad_party_form': BAD_PARTY_FORM,
Expand Down
9 changes: 9 additions & 0 deletions cadasta/xforms/tests/test_views_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,15 @@ def test_geoshape_upload(self):
assert response.status_code == 201
assert geom.geometry.geom_type == 'Polygon'

def test_geoshape_as_location_geometry_upload(self):
data = self._submission(form='location_geoshape_form')
response = self.request(method='POST', user=self.user, post_data=data,
content_type='multipart/form-data')

geom = SpatialUnit.objects.get(attributes={'name': 'Geoshape'})
assert response.status_code == 201
assert geom.geometry.geom_type == 'Polygon'

def test_invalid_submission_upload(self):
# testing submitting with a missing xml_submission_file
data = self._invalid_submission(form='This is not an xml form!')
Expand Down

0 comments on commit c20a4c7

Please sign in to comment.