Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
juuso-j committed Feb 8, 2024
1 parent 63982d9 commit 0d7f126
Showing 1 changed file with 32 additions and 25 deletions.
57 changes: 32 additions & 25 deletions profiles/tests/test_import_questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_import_questions():
assert results_qs[5].description_sv[-12:] == "använda bil."

# Test questions
assert Question.objects.count() == 20
assert Question.objects.count() == 16
# Test question without sub questions
question1b1 = Question.objects.get(number="1b1")
assert question1b1.question_fi == "Miksi et koskaan kulje autolla?"
Expand All @@ -54,8 +54,8 @@ def test_import_questions():
assert sub_q_qs.count() == 8
sq_auto = sub_q_qs.get(order_number=0)
assert sq_auto.description_en == "Car"
assert Option.objects.filter(sub_question=sq_auto).count() == 6
sq_auto_4_5 = Option.objects.get(sub_question=sq_auto, order_number=4)
assert Option.objects.filter(sub_question=sq_auto).count() == 5
sq_auto_4_5 = Option.objects.get(sub_question=sq_auto, order_number=3)
assert sq_auto_4_5.value == "4-5"
sq_auto_4_5_results = sq_auto_4_5.results.all()
assert sq_auto_4_5_results.count() == 2
Expand All @@ -64,8 +64,8 @@ def test_import_questions():

sq_walk = sub_q_qs.get(order_number=6)
sq_walk.description_sv == "Gående"
assert Option.objects.filter(sub_question=sq_walk).count() == 6
assert Option.objects.get(sub_question=sq_walk, order_number=2).value == "1"
assert Option.objects.filter(sub_question=sq_walk).count() == 5
assert Option.objects.get(sub_question=sq_walk, order_number=1).value == "1"
question1d = Question.objects.get(number="1d")
assert question1d.num_sub_questions == 0
assert Option.objects.filter(question=question1d).count() == 3
Expand Down Expand Up @@ -94,27 +94,35 @@ def test_import_questions():
)
assert sub_question_condition.option == Option.objects.get(value_fi="Linja-autolla")

question14 = Question.objects.get(number="14")
assert question14.options.count() == 2
assert (
question14.options.all().order_by("id")[1].value_en == "most comfortable route"
)
question8 = Question.objects.get(number="8")
assert question8.options.count() == 5
assert question8.options.all().order_by("id")[4].value_en == "Other:"
# Test question condition
assert QuestionCondition.objects.all().count() == 13
conditions = QuestionCondition.objects.filter(question=question14)
assert conditions.count() == 2
sq_train = SubQuestion.objects.get(question=question1, order_number=2)
condition = conditions.get(
question_condition=question1, sub_question_condition=sq_train
assert QuestionCondition.objects.all().count() == 9
conditions = QuestionCondition.objects.filter(question=question8)
assert conditions.count() == 1
condition_qs = QuestionCondition.objects.filter(
question_condition=question1, sub_question_condition=sq_auto
)
assert condition_qs.count() == 3
condition = QuestionCondition.objects.get(
question=Question.objects.get(number="1a"),
question_condition=question1,
sub_question_condition=sq_auto,
)
assert condition.option_conditions.count() == 5
assert condition.option_conditions.all()[0].value == "<1"
assert condition.option_conditions.all()[4].value == "6-7"
assert condition.option_conditions.count() == 4
assert condition.option_conditions.all()[0].value == "1"
assert condition.option_conditions.all()[3].value == "6-7"

# Test other options
other_options_qs = Option.objects.filter(is_other=True)
assert other_options_qs.count() == 11
assert other_options_qs.first().question == Question.objects.get(number="1a")
# Test that rows are preserved and duplicates are not generated
import_command()
assert Result.objects.count() == 6
assert Question.objects.count() == 20
assert QuestionCondition.objects.all().count() == 13
assert Question.objects.count() == 16
assert QuestionCondition.objects.all().count() == 9

assert question4.id == Question.objects.get(number="4").id
new_joukkoliikenne = SubQuestion.objects.get(question=question4, order_number=2)
Expand All @@ -125,13 +133,12 @@ def test_import_questions():
assert option_saa_results[0].id == new_option_saa_results[0].id
assert option_saa_results[1].id == new_option_saa_results[1].id
assert option_saa_results[2].id == new_option_saa_results[2].id
assert question14.id == Question.objects.get(number="14").id
assert question8.id == Question.objects.get(number="8").id
assert autoilija.id == Result.objects.get(topic_fi="Autoilija").id
question8 = Question.objects.get(number="8")

# Test that rows with info of Category 2 is skipped
question8 = Question.objects.get(number="8")
assert Option.objects.filter(question=question8).count() == 5
condition = QuestionCondition.objects.get(question=question8)
assert condition.question_condition == Question.objects.get(number="7")
assert condition.option_conditions.all()[0].value_fi == "Ei"
question10 = Question.objects.get(number="10")
assert question10.options.count() == 5

0 comments on commit 0d7f126

Please sign in to comment.