def test_fetch_data_gsheet_success(self, mock_get_authorized_service): data = {'name': 'John', 'age': 40} mock_credential_obj = Mock(OAuth2Credentials) mock_get_authorized_service.return_value = Mock() gviews_v4._get_authorized_service().spreadsheets().values().get().\ execute().get.return_value = data values, error = gviews_v4._fetch_data_gsheet( mock_credential_obj, 1234, 'Syria Security Incidences') self.assertIsNone(error) self.assertEqual(values, data)
def test_fetch_data_gsheet_exception(self): exception = Exception('Deu ruim') mock_credential_obj = Mock(OAuth2Credentials) mock_service_execute = Mock(side_effect=exception) gviews_v4._get_authorized_service = Mock() gviews_v4._get_authorized_service().spreadsheets = mock_service_execute values, error = gviews_v4._fetch_data_gsheet( mock_credential_obj, 1234, 'Syria Security Incidences') expected_error = { 'level': messages.ERROR, 'msg': 'Something went wrong 22: Deu ruim', 'redirect': None } self.assertIsNotNone(error) self.assertIsNone(values) self.assertEqual(error, expected_error)