1616
1717from garf_core import api_clients, parsers, query_editor
1818
19+ test_specification = query_editor.QuerySpecification(
20+ 'SELECT test_column_1 FROM test'
21+ ).generate()
22+
1923
2024class TestDictParser:
2125 @pytest.fixture
2226 def test_parser(self):
23- return parsers.DictParser()
24-
25- @pytest.fixture
26- def test_specification(self):
27- return query_editor.QuerySpecification(
28- 'SELECT test_column_1 FROM test'
29- ).generate()
27+ return parsers.DictParser(test_specification)
3028
31- def test_parse_row_returns_correct_result(
32- self, test_parser, test_specification
33- ):
29+ def test_parse_row_returns_correct_result(self, test_parser):
3430 test_row = {'test_column_1': '1', 'test_column_2': 2}
3531
36- parsed_row = test_parser.parse_row(test_row, test_specification )
32+ parsed_row = test_parser.parse_row(test_row)
3733 expected_row = ['1']
3834
3935 assert parsed_row == expected_row
4036
41- def test_parse_results_returns_correct_result(
42- self, test_parser, test_specification
43- ):
37+ def test_parse_results_returns_correct_result(self, test_parser):
4438 test_response = api_clients.GarfApiResponse(
4539 results=[
4640 {'test_column_1': '1', 'test_column_2': 2},
4741 {'test_column_1': '11', 'test_column_2': 22},
4842 ]
4943 )
5044
51- parsed_row = test_parser.parse_response(test_response, test_specification )
45+ parsed_row = test_parser.parse_response(test_response)
5246 expected_row = [['1'], ['11']]
5347
5448 assert parsed_row == expected_row
5549
5650 def test_parse_results_returns_empty_list_on_missing_results(
57- self, test_parser, test_specification
51+ self, test_parser
5852 ):
5953 test_response = api_clients.GarfApiResponse(results=[])
6054
61- parsed_row = test_parser.parse_response(test_response, test_specification )
55+ parsed_row = test_parser.parse_response(test_response)
6256 expected_row = [[]]
6357
6458 assert parsed_row == expected_row
6559
6660 def test_parse_results_raises_garf_parse_error_on_incorrect_items_in_response(
67- self, test_parser, test_specification
61+ self, test_parser
6862 ):
6963 test_response = api_clients.GarfApiResponse(results=[[1, 2]])
7064
7165 with pytest.raises(parsers.GarfParserError):
72- test_parser.parse_response(test_response, test_specification )
66+ test_parser.parse_response(test_response)
7367
7468
7569class TestNumericDictParser:
7670 @pytest.fixture
7771 def test_parser(self):
78- return parsers.NumericConverterDictParser()
72+ return parsers.NumericConverterDictParser(test_specification )
7973
80- @pytest.fixture
81- def test_specification(self):
82- return query_editor.QuerySpecification(
83- 'SELECT test_column_1 FROM test'
84- ).generate()
85-
86- def test_parse_row_returns_converted_numeric_values(
87- self, test_parser, test_specification
88- ):
74+ def test_parse_row_returns_converted_numeric_values(self, test_parser):
8975 test_row = {'test_column_1': '1', 'test_column_2': 2}
9076
91- parsed_row = test_parser.parse_row(test_row, test_specification )
77+ parsed_row = test_parser.parse_row(test_row)
9278 expected_row = [1]
9379
9480 assert parsed_row == expected_row
@@ -97,19 +83,11 @@ def test_parse_row_returns_converted_numeric_values(
9783class TestListParser:
9884 @pytest.fixture
9985 def test_parser(self):
100- return parsers.ListParser()
86+ return parsers.ListParser(test_specification )
10187
102- @pytest.fixture
103- def test_specification(self):
104- return query_editor.QuerySpecification(
105- 'SELECT test_column_1 FROM test'
106- ).generate()
107-
108- def test_parse_row_returns_converted_numeric_values(
109- self, test_parser, test_specification
110- ):
88+ def test_parse_row_returns_converted_numeric_values(self, test_parser):
11189 test_row = {'test_column_1': '1', 'test_column_2': 2}
11290
113- parsed_row = test_parser.parse_row(test_row, test_specification )
91+ parsed_row = test_parser.parse_row(test_row)
11492
11593 assert parsed_row == test_row
0 commit comments