Esempio n. 1
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
Esempio n. 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")
Esempio n. 3
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")
Esempio n. 4
0
    def test_get_sheets_in_spreadsheet(self):
        spreadsheet_id = "id1"
        expected_sheets = ["s1", "s2"]
        client = Mock()
        client.get.return_value.execute.return_value = Spreadsheet(
            spreadsheetId=spreadsheet_id, sheets=[Sheet(properties=SheetProperties(title=t)) for t in expected_sheets]
        )
        with patch.object(GoogleSheetsClient, "__init__", lambda s, credentials, scopes: None):
            sheet_client = GoogleSheetsClient({"fake": "credentials"}, ["auth_scopes"])
            sheet_client.client = client
        actual_sheets = Helpers.get_sheets_in_spreadsheet(sheet_client, spreadsheet_id)

        self.assertEqual(expected_sheets, actual_sheets)
        client.get.assert_called_with(spreadsheetId=spreadsheet_id, includeGridData=False)
Esempio n. 5
0
    def test_get_sheets_in_spreadsheet(self):
        spreadsheet_id = "id1"
        expected_sheets = ["s1", "s2"]
        client = Mock()
        client.get.return_value.execute.return_value = Spreadsheet(
            spreadsheetId=spreadsheet_id,
            sheets=[
                Sheet(properties=SheetProperties(title=t))
                for t in expected_sheets
            ])

        actual_sheets = Helpers.get_sheets_in_spreadsheet(
            client, spreadsheet_id)

        self.assertEqual(expected_sheets, actual_sheets)
        client.get.assert_called_with(spreadsheetId=spreadsheet_id,
                                      includeGridData=False)