コード例 #1
0
    def test_get_simple_audit_dataset(self):
        '''
        Fetch a simple dataset with 2 records from Typo
        '''
        out = None
        with patch('sys.stdout',
                   new=StringIO()) as mock_stdout, self.assertLogs(
                       LOGGER, level='INFO') as log:
            tap = TapTypo(config=generate_config())
            tap.sync()
            out = mock_stdout.getvalue()

        self.assertEqual(len(log.output), 4)

        self.assertEqual(out, TEST_GET_SIMPLE_AUDIT_DATASET_OUTPUT)
コード例 #2
0
    def test_multi_page_no_limit(self):
        '''
        Fetch two pages of a dataset until records end.
        '''
        out = None
        with patch('sys.stdout',
                   new=StringIO()) as mock_stdout, self.assertLogs(
                       LOGGER, level='INFO') as log:
            tap = TapTypo(config=generate_config(records_per_page=2))
            tap.sync()
            out = mock_stdout.getvalue()

        self.assertEqual(len(log.output), 5)

        self.assertEqual(out, TEST_MULTI_PAGE_NO_LIMIT_OUTPUT)
コード例 #3
0
    def test_discover_mode(self):
        '''
        tap-typo will fetch the schema from Typo and construct a catalog
        with the stream information.

        Verified on this test:
        - Discover mode output.
        - Conversion of typo-provided field types into JSON schema types.
        - Detection of key properties from typo-provided data.
        '''

        out = None

        with patch('sys.stdout',
                   new=StringIO()) as mock_stdout, self.assertLogs(
                       LOGGER, level='INFO') as log:
            tap = TapTypo(config=generate_config())
            tap.discover()
            out = mock_stdout.getvalue()

        self.assertEqual(len(log.output), 1)

        self.assertEqual(out, TEST_DISCOVER_MODE_OUTPUT)
コード例 #4
0
    def test_request_token(self, mock_post):
        '''
        Request an access token from Typo
        '''
        mock_post.return_value.status_code = 200
        mock_post.return_value.json.return_value = {'token': 'test'}

        with self.assertLogs(LOGGER, level='INFO') as log:
            tap = TapTypo(config=generate_config())

        self.assertEqual(len(log.output), 1)

        expected_headers = {'Content-Type': 'application/json'}

        expected_payload = {'apikey': 'typo_key', 'secret': 'typo_secret'}

        token = tap.request_token()

        mock_post.assert_called_with('https://typo.ai/token',
                                     data=json.dumps(expected_payload),
                                     headers=expected_headers,
                                     timeout=20)
        self.assertEqual(token, 'test')
コード例 #5
0
    def test_resume_with_state(self):
        '''
        Resume sync by providing state input
        '''
        out = None
        with patch('sys.stdout',
                   new=StringIO()) as mock_stdout, self.assertLogs(
                       LOGGER, level='INFO') as log:
            tap = TapTypo(
                config=generate_config(records_per_page=5),
                state={
                    'bookmarks': {
                        'tap-typo-repository-mock_repository-dataset-mock_dataset-audit-123':
                        {
                            '__typo_record_id': 6
                        }
                    }
                })
            tap.sync()
            out = mock_stdout.getvalue()

        self.assertEqual(len(log.output), 4)

        self.assertEqual(out, TEST_RESUME_WITH_STATE_OUTPUT)