adding another negative test
@@ -127,6 +127,37 @@ class GsheetTest(unittest.TestCase):
sheets_service_mock.assert_has_calls(calls, any_order=True)
+ def test_write_to_google_sheet_missing_permissions_raises_http_error(
+ self):
+ get_response = {
+ 'range': '{}{}'.format(WORKSHEET_NAME, NUM_ENTRIES_CELL),
+ 'majorDimension': 'ROWS'
+ }
+ sheets_service_mock = mock.MagicMock()
+ sheets_service_mock.spreadsheets().values().get(
+ ).execute.return_value = get_response
+ sheets_service_mock.spreadsheets().values().get(
+ ).execute.side_effect = HttpError(
+ mock.Mock(
+ status=403,
+ message='The caller does not have permission'),
+ b'http content')
+ metrics_to_be_added = [('2_thread', 50000, 40, 1653027155, 1653027215, 1, 2,
+ 3, 4, 5)]
+ calls = [
+ mock.call.spreadsheets().values().get(
+ spreadsheetId=SPREADSHEET_ID,
+ range='{}{}'.format(WORKSHEET_NAME, NUM_ENTRIES_CELL))
+ ]
+
+ with mock.patch.object(gsheet, '_get_sheets_service_client'
+ ) as get_sheets_service_client_mock:
+ get_sheets_service_client_mock.return_value = sheets_service_mock
+ with self.assertRaises(HttpError):
+ gsheet.write_to_google_sheet(WORKSHEET_NAME, metrics_to_be_added)
+
+ sheets_service_mock.assert_has_calls(calls, any_order=True)
+
if __name__ == '__main__':
unittest.main()
