Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marionb committed Jan 9, 2020
1 parent 7cea1df commit c4cccf1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pyramid_oereb/contrib/print_proxy/mapfish_print.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,16 @@ def archive_pdf_file(pdf_archive_path, binary_content, extract_as_dict):
return path_and_filename

@staticmethod
def get_wms_url_params(params = None):
def get_wms_url_params(params=None):
"""
Returns the list of additionally configured wms_url_params.
Args:
params: optional argument used for given custom parameters. Expecting a dict
:return: The configured wms_url_params.
:rtype: dict
"""
result = params
result = params if params else {}
if not params:
wms_url_params = Config.get('print', {}).get('wms_url_params', False)
if wms_url_params:
Expand All @@ -192,7 +194,7 @@ def get_wms_url_params(params = None):
result = {'TRANSPARENT': 'true'}

else:
for param_key, param_value in params.items(): # TODO make this Python 2.x compatible!
for param_key, param_value in params.items(): # TODO make this Python 2.x compatible!
if isinstance(param_value, str):
result[param_key] = param_value
else:
Expand Down
4 changes: 4 additions & 0 deletions tests/contrib/print_proxy/resources/test_custom_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pyramid_oereb:

print:
wms_url_params_from_DB: true
22 changes: 22 additions & 0 deletions tests/contrib/print_proxy/test_mapfish_print_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,28 @@ def test_bad_config_wms_url_params():
assert config == {}


def test_custom_config_wms_url_params():
Config._config = None
Config.init('./tests/contrib/print_proxy/resources/test_custom_config.yml', 'pyramid_oereb')
renderer = Renderer(DummyRenderInfo())
wms_url_params_from_DB = Config.get('print', {}).get('wms_url_params_from_DB', False)
params = {
'TRANSPARENT': ['true'],
'OTHERCUSTOM': ['myvalue'],
'epoch': ['2018-11-29T15:13:31']
}
config = renderer.get_wms_url_params(params if wms_url_params_from_DB else None)
# Restore normal config
Config._config = None
Config.init('./pyramid_oereb/standard/pyramid_oereb.yml', 'pyramid_oereb')
# Do the check for this test. Value should match the one from the YAML configuration.
assert config == {
'TRANSPARENT': 'true',
'OTHERCUSTOM': 'myvalue',
'epoch': '2018-11-29T15:13:31'
}


def test_default_wms_url_param_config():
renderer = Renderer(DummyRenderInfo())
config = renderer.get_wms_url_params()
Expand Down

0 comments on commit c4cccf1

Please sign in to comment.