mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-07-13 17:52:19 +03:00
resolving issues with test
This commit is contained in:
parent
054ebaa57d
commit
4b0ca35e2c
|
@ -3,7 +3,7 @@ class FieldResolverObservable(object):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""A new Observable by filterset"""
|
"""A new Observable by filterset"""
|
||||||
super(FieldResolverObservable).__init__()
|
super(FieldResolverObservable, self).__init__()
|
||||||
self._fields = {}
|
self._fields = {}
|
||||||
|
|
||||||
def attach(self, field, processor):
|
def attach(self, field, processor):
|
||||||
|
|
|
@ -45,7 +45,7 @@ def generate_query(field, query_str):
|
||||||
return query
|
return query
|
||||||
|
|
||||||
|
|
||||||
def filter_generation(field, query_str, expected_arguments, method_to_mock="query"):
|
def filter_generation(field, query_str, verify_arguments, method_to_mock="query"):
|
||||||
a1, a2 = fake_data()
|
a1, a2 = fake_data()
|
||||||
|
|
||||||
query = generate_query(field, query_str)
|
query = generate_query(field, query_str)
|
||||||
|
@ -72,7 +72,7 @@ def filter_generation(field, query_str, expected_arguments, method_to_mock="quer
|
||||||
|
|
||||||
assert not result.errors
|
assert not result.errors
|
||||||
|
|
||||||
mock_query.assert_called_with(expected_arguments)
|
verify_arguments(mock_query)
|
||||||
|
|
||||||
assert len(result.data[field]["edges"]) == 2
|
assert len(result.data[field]["edges"]) == 2
|
||||||
assert result.data[field]["edges"][0]["node"]["headline"] == "a1"
|
assert result.data[field]["edges"][0]["node"]["headline"] == "a1"
|
||||||
|
|
|
@ -28,7 +28,7 @@ def test_filter_string():
|
||||||
filter_generation(
|
filter_generation(
|
||||||
"articlesAsField",
|
"articlesAsField",
|
||||||
'headline: "A text"',
|
'headline: "A text"',
|
||||||
Bool(must=[Match(headline={"query": "A text", "fuzziness": "auto"})]),
|
lambda mock: mock.assert_called_with(Bool(must=[Match(headline={"query": "A text", "fuzziness": "auto"})])),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ def test_filter_string_date():
|
||||||
filter_generation(
|
filter_generation(
|
||||||
"articlesAsField",
|
"articlesAsField",
|
||||||
'headline: "A text"',
|
'headline: "A text"',
|
||||||
Bool(must=[Match(headline={"query": "A text", "fuzziness": "auto"})]),
|
lambda mock: mock.assert_called_with(Bool(must=[Match(headline={"query": "A text", "fuzziness": "auto"})])),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ def test_filter_as_field_order_by():
|
||||||
filter_generation(
|
filter_generation(
|
||||||
"articlesAsField",
|
"articlesAsField",
|
||||||
'headline: "A text", sort:{order:desc, field:id}',
|
'headline: "A text", sort:{order:desc, field:id}',
|
||||||
{"id": {"order": "desc"}},
|
lambda mock: mock.assert_called_with({"id": {"order": "desc"}}),
|
||||||
"sort",
|
"sort",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ def test_filter_as_field_order_by_dict():
|
||||||
filter_generation(
|
filter_generation(
|
||||||
"articlesInMeta",
|
"articlesInMeta",
|
||||||
'headline: "A text", sort:{order:desc, field:id}',
|
'headline: "A text", sort:{order:desc, field:id}',
|
||||||
{"es_id": {"order": "desc"}},
|
lambda mock: mock.assert_called_with({"es_id": {"order": "desc"}}),
|
||||||
"sort",
|
"sort",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ def test_filter_in_meta():
|
||||||
filter_generation(
|
filter_generation(
|
||||||
"articlesInMeta",
|
"articlesInMeta",
|
||||||
'headline: "A text"',
|
'headline: "A text"',
|
||||||
Bool(must=[Match(headline={"query": "A text", "fuzziness": "auto"})]),
|
lambda mock: mock.assert_called_with(Bool(must=[Match(headline={"query": "A text", "fuzziness": "auto"})])),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ def test_filter_in_meta_dict():
|
||||||
filter_generation(
|
filter_generation(
|
||||||
"articlesInMetaDict",
|
"articlesInMetaDict",
|
||||||
'headline: "A text"',
|
'headline: "A text"',
|
||||||
Bool(must=[Match(headline={"query": "A text", "fuzziness": "auto"})]),
|
lambda mock: mock.assert_called_with(Bool(must=[Match(headline={"query": "A text", "fuzziness": "auto"})])),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ def test_filter_in_meta_dict_foreign():
|
||||||
filter_generation(
|
filter_generation(
|
||||||
"articlesInMetaDict",
|
"articlesInMetaDict",
|
||||||
'reporterEmail: "A mail"',
|
'reporterEmail: "A mail"',
|
||||||
Bool(must=[Match(reporter__email={"query": "A mail", "fuzziness": "auto"})]),
|
lambda mock: mock.assert_called_with(Bool(must=[Match(reporter__email={"query": "A mail", "fuzziness": "auto"})])),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ def test_filter_in_multi_field():
|
||||||
filter_generation(
|
filter_generation(
|
||||||
"articlesInMultiField",
|
"articlesInMultiField",
|
||||||
'contain: "A text"',
|
'contain: "A text"',
|
||||||
Bool(
|
lambda mock: mock.assert_called_with(Bool(
|
||||||
must=[
|
must=[
|
||||||
Bool(
|
Bool(
|
||||||
should=[
|
should=[
|
||||||
|
@ -95,11 +95,23 @@ def test_filter_in_multi_field():
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
),
|
)),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def compare_must_array(must, other_must):
|
||||||
|
assert len(must) == len(other_must)
|
||||||
|
|
||||||
|
for target in must:
|
||||||
|
assert target in other_must
|
||||||
|
|
||||||
|
|
||||||
def test_filter_generating_all():
|
def test_filter_generating_all():
|
||||||
|
spected_query = Bool(must=[Match(headline={"query": "A text", "fuzziness": "auto"}),
|
||||||
|
Match(pub_date={"query": "0000-00-00", "fuzziness": "auto"}),
|
||||||
|
Match(pub_date_time={"query": "00:00:00", "fuzziness": "auto"}),
|
||||||
|
Match(lang={"query": "es", "fuzziness": "auto"}), Term(importance=1), ])
|
||||||
|
|
||||||
filter_generation(
|
filter_generation(
|
||||||
"articlesInGenerateAll",
|
"articlesInGenerateAll",
|
||||||
'headline: "A text", '
|
'headline: "A text", '
|
||||||
|
@ -107,15 +119,7 @@ def test_filter_generating_all():
|
||||||
'pubDateTime: "00:00:00", '
|
'pubDateTime: "00:00:00", '
|
||||||
'lang: "es", '
|
'lang: "es", '
|
||||||
"importance: 1, ",
|
"importance: 1, ",
|
||||||
Bool(
|
lambda mock: compare_must_array(mock.call_args[0][0].must, spected_query.must),
|
||||||
must=[
|
|
||||||
Match(headline={"query": "A text", "fuzziness": "auto"}),
|
|
||||||
Match(pub_date={"query": "0000-00-00", "fuzziness": "auto"}),
|
|
||||||
Match(pub_date_time={"query": "00:00:00", "fuzziness": "auto"}),
|
|
||||||
Match(lang={"query": "es", "fuzziness": "auto"}),
|
|
||||||
Term(importance=1),
|
|
||||||
]
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ def test_processor_term():
|
||||||
filter_generation(
|
filter_generation(
|
||||||
"articlesInMetaDict",
|
"articlesInMetaDict",
|
||||||
'headlineTerm: "A text"',
|
'headlineTerm: "A text"',
|
||||||
Bool(must=[Term(headline="A text")]),
|
lambda mock: mock.assert_called_with(Bool(must=[Term(headline="A text")])),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ def test_processor_regex():
|
||||||
filter_generation(
|
filter_generation(
|
||||||
"articlesInMetaDict",
|
"articlesInMetaDict",
|
||||||
'headlineRegex: "A text"',
|
'headlineRegex: "A text"',
|
||||||
Bool(must=[Wildcard(headline="A text")]),
|
lambda mock: mock.assert_called_with(Bool(must=[Wildcard(headline="A text")])),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ def test_processor_phrase():
|
||||||
filter_generation(
|
filter_generation(
|
||||||
"articlesInMetaDict",
|
"articlesInMetaDict",
|
||||||
'headlinePhrase: "A text"',
|
'headlinePhrase: "A text"',
|
||||||
Bool(must=[MatchPhrase(headline={"query": "A text"})]),
|
lambda mock: mock.assert_called_with(Bool(must=[MatchPhrase(headline={"query": "A text"})])),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ def test_processor_prefix():
|
||||||
filter_generation(
|
filter_generation(
|
||||||
"articlesInMetaDict",
|
"articlesInMetaDict",
|
||||||
'headlinePrefix: "A text"',
|
'headlinePrefix: "A text"',
|
||||||
Bool(must=[MatchPhrasePrefix(headline={"query": "A text"})]),
|
lambda mock: mock.assert_called_with(Bool(must=[MatchPhrasePrefix(headline={"query": "A text"})])),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ def test_processor_in():
|
||||||
filter_generation(
|
filter_generation(
|
||||||
"articlesInMetaDict",
|
"articlesInMetaDict",
|
||||||
'headlineIn: ["A text 1", "A text 2"]',
|
'headlineIn: ["A text 1", "A text 2"]',
|
||||||
Bool(must=[Terms(headline=["A text 1", "A text 2"])]),
|
lambda mock: mock.assert_called_with(Bool(must=[Terms(headline=["A text 1", "A text 2"])])),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ def test_processor_exits():
|
||||||
filter_generation(
|
filter_generation(
|
||||||
"articlesInMetaDict",
|
"articlesInMetaDict",
|
||||||
"headlineExits: true",
|
"headlineExits: true",
|
||||||
Bool(must=[Bool(must=[Exists(field="headline")])]),
|
lambda mock: mock.assert_called_with(Bool(must=[Bool(must=[Exists(field="headline")])])),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ def test_processor_lte():
|
||||||
filter_generation(
|
filter_generation(
|
||||||
"articlesInMetaDict",
|
"articlesInMetaDict",
|
||||||
'headlineLte: "A text"',
|
'headlineLte: "A text"',
|
||||||
Bool(must=Range(headline={"lte": "A text"})),
|
lambda mock: mock.assert_called_with(Bool(must=Range(headline={"lte": "A text"}))),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -88,5 +88,5 @@ def test_processor_gte():
|
||||||
filter_generation(
|
filter_generation(
|
||||||
"articlesInMetaDict",
|
"articlesInMetaDict",
|
||||||
'headlineGte: "A text"',
|
'headlineGte: "A text"',
|
||||||
Bool(must=Range(headline={"gte": "A text"})),
|
lambda mock: mock.assert_called_with(Bool(must=Range(headline={"gte": "A text"}))),
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user