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
alukach authored and oliverroick committed Apr 12, 2018
1 parent 826df38 commit bff28be
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
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
28 changes: 28 additions & 0 deletions cadasta/spatial/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,34 @@ def test_location_type_label_questionnaire_default_lang(self):
type='HOUSE')
assert su.location_type_label == 'House'

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')
assert su.location_type_label == 'House'

def test_location_type_label_questionnaire_selected_lang(self):
activate('es')
questionnaire = q_factories.QuestionnaireFactory.create(
Expand Down

0 comments on commit bff28be

Please sign in to comment.