Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def apply_values_from_url_params(logger, request_options: RequestOptionsType, ur
DatasourcesAndWorkbooks.apply_encoded_filter_value(logger, request_options, value)

except Exception as e:
logger.warn("Error building filter params", e)
logger.warning("Error building filter params: %s", e)
# ExportCommand.log_stack(logger) # type: ignore

# this is called from within from_url_params, for each view_filter value
Expand Down Expand Up @@ -114,7 +114,7 @@ def apply_options_in_url(logger, request_options: RequestOptionsType, value: str
logger.debug("handling url option {}".format(value))
setting = value.split("=")
if len(setting) != 2:
logger.warn("Unable to read url parameter '{}', skipping".format(value))
logger.warning("Unable to read url parameter '{}', skipping".format(value))
return
setting_name = setting[0]
setting_val = setting[1]
Expand All @@ -129,12 +129,12 @@ def apply_options_in_url(logger, request_options: RequestOptionsType, value: str
elif ":size" == setting_name:
if isinstance(request_options, (TSC.ImageRequestOptions, TSC.PDFRequestOptions)):
try:
height, width = setting_val.split(",")
request_options.viz_height = int(height)
request_options.viz_width = int(width)
width, height = setting_val.split(",")
w_int, h_int = int(width), int(height)
request_options.viz_width = w_int
request_options.viz_height = h_int
except Exception as oops:
logger.warn("Unable to read image size options '{}', skipping".format(setting_val))
logger.warn(oops)
logger.warning("Unable to read image size options: %s", oops)
else:
logger.debug(
"Request options are not of type ImageRequestOptions or PDFRequestOptions, skipping size setting"
Expand Down
24 changes: 20 additions & 4 deletions tests/commands/test_datasources_and_workbooks_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,15 @@ def test_apply_pdf_options_with_language(self):

def test_apply_options_in_url_with_size(self):
request_options = tsc.ImageRequestOptions()
value = ":size=800,600"
DatasourcesAndWorkbooks.apply_options_in_url(mock_logger, request_options, ":size=1920,1080")
self.assertEqual(request_options.viz_width, 1920)
self.assertEqual(request_options.viz_height, 1080)

DatasourcesAndWorkbooks.apply_options_in_url(mock_logger, request_options, value)
self.assertEqual(request_options.viz_height, 800)
self.assertEqual(request_options.viz_width, 600)
def test_apply_options_in_url_with_size_via_url_params(self):
request_options = tsc.ImageRequestOptions()
DatasourcesAndWorkbooks.apply_values_from_url_params(mock_logger, request_options, "?:size=1920,1080")
self.assertEqual(request_options.viz_width, 1920)
self.assertEqual(request_options.viz_height, 1080)

def test_apply_options_in_url_with_refresh(self):
request_options = tsc.ImageRequestOptions()
Expand All @@ -151,6 +155,18 @@ def test_apply_options_in_url_with_invalid_size(self):
self.assertEqual(request_options.viz_height, None)
self.assertEqual(request_options.viz_width, None)

def test_apply_options_in_url_invalid_first_dimension_leaves_both_unset(self):
request_options = tsc.ImageRequestOptions()
DatasourcesAndWorkbooks.apply_options_in_url(mock_logger, request_options, ":size=notanumber,600")
self.assertIsNone(request_options.viz_width)
self.assertIsNone(request_options.viz_height)

def test_apply_options_in_url_invalid_second_dimension_leaves_both_unset(self):
request_options = tsc.ImageRequestOptions()
DatasourcesAndWorkbooks.apply_options_in_url(mock_logger, request_options, ":size=1920,notanumber")
self.assertIsNone(request_options.viz_width)
self.assertIsNone(request_options.viz_height)

def test_apply_options_in_url_with_unrecognized_parameter(self):
request_options = tsc.ImageRequestOptions()
default_max_age = request_options.max_age
Expand Down
Loading