예제 #1
0
 def test_config_provided_float_request_timeout(self, mock_get, mock_request):
     """ 
         Unit tests to ensure that request timeout is set based on config float value
     """
     config = { "refresh_token": "dummy_token", "client_id": "dummy_client_id", "client_secret": "dummy_client_secret", "user_agent": "dummy_ua", "request_timeout": 100.8}
     client = GoogleClient(**config)
     client.request("GET", "dummy_path")
     
     mock_request.assert_called_with('GET', 'https://sheets.googleapis.com/v4/dummy_path', headers={'Authorization': 'Bearer None', 'User-Agent': 'dummy_ua'}, timeout=100.8)
예제 #2
0
 def test_request_timeout_and_backoff(self, mock_get_token, mock_request):
     """
     Check whether the request backoffs properly for request() for 5 times in case of Timeout error.
     """
     mock_request.side_effect = Timeout
     client = GoogleClient("dummy_client_id", "dummy_client_secret", "dummy_refresh_token", 300)
     with self.assertRaises(Timeout):
         client.request("GET")
     self.assertEquals(mock_request.call_count, 5)
예제 #3
0
    def test_check_access_token_connection_error_and_backoff(self, mocked_request):
        """
        Check whether the request backoffs properly for __enter__() for 5 times in case of Timeout error.
        """
        mocked_request.side_effect = ConnectionError

        config = {
            "client_id": "dummy_ci",
            "client_secret": "dummy_cs",
            "refresh_token": "test_rt",
            "user_agent": "test_ua",
        }
        # initialize 'GoogleClient'
        try:
            with GoogleClient(config['client_id'],
                config['client_secret'],
                config['refresh_token'],
                config.get('request_timeout'),
                config['user_agent']) as client:
                pass
        except ConnectionError:
            pass

        # verify that we backoff for 5 times
        self.assertEquals(mocked_request.call_count, 5)
예제 #4
0
def main():

    parsed_args = singer.utils.parse_args(REQUIRED_CONFIG_KEYS)

    with GoogleClient(parsed_args.config['credentials_file']) as client:

        state = {}
        if parsed_args.state:
            state = parsed_args.state

        config = parsed_args.config
        spreadsheet_id = config.get('spreadsheet_id')

        if parsed_args.discover:
            do_discover(client, spreadsheet_id)
        elif parsed_args.catalog:
            sync(client=client,
                 config=config,
                 catalog=parsed_args.catalog,
                 state=state)
예제 #5
0
def main():
    parsed_args = parse_args(REQUIRED_CONFIG_KEYS)

    with GoogleClient(parsed_args.config['client_id'],
                      parsed_args.config['client_secret'],
                      parsed_args.config['refresh_token'],
                      parsed_args.config['user_agent']) as client:

        state = {}
        if parsed_args.state:
            state = parsed_args.state

        config = parsed_args.config
        spreadsheet_id = config.get('spreadsheet_id')

        if parsed_args.discover:
            do_discover(parsed_args.select_all, client, spreadsheet_id)
        elif parsed_args.catalog:
            sync(client=client,
                 config=config,
                 catalog=parsed_args.catalog,
                 state=state)
예제 #6
0
def gsheet_client(tap_config):
    return GoogleClient(tap_config.get('client_id'),
                        tap_config.get('client_secret'),
                        tap_config.get('refresh_token'),
                        tap_config.get('user_agent'))
예제 #7
0
 def test_unsupported_fields(self, mocked_get):
     """
     Test whether the incusion property for the skipped property is changed to `unsupported`
     and the description is added in the schema
     """
     sheet = {
         "sheets": [{
             "properties": {
                 "sheetId": 0,
                 "title": "Sheet1",
                 "index": 0,
                 "sheetType": "GRID",
                 "gridProperties": {
                     "rowCount": 3,
                     "columnCount": 26
                 }
             },
             "data": [{
                 "rowData": [{
                     "values": [{}, {
                         "formattedValue": "abc"
                     }, {
                         "formattedValue": "def"
                     }]
                 }, {
                     "values": [{
                         "formattedValue": "A"
                     }, {
                         "formattedValue": "B"
                     }, {
                         "formattedValue": "4"
                     }]
                 }]
             }]
         }]
     }
     expected_schema = {
         "type": "object",
         "additionalProperties": False,
         "properties": {
             "__sdc_spreadsheet_id": {
                 "type": ["null", "string"]
             },
             "__sdc_sheet_id": {
                 "type": ["null", "integer"]
             },
             "__sdc_row": {
                 "type": ["null", "integer"]
             },
             "__sdc_skip_col_01": {
                 "type": ["null", "string"],
                 "description":
                 "Column is unsupported and would be skipped because header is not available"
             },
             "abc": {
                 "type": ["null", "string"]
             },
             "def": {
                 "type": ["null", "string"]
             }
         }
     }
     mocked_get.return_value = sheet
     schemas, field_metadata = schema.get_schemas(
         GoogleClient('client_id', 'client_secret', 'refresh_token'),
         'sheet_id')
     # check if the schemas are equal, hence verifying if the description is present
     self.assertEqual(expected_schema, schemas["Sheet1"])
     for each in field_metadata["Sheet1"]:
         if each["breadcrumb"] and '__sdc_skip_col_01' in each["breadcrumb"]:
             # check if the inclusion property is updated to `unsupported`
             self.assertEqual(each["metadata"]["inclusion"], "unsupported")