示例#1
0
def test_TableauScraper_promptSelect(mocker: MockerFixture) -> None:
    mocker.patch("tableauscraper.api.getTableauViz",
                 return_value=tableauVizHtmlResponse)
    mocker.patch("tableauscraper.api.getTableauData",
                 return_value=tableauDataResponse)
    mocker.patch("tableauscraper.api.select", return_value=vqlCmdResponse)
    ts = TS()
    ts.loads(fakeUri)
    mocker.patch("builtins.input", side_effect=["0", "0", "0", ""])
    tableauDataFrameGroup = ts.promptSelect()
    assert type(tableauDataFrameGroup) is TableauDashboard
    assert len(tableauDataFrameGroup.worksheets) == 1
    assert tableauDataFrameGroup.worksheets[0].name == "[WORKSHEET1]"
    assert tableauDataFrameGroup.worksheets[0].data.shape[0] == 4
    assert tableauDataFrameGroup.worksheets[0].data.shape[1] == 2
    assert list(tableauDataFrameGroup.worksheets[0].data.columns.values) == [
        "[FIELD1]-value",
        "[FIELD2]-alias",
    ]
示例#2
0
ts = TS()
ts.loads(args.url)

# checkout the json data
# with open('data.json', 'w', encoding='utf-8') as f:
#    json.dump(ts.data, f, ensure_ascii=False, indent=4)
# with open('info.json', 'w', encoding='utf-8') as f:
#    json.dump(ts.info, f, ensure_ascii=False, indent=4)

if args.get == "workbook":
    workbook = ts.promptDashboard()
elif args.get == "parameter":
    workbook = ts.promptParameters()
elif args.get == "select":
    workbook = ts.promptSelect()

with pd.option_context(
    "display.max_rows", None, "display.max_columns", 5, "display.width", 1000
):
    for idx, worksheet in enumerate(workbook.worksheets):
        if idx == 0:
            print("|" + ("-" * (os.get_terminal_size().columns - 2)) + "|")
        print("|" + worksheet.name.center(os.get_terminal_size().columns - 2) + "|")
        print("|" + ("-" * (os.get_terminal_size().columns - 2)) + "|")
        print(worksheet.data)
        print("")
        print("selectable values")
        # selectable values
        selection = worksheet.getSelectableItems()
        print(
示例#3
0
ts = TS()
ts.loads(args.url)

# checkout the json data
# with open('data.json', 'w', encoding='utf-8') as f:
#    json.dump(ts.data, f, ensure_ascii=False, indent=4)
# with open('info.json', 'w', encoding='utf-8') as f:
#    json.dump(ts.info, f, ensure_ascii=False, indent=4)

if args.get == "dashboard":
    dashboard = ts.promptDashboard()
elif args.get == "dropdown":
    dashboard = ts.promptDropdown()
elif args.get == "select":
    dashboard = ts.promptSelect()

with pd.option_context(
    "display.max_rows", None, "display.max_columns", 5, "display.width", 1000
):
    for idx, worksheet in enumerate(dashboard.worksheets):
        if idx == 0:
            print("|" + ("-" * (os.get_terminal_size().columns - 2)) + "|")
        print("|" + worksheet.name.center(os.get_terminal_size().columns - 2) + "|")
        print("|" + ("-" * (os.get_terminal_size().columns - 2)) + "|")
        print(worksheet.data)
        print("")
        # selectable values
        selectableColumns = worksheet.getSelectableColumns()
        print(f"selectable columns for this worksheet : {len(selectableColumns)}")
        for columnName in selectableColumns: