예제 #1
0
    def test_get_formatted_row_values(self):
        expected = [str(i) for i in range(10)]
        row_data = RowData(values=[CellData(formattedValue=x) for x in expected])

        actual = Helpers.get_formatted_row_values(row_data)

        self.assertEqual(expected, actual)
예제 #2
0
    def test_get_first_row(self):
        spreadsheet_id = "123"
        sheet = "s1"
        expected_first_row = ["1", "2", "3", "4"]
        fake_response = Spreadsheet(
            spreadsheetId=spreadsheet_id,
            sheets=[
                Sheet(data=[
                    GridData(rowData=[
                        RowData(values=[
                            CellData(formattedValue=v)
                            for v in expected_first_row
                        ])
                    ])
                ])
            ],
        )

        client = Mock()
        client.get.return_value.execute.return_value = fake_response
        with patch.object(GoogleSheetsClient, "__init__",
                          lambda s, credentials, scopes: None):
            sheet_client = GoogleSheetsClient({"fake": "credentials"},
                                              ["auth_scopes"])
            sheet_client.client = client
        actual = Helpers.get_first_row(sheet_client, spreadsheet_id, sheet)
        self.assertEqual(expected_first_row, actual)
        client.get.assert_called_with(spreadsheetId=spreadsheet_id,
                                      includeGridData=True,
                                      ranges=f"{sheet}!1:1")
예제 #3
0
        def mock_client_call(spreadsheetId, includeGridData, ranges=None):
            if spreadsheetId != spreadsheet_id:
                return None
            # the spreadsheet only contains sheet1
            elif not includeGridData and ranges is None:
                mocked_return = Spreadsheet(
                    spreadsheetId=spreadsheet_id,
                    sheets=[Sheet(properties=SheetProperties(title=sheet1))])
            elif includeGridData and ranges == f"{sheet1}!1:1":
                mocked_return = Spreadsheet(
                    spreadsheetId=spreadsheet_id,
                    sheets=[
                        Sheet(data=[
                            GridData(rowData=[
                                RowData(values=[
                                    CellData(formattedValue=v)
                                    for v in sheet1_first_row
                                ])
                            ])
                        ])
                    ],
                )

            m = Mock()
            m.execute.return_value = mocked_return
            return m
예제 #4
0
    def test_get_first_row(self):
        spreadsheet_id = "123"
        sheet = "s1"
        expected_first_row = ["1", "2", "3", "4"]
        fake_response = Spreadsheet(
            spreadsheetId=spreadsheet_id,
            sheets=[
                Sheet(data=[
                    GridData(rowData=[
                        RowData(values=[
                            CellData(formattedValue=v)
                            for v in expected_first_row
                        ])
                    ])
                ])
            ],
        )

        client = Mock()
        client.get.return_value.execute.return_value = fake_response

        actual = Helpers.get_first_row(client, spreadsheet_id, sheet)
        self.assertEqual(expected_first_row, actual)
        client.get.assert_called_with(spreadsheetId=spreadsheet_id,
                                      includeGridData=True,
                                      ranges=f"{sheet}!1:1")