Skip to content

Commit

Permalink
Pass rest_method to test methods also as Enum item
Browse files Browse the repository at this point in the history
  • Loading branch information
index-git authored and jirik committed Sep 13, 2023
1 parent 0b2cfc0 commit 5b97447
Show file tree
Hide file tree
Showing 17 changed files with 28 additions and 21 deletions.
4 changes: 2 additions & 2 deletions tests/dynamic_data/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from tests.asserts.util import recursive_dict_update
from test_tools import process_client, cleanup, external_db
from .base_test_classes import WithChunksDomain, CompressDomainBase, CompressDomain, RestArgs, RestMethod, PublicationByDefinitionBase, \
LayerByUsedServers, PublicationByUsedServers, TestCaseType, Parametrization, StyleFileDomainBase # pylint: disable=unused-import
LayerByUsedServers, PublicationByUsedServers, TestCaseType, Parametrization, StyleFileDomainBase, RestMethodParam # pylint: disable=unused-import
from . import base_test_util as util
from .base_test_classes import ExternalTableDef
from .. import Publication, EnumTestTypes, EnumTestKeys, PublicationValues
Expand Down Expand Up @@ -41,7 +41,7 @@ def pytest_generate_tests(metafunc):
publ_type_name: test_case.publication,
'key': test_case.key,
'params': copy.deepcopy(test_case.params),
'rest_method': rest_method,
'rest_method': RestMethodParam(test_case.rest_method, rest_method),
'rest_args': rest_args,
'parametrization': parametrization,
'post_before_test': (test_case.publication, test_case.rest_method, test_case.post_before_test_args),
Expand Down
7 changes: 7 additions & 0 deletions tests/dynamic_data/base_test_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,10 @@ class TestCaseType:
marks: List[_pytest.mark.structures.Mark] = field(default_factory=list)
parametrization: Parametrization = None
post_before_test_args: dict = field(default_factory=dict)


@dataclass(frozen=True)
class RestMethodParam:
# pylint: disable=invalid-name
enum_item: RestMethodBase = None
fn: callable = None
2 changes: 1 addition & 1 deletion tests/dynamic_data/publications/crs/maps/maps_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def test_input_crs(self, map, key, params, rest_method):
'crs': map_crs,
'title': map.name,
}
rest_method(map, args=map_args)
rest_method.fn(map, args=map_args)

exp_publication_detail = {
'description': 'Map generated for internal layers',
Expand Down
2 changes: 1 addition & 1 deletion tests/dynamic_data/publications/implicit_name_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,6 @@ class TestLayer(base_test.TestSingleRestPublication):
@staticmethod
def test_implicit_name(publication: Publication, rest_method, rest_args):
"""Parametrized using pytest_generate_tests"""
rest_method(publication, args=rest_args)
rest_method.fn(publication, args=rest_args)

asserts_util.is_publication_valid_and_complete(publication)
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class TestLayer(base_test.TestSingleRestPublication):
def test_layer(layer, params, rest_args, rest_method, parametrization):
"""Parametrized using pytest_generate_tests"""
publ_def = parametrization.publication_definition
rest_method(layer, args=rest_args)
rest_method.fn(layer, args=rest_args)

assert_util.is_publication_valid_and_complete(layer)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def test_layer(self, layer: Publication, rest_method, rest_args, ):
db_util.run_statement(statement, conn_cur=conn_cur)

# publish layer from external DB table
rest_method(layer, args=rest_args)
rest_method.fn(layer, args=rest_args)

# general checks
assert_util.is_publication_valid_and_complete(layer)
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def test_layer(self, layer: Publication, rest_method, rest_args, params):
assert result[0][0] == params['exp_geometry_type']

# publish layer from external DB table
rest_method(layer, args=rest_args)
rest_method.fn(layer, args=rest_args)

# general checks
assert_util.is_publication_valid_and_complete(layer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_overview_resampling(layer, key, rest_method):
'overview_resampling': overview_resampling_method,
'style_file': os.path.join(DIRECTORY, 'style.sld'),
}
rest_method(layer, args=layer_args)
rest_method.fn(layer, args=layer_args)

assert_util.is_publication_valid_and_complete(layer)
exp_thumbnail = os.path.join(DIRECTORY, f"thumbnail_{overview_resampling_method}.png")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def test_contrast(layer: Publication, params, rest_method, rest_args):
rel_file_path = os.path.relpath(abs_file_path, DIRECTORY)
assert_input_file(abs_file_path, expected_input.get(rel_file_path, expected_input))

rest_method(layer, args=rest_args)
rest_method.fn(layer, args=rest_args)

assert_util.is_publication_valid_and_complete(layer)
base_file_name = '_'.join(layer.name.split('_')[1:])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ class TestLayer(base_test.TestSingleRestPublication):
@staticmethod
def test_qml_style(layer: Publication, rest_args, rest_method):
"""Parametrized using pytest_generate_tests"""
rest_method(layer, args=rest_args)
rest_method.fn(layer, args=rest_args)

assert_util.is_publication_valid_and_complete(layer)
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class TestLayer(base_test.TestSingleRestPublication):
@staticmethod
def test_style_xml(layer: Publication, params, rest_method):
"""Parametrized using pytest_generate_tests"""
rest_method(layer, args={
rest_method.fn(layer, args={
'file_paths': ['sample/layman.layer/small_layer.geojson'],
'style_file': params.get('style_file'),
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ class TestLayer(base_test.TestSingleRestPublication):
@pytest.mark.timeout(60)
def test_timeseries_layer(self, layer: Publication, params, rest_method, rest_args):
"""Parametrized using pytest_generate_tests"""
rest_method(layer, args=rest_args)
rest_method.fn(layer, args=rest_args)

asserts_util.is_publication_valid_and_complete(layer)

Expand All @@ -362,9 +362,9 @@ def test_timeseries_layer(self, layer: Publication, params, rest_method, rest_ar
exp_thumbnail = os.path.join(DIRECTORY, exp_thumbnail_file)
asserts_publ.internal.thumbnail_equals(layer.workspace, layer.type, layer.name, exp_thumbnail, max_diffs=1)

if rest_method == self.post_publication: # pylint: disable=W0143
if rest_method.enum_item == base_test.RestMethod.POST:
http_method = common.REQUEST_METHOD_POST
elif rest_method == self.patch_publication: # pylint: disable=W0143
elif rest_method.enum_item == base_test.RestMethod.PATCH:
http_method = common.REQUEST_METHOD_PATCH
else:
raise NotImplementedError(f"Unknown rest_method: {rest_method}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ def test_publication(self, map, rest_method, rest_args, params):
(map, exp['operates_on'] or []),
])

rest_method(map, args=rest_args)
if rest_method in [self.post_publication, self.patch_publication]:
rest_method.fn(map, args=rest_args)
if rest_method.enum_item in [base_test_classes.RestMethodAll.POST, base_test_classes.RestMethodAll.PATCH]:
assert_util.is_publication_valid_and_complete(map)

exp = params['exp_after_rest_method']
Expand Down
2 changes: 1 addition & 1 deletion tests/dynamic_data/publications/publication_name_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def function_cleanup(self, request):
def test_publication_name(publication, rest_method, rest_args, parametrization):
"""Parametrized using pytest_generate_tests"""
publ_def = parametrization.publication_definition
rest_method(publication, args=rest_args)
rest_method.fn(publication, args=rest_args)
assert_util.is_publication_valid_and_complete(publication)
publ_asserts.internal.correct_values_in_detail(publication.workspace, publication.type, publication.name,
**publ_def.info_values)
Expand Down
2 changes: 1 addition & 1 deletion tests/dynamic_data/publications/updating_layer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class TestUpdatingLayer(base_test.TestSingleRestPublication):
@staticmethod
def test_layer(layer, params, rest_method):
"""Parametrized using pytest_generate_tests"""
rest_method(layer, args=params)
rest_method.fn(layer, args=params)

exp_publication_detail = {
'geodata_type': 'unknown',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1376,10 +1376,10 @@ def test_publication(self, publication: Publication, rest_method, rest_args, par
format_exception(exp_exception, publication, parametrization)
exception = pytest.raises(params[Key.EXCEPTION]) if is_sync else does_not_raise()
with exception as exception_info:
response = rest_method(publication, args=rest_args)
response = rest_method.fn(publication, args=rest_args)
if is_sync:
processing.exception.response_exception(expected=exp_exception, thrown=exception_info)
if rest_method == self.patch_publication: # pylint: disable=W0143
if rest_method.enum_item == base_test.RestMethod.PATCH:
assert_utils.is_publication_valid_and_complete(publication)
else:
processing.response.valid_post(workspace=publication.workspace,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class TestPublication(base_test.TestSingleRestPublication):

def test_publication(self, publication, rest_method):
proxy_prefix = '/layman-proxy'
response = rest_method(publication, args={'headers': {'X-Forwarded-Prefix': proxy_prefix}})
response = rest_method.fn(publication, args={'headers': {'X-Forwarded-Prefix': proxy_prefix}})
publication_response = response[0] if isinstance(response, list) and len(response) == 1 else response
if rest_method == self.patch_publication: # pylint: disable=W0143
if publication.type == process_client.LAYER_TYPE:
Expand Down

0 comments on commit 5b97447

Please sign in to comment.