Skip to content

Commit 8f2a25a

Browse files
committed
fix: deterministic option sort
1 parent cba8fbe commit 8f2a25a

File tree

5 files changed

+14
-10
lines changed

5 files changed

+14
-10
lines changed

caluma/caluma_form/factories.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class Meta:
132132
class QuestionOptionFactory(DjangoModelFactory):
133133
option = SubFactory(OptionFactory)
134134
question = SubFactory(QuestionFactory, type=models.Question.TYPE_CHOICE)
135-
sort = 0
135+
sort = Faker("pyint")
136136

137137
class Meta:
138138
model = models.QuestionOption

caluma/caluma_form/tests/__snapshots__/test_document.ambr

+1-1
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@
835835
}),
836836
dict({
837837
'node': dict({
838-
'label': 'Mary White',
838+
'label': 'Robert Skinner',
839839
'slug': 'anothervalue',
840840
}),
841841
}),

caluma/caluma_form/tests/__snapshots__/test_question.ambr

+5-5
Original file line numberDiff line numberDiff line change
@@ -951,8 +951,8 @@
951951
'__typename': 'MultipleChoiceQuestion',
952952
'defaultAnswer': dict({
953953
'value': list([
954+
'successful-job',
954955
'maybe-stock-capital',
955-
'court-ask',
956956
]),
957957
}),
958958
'hintText': 'test',
@@ -964,14 +964,14 @@
964964
'edges': list([
965965
dict({
966966
'node': dict({
967-
'label': 'William Ramos',
968-
'slug': 'maybe-stock-capital',
967+
'label': 'Jennifer Lee',
968+
'slug': 'successful-job',
969969
}),
970970
}),
971971
dict({
972972
'node': dict({
973-
'label': 'Scott Powell',
974-
'slug': 'court-ask',
973+
'label': 'William Ramos',
974+
'slug': 'maybe-stock-capital',
975975
}),
976976
}),
977977
]),

caluma/caluma_form/tests/test_option.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,10 @@ def test_option_is_hidden(
196196
options = result.data["allDocuments"]["edges"][0]["node"]["answers"]["edges"][0][
197197
"node"
198198
]["question"]["options"]["edges"]
199-
expected = [{"node": {"slug": "bar"}}, {"node": {"slug": "thing-piece"}}]
199+
200+
expected = [{"node": {"slug": "piece-training"}}, {"node": {"slug": "bar"}}]
200201
if is_hidden:
201-
expected = [{"node": {"slug": "thing-piece"}}]
202+
expected = [{"node": {"slug": "piece-training"}}]
202203
assert options == expected
203204

204205

caluma/caluma_form/tests/test_structure.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,10 @@ def test_options(simple_form_structure, form_question_factory, question_option_f
266266
question__type="choice", form=simple_form_structure.form
267267
).question
268268

269-
opts = question_option_factory.create_batch(4, question=choice_q)
269+
opts = sorted(
270+
question_option_factory.create_batch(4, question=choice_q),
271+
key=lambda x: -x.sort,
272+
)
270273
assert choice_q.options.exists()
271274

272275
fieldset = structure.FieldSet(simple_form_structure)

0 commit comments

Comments
 (0)