Skip to content

Commit

Permalink
chore: add test for prefetching
Browse files Browse the repository at this point in the history
  • Loading branch information
czosel committed Dec 31, 2024
1 parent 55cf7ec commit 0426441
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
22 changes: 22 additions & 0 deletions caluma/caluma_form/tests/test_question.py
Original file line number Diff line number Diff line change
Expand Up @@ -1198,3 +1198,25 @@ def test_save_action_button_question(db, snapshot, question, schema_executor):
result = schema_executor(query, variable_values=inp)
assert not bool(result.errors)
snapshot.assert_match(result.data)


def test_init_of_calc_questions_queries(
db,
form,
form_and_document,
form_question_factory,
django_assert_num_queries,
):
(form, document, questions_dict, _) = form_and_document(
use_table=True, use_subform=True, table_row_count=10
)

form_question_factory(
form=form,
question__slug="calc_question",
question__type=Question.TYPE_CALCULATED_FLOAT,
question__calc_expression="'table'|answer|mapby('column')|sum + 'top_question'|answer + 'sub_question'|answer",
)

with django_assert_num_queries(38):
api.save_answer(questions_dict["top_question"], document, value="1")
13 changes: 7 additions & 6 deletions caluma/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def fallback_factory(factory, **kwargs):
return existing
return factory(**kwargs)

def factory(use_table=False, use_subform=False):
def factory(use_table=False, use_subform=False, table_row_count=1):
form = fallback_factory(
form_factory, slug="top_form", meta={"is-top-form": True, "level": 0}
)
Expand Down Expand Up @@ -324,11 +324,12 @@ def factory(use_table=False, use_subform=False):
document=document, question=questions["table"]
)

row_doc = document_factory(form=row_form, family=document)
answers["column"] = answer_factory(
document=row_doc, question=questions["column"]
)
answers["table"].documents.add(row_doc)
for _ in range(table_row_count):
row_doc = document_factory(form=row_form, family=document)
answers["column"] = answer_factory(
document=row_doc, question=questions["column"]
)
answers["table"].documents.add(row_doc)

if use_subform:
sub_form = fallback_factory(
Expand Down

0 comments on commit 0426441

Please sign in to comment.