WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 8848740

Browse files
authored
Promote code for 2.0.17 (#341)
A fast following update with a packaging fix fix ubuntu and max-x64 executables are missing a dependency #337 fix get: implement size parameters (--width and --height) #94 fix Filtering does not work for a full workbook (--fullpdf) #233
2 parents dd10d39 + fb8f640 commit 8848740

File tree

5 files changed

+71
-40
lines changed

5 files changed

+71
-40
lines changed

tabcmd/commands/datasources_and_workbooks/datasources_and_workbooks_command.py

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def get_ds_by_content_url(logger, server, datasource_content_url) -> TSC.Datasou
6262
return matching_datasources[0]
6363

6464
@staticmethod
65-
def apply_values_from_url_params(logger, request_options: TSC.PDFRequestOptions, url) -> None:
65+
def apply_values_from_url_params(logger, request_options: TSC.RequestOptions, url) -> None:
6666
logger.debug(url)
6767
try:
6868
if "?" in url:
@@ -99,25 +99,40 @@ def apply_encoded_filter_value(logger, request_options, value):
9999
# from apply_options, which expects an un-encoded input,
100100
# or from apply_url_params via apply_encoded_filter_value which decodes the input
101101
@staticmethod
102-
def apply_filter_value(logger, request_options: TSC.PDFRequestOptions, value: str) -> None:
102+
def apply_filter_value(logger, request_options: TSC.RequestOptions, value: str) -> None:
103103
logger.debug("handling filter param {}".format(value))
104104
data_filter = value.split("=")
105-
request_options.vf(data_filter[0], data_filter[1])
105+
# we should export the _DataExportOptions class from tsc
106+
request_options.vf(data_filter[0], data_filter[1]) # type: ignore
106107

107108
# this is called from within from_url_params, for each param value
109+
# expects either ImageRequestOptions or PDFRequestOptions
108110
@staticmethod
109-
def apply_options_in_url(logger, request_options: TSC.PDFRequestOptions, value: str) -> None:
111+
def apply_options_in_url(logger, request_options: TSC.RequestOptions, value: str) -> None:
110112
logger.debug("handling url option {}".format(value))
111113
setting = value.split("=")
112-
if ":iid" == setting[0]:
114+
if len(setting) != 2:
115+
logger.warn("Unable to read url parameter '{}', skipping".format(value))
116+
return
117+
setting_name = setting[0]
118+
setting_val = setting[1]
119+
logger.debug("setting named {}, has value {}".format(setting_name, setting_val))
120+
121+
if ":iid" == setting_name:
113122
logger.debug(":iid value ignored in url")
114-
elif ":refresh" == setting[0] and DatasourcesAndWorkbooks.is_truthy(setting[1]):
123+
elif ":refresh" == setting_name and DatasourcesAndWorkbooks.is_truthy(setting_val):
115124
# mypy is worried that this is readonly
116-
request_options.max_age = 0 # type:ignore
117-
logger.debug("Set max age to {} from {}".format(request_options.max_age, value))
118-
elif ":size" == setting[0]:
119-
height, width = setting[1].split(",")
120-
logger.warn("Height/width parameters not yet implemented ({})".format(value))
125+
request_options.max_age = 0 # type: ignore
126+
logger.debug("Set max age to {} from {}".format((TSC.ImageRequestOptions(request_options)).max_age, value))
127+
elif ":size" == setting_name:
128+
# this is only used by get as png
129+
try:
130+
height, width = setting_val.split(",")
131+
(TSC.ImageRequestOptions(request_options)).viz_height = int(height)
132+
(TSC.ImageRequestOptions(request_options)).viz_width = int(width)
133+
except Exception as oops:
134+
logger.warn("Unable to read image size options '{}', skipping".format(setting_val))
135+
logger.warn(oops)
121136
else:
122137
logger.debug("Parameter[s] not recognized: {}".format(value))
123138

@@ -127,8 +142,11 @@ def is_truthy(value: str):
127142

128143
@staticmethod
129144
def apply_png_options(logger, request_options: TSC.ImageRequestOptions, args):
130-
if args.height or args.width:
131-
logger.warn("Height/width arguments not yet implemented in export")
145+
# these are only used in export, not get
146+
if args.height:
147+
request_options.viz_height = int(args.height)
148+
if args.width:
149+
request_options.viz_width = int(args.width)
132150
# Always request high-res images
133151
request_options.image_resolution = "high"
134152

tabcmd/commands/datasources_and_workbooks/export_command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def run_command(args):
133133
Errors.exit_with_error(logger, "Error saving to file", e)
134134

135135
@staticmethod
136-
def apply_filters_from_args(request_options: TSC.PDFRequestOptions, args, logger=None) -> None:
136+
def apply_filters_from_args(request_options: TSC.RequestOptions, args, logger=None) -> None:
137137
if args.filter:
138138
logger.debug("filter = {}".format(args.filter))
139139
params = args.filter.split("&")

tabcmd/commands/datasources_and_workbooks/get_url_command.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ def generate_png(logger, server_content_type, args, get_url_item):
115115
logger.trace("Entered method " + inspect.stack()[0].function)
116116
try:
117117
logger.debug(_("content_type.view") + ": {}".format(get_url_item.name))
118-
req_option_csv = TSC.ImageRequestOptions(maxage=1)
119-
DatasourcesAndWorkbooks.apply_values_from_url_params(logger, req_option_csv, args.url)
120-
server_content_type.populate_image(get_url_item, req_option_csv)
118+
req_option_png = TSC.ImageRequestOptions(maxage=1)
119+
DatasourcesAndWorkbooks.apply_values_from_url_params(logger, req_option_png, args.url)
120+
server_content_type.populate_image(get_url_item, req_option_png)
121121
filename = GetUrl.filename_from_args(args.filename, get_url_item.name, "png")
122122
DatasourcesAndWorkbooks.save_to_file(logger, get_url_item.image, filename)
123123
except Exception as e:

tests/commands/test_datasources_and_workbooks_command.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,20 @@ def test_apply_options_from_url_params(self):
4747
assert request_options.max_age == 0
4848

4949
def test_apply_png_options(self):
50-
# these aren't implemented yet. the layout and orientation ones don't apply.
51-
mock_args.width = 800
52-
mock_args.height = 76
50+
mock_args.width = "800"
51+
mock_args.height = "76"
5352
request_options = tsc.ImageRequestOptions()
5453
DatasourcesAndWorkbooks.apply_png_options(mock_logger, request_options, mock_args)
5554
assert request_options.image_resolution == "high"
55+
assert request_options.viz_width == 800
56+
assert request_options.viz_height == 76
57+
58+
def test_apply_png_options_bad_values(self):
59+
mock_args.height = "seven"
60+
mock_args.width = "800b"
61+
request_options = tsc.ImageRequestOptions()
62+
with self.assertRaises(ValueError):
63+
DatasourcesAndWorkbooks.apply_png_options(mock_logger, request_options, mock_args)
5664

5765
def test_apply_pdf_options(self):
5866
expected_page = tsc.PDFRequestOptions.PageType.Folio.__str__()

tests/e2e/online_tests.py

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
unique = str(time.gmtime().tm_sec)
2929
group_name = "test-ing-group" + unique
3030
workbook_name = "wb_1_" + unique
31-
default_project_name = "Personal Work" # "default-proj" + unique
31+
default_project_name = "Personal Work" # "default-proj" + unique
3232
parent_location = "parent" + unique
3333
project_name = "test-proj-" + unique
3434

@@ -43,7 +43,7 @@
4343
def _test_command(test_args: list[str]):
4444
# this will raise an exception if it gets a non-zero return code
4545
# that will bubble up and fail the test
46-
46+
4747
# default: run tests using tabcmd 2
4848
calling_args = ["python", "-m", "tabcmd"] + test_args + [debug_log] + ["--no-certcheck"]
4949

@@ -120,7 +120,7 @@ def _publish_creds_args(
120120

121121
def _delete_wb(self, name):
122122
command = "delete"
123-
arguments = [command, "--project", default_project_name, name]
123+
arguments = [command, "--project", default_project_name, name]
124124
_test_command(arguments)
125125

126126
def _delete_ds(self, name):
@@ -142,20 +142,17 @@ def _get_custom_view(self):
142142
# TODO
143143
command = "get"
144144

145-
146-
147145
def _export_wb(self, friendly_name, filename=None, additional_args=None):
148146
command = "export"
149147
arguments = [command, friendly_name, "--fullpdf"]
150-
148+
151149
if filename:
152150
arguments = arguments + ["--filename", filename]
153151
if additional_args:
154152
arguments = arguments + additional_args
155153
_test_command(arguments)
156154

157-
158-
def _export_view(self, wb_name_on_server, sheet_name, export_type, filename=None, additional_args=None):
155+
def _export_view(self, wb_name_on_server, sheet_name, export_type, filename=None, additional_args=None):
159156
server_file = "/" + wb_name_on_server + "/" + sheet_name
160157
command = "export"
161158
arguments = [command, server_file, export_type]
@@ -180,15 +177,15 @@ def _get_datasource(self, server_file):
180177

181178
def _create_extract(self, type, wb_name):
182179
command = "createextracts"
183-
arguments = [command, type, wb_name, "--project", default_project_name]
180+
arguments = [command, type, wb_name, "--project", default_project_name]
184181
if extract_encryption_enabled and not use_tabcmd_classic:
185182
arguments.append("--encrypt")
186183
_test_command(arguments)
187184

188185
# variation: url
189186
def _refresh_extract(self, type, wb_name):
190187
command = "refreshextracts"
191-
arguments = [command, "-w", wb_name, "--project", default_project_name] # bug: should not need -w
188+
arguments = [command, "-w", wb_name, "--project", default_project_name] # bug: should not need -w
192189
try:
193190
_test_command(arguments)
194191
except Exception as e:
@@ -202,7 +199,7 @@ def _refresh_extract(self, type, wb_name):
202199

203200
def _delete_extract(self, type, item_name):
204201
command = "deleteextracts"
205-
arguments = [command, type, item_name, "--include-all", "--project", default_project_name]
202+
arguments = [command, type, item_name, "--include-all", "--project", default_project_name]
206203
try:
207204
_test_command(arguments)
208205
except Exception as e:
@@ -379,6 +376,17 @@ def test_view_get_pdf(self):
379376
# bug in tabcmd classic: doesn't work without download name
380377
self._get_view(wb_name_on_server, sheet_name, "downloaded_file.pdf")
381378

379+
@pytest.mark.order(11)
380+
def test_view_get_png_sizes(self):
381+
wb_name_on_server = OnlineCommandTest.TWBX_WITH_EXTRACT_NAME
382+
sheet_name = OnlineCommandTest.TWBX_WITH_EXTRACT_SHEET
383+
384+
self._get_view(wb_name_on_server, sheet_name, "get_view_default_size.png")
385+
url_params = "?:size=100,200"
386+
self._get_view(wb_name_on_server, sheet_name + url_params, "get_view_sized_sm.png")
387+
url_params = "?:size=500,700"
388+
self._get_view(wb_name_on_server, sheet_name + url_params, "get_view_sized_LARGE.png")
389+
382390
@pytest.mark.order(11)
383391
def test_view_get_csv(self):
384392
wb_name_on_server = OnlineCommandTest.TWBX_WITH_EXTRACT_NAME
@@ -451,21 +459,18 @@ def test__delete_ds_live(self):
451459
def test_export_wb_filters(self):
452460
wb_name_on_server = OnlineCommandTest.TWBX_WITH_EXTRACT_NAME
453461
sheet_name = OnlineCommandTest.TWBX_WITH_EXTRACT_SHEET
454-
friendly_name = wb_name_on_server +"/" + sheet_name
455-
filters = ["--filter", "Product Type=Tea", "--fullpdf", "--pagelayout", "landscape"]
462+
friendly_name = wb_name_on_server + "/" + sheet_name
463+
filters = ["--filter", "Product Type=Tea", "--fullpdf", "--pagelayout", "landscape"]
456464
self._export_wb(friendly_name, "filter_a_wb_to_tea_and_two_pages.pdf", filters)
457465
# NOTE: this test needs a visual check on the returned pdf to confirm the expected appearance
458466

459467
@pytest.mark.order(19)
460468
def test_export_wb_pdf(self):
461-
command = "export"
462469
wb_name_on_server = OnlineCommandTest.TWBX_WITH_EXTRACT_NAME
463-
friendly_name = (
464-
wb_name_on_server + "/" + OnlineCommandTest.TWBX_WITH_EXTRACT_SHEET
465-
)
470+
friendly_name = wb_name_on_server + "/" + OnlineCommandTest.TWBX_WITH_EXTRACT_SHEET
466471
filename = "exported_wb.pdf"
467472
self._export_wb(friendly_name, filename)
468-
473+
469474
@pytest.mark.order(19)
470475
def test_export_data_csv(self):
471476
wb_name_on_server = OnlineCommandTest.TWBX_WITH_EXTRACT_NAME
@@ -483,13 +488,13 @@ def test_export_view_pdf(self):
483488
wb_name_on_server = OnlineCommandTest.TWBX_WITH_EXTRACT_NAME
484489
sheet_name = OnlineCommandTest.TWBX_WITH_EXTRACT_SHEET
485490
self._export_view(wb_name_on_server, sheet_name, "--pdf", "export_view_pdf.pdf")
486-
491+
487492
@pytest.mark.order(19)
488493
def test_export_view_filtered(self):
489494
wb_name_on_server = OnlineCommandTest.TWBX_WITH_EXTRACT_NAME
490495
sheet_name = OnlineCommandTest.TWBX_WITH_EXTRACT_SHEET
491496
filename = "view_with_filters.pdf"
492-
497+
493498
filters = ["--filter", "Product Type=Tea"]
494499
self._export_view(wb_name_on_server, sheet_name, "--pdf", filename, filters)
495500

0 commit comments

Comments
 (0)