resolving issues with test

This commit is contained in:
Alejandro Nunez Capote 2019-06-10 13:11:42 -04:00
parent 054ebaa57d
commit 4b0ca35e2c
4 changed files with 33 additions and 29 deletions

View File

@ -3,7 +3,7 @@ class FieldResolverObservable(object):
def __init__(self):
"""A new Observable by filterset"""
super(FieldResolverObservable).__init__()
super(FieldResolverObservable, self).__init__()
self._fields = {}
def attach(self, field, processor):

View File

@ -45,7 +45,7 @@ def generate_query(field, query_str):
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()
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
mock_query.assert_called_with(expected_arguments)
verify_arguments(mock_query)
assert len(result.data[field]["edges"]) == 2
assert result.data[field]["edges"][0]["node"]["headline"] == "a1"

View File

@ -28,7 +28,7 @@ def test_filter_string():
filter_generation(
"articlesAsField",
'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(
"articlesAsField",
'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(
"articlesAsField",
'headline: "A text", sort:{order:desc, field:id}',
{"id": {"order": "desc"}},
lambda mock: mock.assert_called_with({"id": {"order": "desc"}}),
"sort",
)
@ -53,7 +53,7 @@ def test_filter_as_field_order_by_dict():
filter_generation(
"articlesInMeta",
'headline: "A text", sort:{order:desc, field:id}',
{"es_id": {"order": "desc"}},
lambda mock: mock.assert_called_with({"es_id": {"order": "desc"}}),
"sort",
)
@ -62,7 +62,7 @@ def test_filter_in_meta():
filter_generation(
"articlesInMeta",
'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(
"articlesInMetaDict",
'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(
"articlesInMetaDict",
'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(
"articlesInMultiField",
'contain: "A text"',
Bool(
lambda mock: mock.assert_called_with(Bool(
must=[
Bool(
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():
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(
"articlesInGenerateAll",
'headline: "A text", '
@ -107,15 +119,7 @@ def test_filter_generating_all():
'pubDateTime: "00:00:00", '
'lang: "es", '
"importance: 1, ",
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),
]
),
lambda mock: compare_must_array(mock.call_args[0][0].must, spected_query.must),
)

View File

@ -32,7 +32,7 @@ def test_processor_term():
filter_generation(
"articlesInMetaDict",
'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(
"articlesInMetaDict",
'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(
"articlesInMetaDict",
'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(
"articlesInMetaDict",
'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(
"articlesInMetaDict",
'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(
"articlesInMetaDict",
"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(
"articlesInMetaDict",
'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(
"articlesInMetaDict",
'headlineGte: "A text"',
Bool(must=Range(headline={"gte": "A text"})),
lambda mock: mock.assert_called_with(Bool(must=Range(headline={"gte": "A text"}))),
)