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 72cd48c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pyramid_oereb/contrib/print_proxy/mapfish_print.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ 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={}):
"""
Returns the list of additionally configured wms_url_params.
Expand All @@ -192,7 +192,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 Expand Up @@ -295,7 +295,7 @@ def convert_to_printable_extract(self, extract_dict, feature_geometry, pdf_to_jo
'baseURL': urlparse.urlunsplit((url.scheme, url.netloc, url.path, None, None)),
'layers': params.pop('LAYERS', '')[0].split(','),
'imageFormat': params.pop('FORMAT', 'image/png')[0],
'customParams': self.get_wms_url_params(params if wms_url_params_from_DB else None),
'customParams': self.get_wms_url_params(params if wms_url_params_from_DB else {}),
}, basemap]
}

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 {})
# 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 72cd48c

Please sign in to comment.