def test_getWorksheet():
    ts = TS()
    tableauDataFrame = dashboard.getWorksheet(ts, data, info, "[WORKSHEET1]")
    assert tableauDataFrame.name == "[WORKSHEET1]"
    assert tableauDataFrame.data.shape[0] == 4
    assert tableauDataFrame.data.shape[1] == 2
    assert type(tableauDataFrame) is TableauWorksheet
示例#2
0
def test_getWorksheet():
    ts = TS()
    tableauDataFrame = dashboard.getWorksheet(ts, data, info, "[WORKSHEET1]")
    assert tableauDataFrame.name == "[WORKSHEET1]"
    assert tableauDataFrame.data.shape[0] == 4
    assert tableauDataFrame.data.shape[1] == 2
    assert type(tableauDataFrame) is TableauWorksheet

    # story point
    tableauDataFrame = dashboard.getWorksheet(
        ts, dataWithoutPresModelWithDictionary, storyPointsInfo,
        "[WORKSHEET1]")
    assert tableauDataFrame.name == "[WORKSHEET1]"
    assert tableauDataFrame.data.shape[0] == 4
    assert tableauDataFrame.data.shape[1] == 2
    assert type(tableauDataFrame) is TableauWorksheet
def test_TableauWorksheet(mocker: MockerFixture) -> None:
    ts = TS()
    tableauDataFrame = dashboard.getWorksheet(ts, data, info, "[WORKSHEET1]")
    assert tableauDataFrame.name == "[WORKSHEET1]"
    assert tableauDataFrame.data.shape[0] == 4
    assert tableauDataFrame.data.shape[1] == 2
    assert type(tableauDataFrame) is TableauWorksheet

    columns = tableauDataFrame.getColumns()
    assert type(columns) is list
    assert columns == ["[FIELD1]", "[FIELD2]"]

    selectableColumns = tableauDataFrame.getSelectableColumns()
    assert type(selectableColumns) is list
    assert selectableColumns == ["[FIELD1]"]

    values = tableauDataFrame.getValues("[FIELD1]")
    assert type(values) is list
    assert values == ["2", "3", "4", "5"]

    # column name doesn't exist
    values = tableauDataFrame.getValues("XXX")
    assert type(values) is list
    assert values == []

    # no values
    tableauDataFrame = dashboard.getWorksheet(ts, emptyValues, info,
                                              "[WORKSHEET1]")
    values = tableauDataFrame.getValues("[FIELD1]")
    assert type(values) is list
    assert values == []

    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.loads(fakeUri)
    tableauDataFrame = dashboard.getWorksheet(ts, data, info, "[WORKSHEET1]")
    tableauDataFrameGroup = tableauDataFrame.select("[FIELD1]", "2")
    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",
    ]

    # column name doesn't exist
    tableauDataFrameGroup = tableauDataFrame.select("XXXX", "2")
    assert type(tableauDataFrameGroup) is TableauDashboard
    assert len(tableauDataFrameGroup.worksheets) == 0

    #### VQL CMD RESPONSE ####
    tableauDataFrame = dashboard.getWorksheet(ts, data, info, "[WORKSHEET1]")
    tableauDataFrame = tableauDataFrame.select(
        "[FIELD1]", "2").getWorksheet("[WORKSHEET1]")
    assert type(tableauDataFrame) is TableauWorksheet
    assert tableauDataFrame.cmdResponse

    columns = tableauDataFrame.getColumns()
    assert type(columns) is list
    assert columns == ["[FIELD1]", "[FIELD2]"]

    selectableColumns = tableauDataFrame.getSelectableColumns()
    assert type(selectableColumns) is list
    assert selectableColumns == ["[FIELD1]"]

    values = tableauDataFrame.getValues("[FIELD1]")
    assert type(values) is list
    assert values == ["2", "3", "4", "5"]

    # column name doesn't exist
    values = tableauDataFrame.getValues("XXX")
    assert type(values) is list
    assert values == []

    # no values

    mocker.patch("tableauscraper.api.select",
                 return_value=vqlCmdResponseDictionaryEmpty)
    tableauDataFrame = dashboard.getWorksheet(ts, data, info, "[WORKSHEET1]")
    tableauDataFrame = tableauDataFrame.select(
        "[FIELD1]", "2").getWorksheet("[WORKSHEET1]")
    values = tableauDataFrame.getValues("[FIELD1]")
    assert type(values) is list
    assert values == []
示例#4
0
 def getWorksheet(self, worksheetName) -> TableauWorksheet:
     return dashboard.getWorksheet(self, self.data, self.info,
                                   worksheetName)