Skip to content

Commit

Permalink
Use QuestionOption.question.name when fetching location_type question
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony Lukach committed Apr 11, 2018
1 parent 826df38 commit 8150a65
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions cadasta/spatial/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ def set_label_on_spatialunits(sender, instance, **kwargs):
try:
rel_questionoption = QuestionOption.objects.get(
name=instance.type,
question__name='location_type',
question__questionnaire__id=instance.project.current_questionnaire)
except QuestionOption.DoesNotExist:
return
Expand Down
26 changes: 25 additions & 1 deletion cadasta/spatial/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def test_location_type_label_standard(self):
su = SpatialUnitFactory.create(type="RW")
assert su.location_type_label == "Right-of-way"

def test_location_type_label_questionnaire_default_lang(self):
def test_location_type_label_standard(self):
questionnaire = q_factories.QuestionnaireFactory.create(
default_language='en')
question = q_factories.QuestionFactory.create(
Expand All @@ -136,6 +136,30 @@ def test_location_type_label_questionnaire_default_lang(self):
name='HOUSE',
label={'en': 'House', 'de': 'Hause'}
)

def test_location_type_label_uses_correct_question_option(self):
"""
Ensure that the label setter pre_save signal fetches the correct
question option.
"""
questionnaire = q_factories.QuestionnaireFactory.create(
default_language='en')
location_question = q_factories.QuestionFactory.create(
questionnaire=questionnaire,
name='location_type',
type='S1'
)
other_question = q_factories.QuestionFactory.create(
questionnaire=questionnaire,
name='least_favorite_music_genre',
type='S1'
)
for q in (location_question, other_question):
q_factories.QuestionOptionFactory.create(
question=q,
name='HOUSE',
label={'en': 'House', 'de': 'Hause'}
)
su = SpatialUnitFactory.create(
project=questionnaire.project,
type='HOUSE')
Expand Down

0 comments on commit 8150a65

Please sign in to comment.