Skip to content

Commit

Permalink
fix(tests): remove DeprecationWarnings
Browse files Browse the repository at this point in the history
Fix DeprecationWarnings in tests.
`Schema.execute()` deprecated keyword argument `variables` and
`context` in favour of `variable_values` and `context_values`
respectively.
  • Loading branch information
Stefan Borer committed Jun 4, 2020
1 parent 2f35191 commit 262682e
Show file tree
Hide file tree
Showing 26 changed files with 143 additions and 135 deletions.
2 changes: 1 addition & 1 deletion caluma/caluma_core/tests/test_inversible_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_inversible_with_vars(db, schema_executor, document_factory):
}
"""

result = schema_executor(query, variables=variables)
result = schema_executor(query, variable_values=variables)
assert not result.errors

result_ids = [
Expand Down
2 changes: 1 addition & 1 deletion caluma/caluma_core/tests/test_meta_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_meta_value_filter(
if lookup:
variables["filter"][0]["lookup"] = lookup

result = schema_executor(query, variables=variables)
result = schema_executor(query, variable_values=variables)

assert not result.errors

Expand Down
2 changes: 1 addition & 1 deletion caluma/caluma_core/tests/test_mutation_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def check_perm(self, mutation, info):

result = schema_executor(
query,
variables={
variable_values={
"quest": {
"slug": "email_addr",
"label": "hello",
Expand Down
2 changes: 1 addition & 1 deletion caluma/caluma_core/tests/test_ordersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def result_ids(result):
]

def get_ordered(ordering):
result = schema_executor(query, variables={"order": ordering})
result = schema_executor(query, variable_values={"order": ordering})
assert not result.errors
return result_ids(result)

Expand Down
2 changes: 1 addition & 1 deletion caluma/caluma_core/tests/test_pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_has_next_previous(

inp = {"first": first, "last": last, "before": before, "after": after}

result = schema_executor(query, variables=inp)
result = schema_executor(query, variable_values=inp)

assert not result.errors
assert result.data["allDocuments"]["pageInfo"]["hasNextPage"] == has_next
Expand Down
8 changes: 4 additions & 4 deletions caluma/caluma_data_source/tests/test_data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def test_data_source_failure(data_source, schema_executor, settings):

inp = {"name": data_source}

result = schema_executor(query, variables=inp)
result = schema_executor(query, variable_values=inp)
assert result.errors


Expand All @@ -144,7 +144,7 @@ def test_data_source_defaults(snapshot, schema_executor, settings):
}
"""

result = schema_executor(query, variables={})
result = schema_executor(query, variable_values={})
assert not result.errors
snapshot.assert_match(result.data)

Expand All @@ -171,7 +171,7 @@ def test_data_source_exception(schema_executor, settings):
}
"""

result = schema_executor(query, variables={})
result = schema_executor(query, variable_values={})
assert result.errors


Expand Down Expand Up @@ -243,7 +243,7 @@ def __str__(self):
}
}
assert not DynamicOption.objects.exists()
result = schema_executor(query, variables=variables, info=info)
result = schema_executor(query, variable_values=variables, info=info)
assert not result.errors
assert DynamicOption.objects.filter(
document=document,
Expand Down
4 changes: 3 additions & 1 deletion caluma/caluma_form/tests/test_answer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ def test_remove_answer(db, snapshot, question, answer, schema_executor):
}
"""

result = schema_executor(query, variables={"input": {"answer": str(answer.pk)}})
result = schema_executor(
query, variable_values={"input": {"answer": str(answer.pk)}}
)

assert not result.errors
with pytest.raises(models.Answer.DoesNotExist):
Expand Down
40 changes: 22 additions & 18 deletions caluma/caluma_form/tests/test_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def test_query_all_documents(
answer.save()
search = answer.file.name

result = schema_executor(query, variables={"search": search})
result = schema_executor(query, variable_values={"search": search})
assert not result.errors
snapshot.assert_match(result.data)

Expand Down Expand Up @@ -265,7 +265,7 @@ def test_complex_document_query_performance(
"""

with django_assert_num_queries(8):
result = schema_executor(query, variables={"id": str(document.pk)})
result = schema_executor(query, variable_values={"id": str(document.pk)})
assert not result.errors


Expand All @@ -292,7 +292,7 @@ def test_query_all_documents_filter_answers_by_question(
}
"""

result = schema_executor(query, variables={"question": question.slug})
result = schema_executor(query, variable_values={"question": question.slug})
assert not result.errors
assert len(result.data["allDocuments"]["edges"]) == 1
result_document = result.data["allDocuments"]["edges"][0]["node"]
Expand Down Expand Up @@ -333,7 +333,7 @@ def test_query_all_documents_filter_answers_by_questions(
"""

result = schema_executor(
query, variables={"questions": [questions[0].slug, questions[1].slug]}
query, variable_values={"questions": [questions[0].slug, questions[1].slug]}
)
assert not result.errors
assert len(result.data["allDocuments"]["edges"]) == 3
Expand Down Expand Up @@ -372,7 +372,7 @@ def test_save_document(db, document, schema_executor, update):
# not update = create = we don't pass the ID
del inp["input"]["id"]

result = schema_executor(query, variables=inp)
result = schema_executor(query, variable_values=inp)

assert not result.errors
assert result.data["saveDocument"]["document"]["form"]["slug"] == document.form.slug
Expand Down Expand Up @@ -740,7 +740,7 @@ def test_save_document_answer(
# delete answer to force create test instead of update
Answer.objects.filter(pk=answer.pk).delete()

result = schema_executor(query, variables=inp)
result = schema_executor(query, variable_values=inp)

assert not bool(result.errors) == success
if success:
Expand Down Expand Up @@ -780,7 +780,7 @@ def test_save_document_answer_empty(
# delete answer to force create test instead of update
Answer.objects.filter(pk=answer.pk).delete()

result = schema_executor(query, variables=inp)
result = schema_executor(query, variable_values=inp)

assert not result.errors
snapshot.assert_match(result.data)
Expand Down Expand Up @@ -817,7 +817,7 @@ def test_save_document_table_answer_invalid_row_document(
}
inp["input"]["value"] = [str(document_factory(form=question.row_form).pk)]

result = schema_executor(query, variables=inp)
result = schema_executor(query, variable_values=inp)
assert not result.errors


Expand All @@ -842,7 +842,7 @@ def test_save_document_table_answer_invalid_row_form(
inp["input"]["value"] = [
str(document.pk) for document in document_factory.create_batch(1)
]
result = schema_executor(query, variables=inp)
result = schema_executor(query, variable_values=inp)
assert result.errors


Expand Down Expand Up @@ -884,7 +884,7 @@ def test_save_document_table_answer_setting_family(

# attach documents to table answer
inp["input"]["value"] = {remaining_document.pk, to_be_deleted_document.pk}
result = schema_executor(query, variables=inp)
result = schema_executor(query, variable_values=inp)
assert not result.errors
assert {main_pk, to_be_deleted_table_row.pk} | inp["input"]["value"] == set(
Document.objects.filter(family=main_family).values_list("id", flat=True)
Expand All @@ -896,7 +896,7 @@ def test_save_document_table_answer_setting_family(

# detach one document answer from table answer
inp["input"]["value"] = {remaining_document.pk}
result = schema_executor(query, variables=inp)
result = schema_executor(query, variable_values=inp)
assert not result.errors
assert {main_pk} | inp["input"]["value"] == set(
Document.objects.filter(family=main_family).values_list("id", flat=True)
Expand All @@ -921,7 +921,7 @@ def test_query_answer_node(db, answer, schema_executor):
}
"""

result = schema_executor(node_query, variables={"id": global_id})
result = schema_executor(node_query, variable_values={"id": global_id})
assert not result.errors


Expand Down Expand Up @@ -963,7 +963,7 @@ def test_validity_query(db, form, question, document, is_valid, schema_executor)
}
"""

result = schema_executor(query, variables={"document_id": document.id})
result = schema_executor(query, variable_values={"document_id": document.id})

# if is_valid, we expect 0 errors, otherwise one
num_errors = int(not is_valid)
Expand Down Expand Up @@ -1008,7 +1008,7 @@ def filter_queryset_for_document(self, node, queryset, info):

mocker.patch("caluma.caluma_core.types.Node.visibility_classes", [CustomVisibility])

result = schema_executor(query, variables={"document_id": document.id})
result = schema_executor(query, variable_values={"document_id": document.id})

if hide_documents:
assert result.data["documentValidity"] is None
Expand All @@ -1028,7 +1028,9 @@ def test_remove_document_without_case(db, document, answer, schema_executor):
}
"""

result = schema_executor(query, variables={"input": {"document": str(document.pk)}})
result = schema_executor(
query, variable_values={"input": {"document": str(document.pk)}}
)

assert not result.errors
with pytest.raises(Document.DoesNotExist):
Expand All @@ -1049,7 +1051,9 @@ def test_remove_document_with_case(db, document, answer, case, schema_executor):
}
"""

result = schema_executor(query, variables={"input": {"document": str(document.pk)}})
result = schema_executor(
query, variable_values={"input": {"document": str(document.pk)}}
)

assert result.errors
Document.objects.get(pk=document.pk)
Expand Down Expand Up @@ -1091,7 +1095,7 @@ def test_remove_document_without_case_table(
"""

result = schema_executor(
query, variables={"input": {"document": str(table_answer.document.pk)}}
query, variable_values={"input": {"document": str(table_answer.document.pk)}}
)

assert not result.errors
Expand Down Expand Up @@ -1169,7 +1173,7 @@ def test_copy_document(
"""

result = schema_executor(
query, variables={"input": {"source": str(main_document.pk)}}
query, variable_values={"input": {"source": str(main_document.pk)}}
)
assert not result.errors

Expand Down
8 changes: 4 additions & 4 deletions caluma/caluma_form/tests/test_filter_by_answer.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def test_query_all_questions(
}
}
""",
variables={"form_id": top_form.pk},
variable_values={"form_id": top_form.pk},
)

document_id = extract_global_id(result.data["saveDocument"]["document"]["id"])
Expand Down Expand Up @@ -138,7 +138,7 @@ def test_query_all_questions(
if hierarchy_lookup is not None:
variables["hasAnswer"][0]["hierarchy"] = hierarchy_lookup

result = schema_executor(query, variables=variables)
result = schema_executor(query, variable_values=variables)
# note: result.errors may contain stuff that pytest-snapshottest cannot
# serialize properly, thus we stringify it
snapshot.assert_match(
Expand Down Expand Up @@ -192,7 +192,7 @@ def test_has_answer_intersect(
]
}

result = schema_executor(query, variables=variables)
result = schema_executor(query, variable_values=variables)
assert not result.errors

expect_count = 1 if expect_find else 0
Expand Down Expand Up @@ -223,7 +223,7 @@ def test_visible_in_context(
"""
variables = {"visible": True}

result = schema_executor(query, variables=variables)
result = schema_executor(query, variable_values=variables)
assert not result.errors
assert (
len(result.data["allDocuments"]["edges"][0]["node"]["answers"]["edges"])
Expand Down
18 changes: 9 additions & 9 deletions caluma/caluma_form/tests/test_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_query_all_forms(

result = schema_executor(
query,
variables={
variable_values={
"question": question.label,
"orderBy": ["NAME_ASC", "CREATED_AT_ASC"],
},
Expand Down Expand Up @@ -81,7 +81,7 @@ def test_save_form(db, snapshot, form, settings, schema_executor, language_code)

inp = {"input": extract_serializer_input_fields(SaveFormSerializer, form)}
with translation.override(language_code):
result = schema_executor(query, variables=inp)
result = schema_executor(query, variable_values=inp)

assert not result.errors
snapshot.assert_match(result.data)
Expand All @@ -100,7 +100,7 @@ def test_save_form_created_as_admin_user(db, form, admin_schema_executor, admin_

inp = {"input": extract_serializer_input_fields(SaveFormSerializer, form)}
form.delete() # test creation of form
result = admin_schema_executor(query, variables=inp)
result = admin_schema_executor(query, variable_values=inp)

assert not result.errors
assert result.data["saveForm"]["form"]["createdByUser"] == admin_user.username
Expand All @@ -121,7 +121,7 @@ def test_copy_form(db, form, form_question_factory, schema_executor):
"""

inp = {"input": {"source": form.pk, "slug": "new-form", "name": "Test Form"}}
result = schema_executor(query, variables=inp)
result = schema_executor(query, variable_values=inp)

assert not result.errors

Expand Down Expand Up @@ -163,7 +163,7 @@ def test_add_form_question(db, form, question, form_question_factory, schema_exe

result = schema_executor(
query,
variables={
variable_values={
"input": {
"form": to_global_id(type(form).__name__, form.pk),
"question": to_global_id(type(question).__name__, question.pk),
Expand Down Expand Up @@ -199,7 +199,7 @@ def test_remove_form_question(

result = schema_executor(
query,
variables={
variable_values={
"input": {
"form": to_global_id(type(form).__name__, form.pk),
"question": to_global_id(type(question).__name__, question.pk),
Expand Down Expand Up @@ -236,7 +236,7 @@ def test_reorder_form_questions(db, form, form_question_factory, schema_executor
)
result = schema_executor(
query,
variables={
variable_values={
"input": {
"form": to_global_id(type(form).__name__, form.pk),
"questions": [
Expand Down Expand Up @@ -283,7 +283,7 @@ def test_reorder_form_questions_invalid_question(

result = schema_executor(
query,
variables={
variable_values={
"input": {
"form": to_global_id(type(form).__name__, form.pk),
"questions": [
Expand Down Expand Up @@ -319,7 +319,7 @@ def test_reorder_form_questions_duplicated_question(

result = schema_executor(
query,
variables={
variable_values={
"input": {
"form": to_global_id(type(form).__name__, form.pk),
"questions": [question.slug, question.slug],
Expand Down
2 changes: 1 addition & 1 deletion caluma/caluma_form/tests/test_format_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def test_base_format_validators(

inp = {"input": extract_serializer_input_fields(SaveAnswerSerializer, answer)}

result = schema_executor(query, variables=inp)
result = schema_executor(query, variable_values=inp)

assert not bool(result.errors) == success
if success:
Expand Down
Loading

0 comments on commit 262682e

Please sign in to comment.