Esempio n. 1
0
    def test_currently_syncing_with_interrupt(self, mocked_write_bookmark,
                                              mocked_currently_syncing_streams,
                                              mocked_currently_syncing_sync,
                                              mocked_metadata, mocked_schema,
                                              mocked_process_records, mock_get,
                                              mocked_get_access_token):
        """Test currently syncing stream with interrupt"""

        state = {"currently_syncing": "targeting_genders"}
        sync(
            self.client, self.config,
            MockCatalog([
                "targeting_age_groups", "targeting_genders",
                "targeting_languages"
            ]), state)

        # create expected calls for which currently syncing is to be written
        expected_currently_syncing_calls_from_sync = [
            mock.call({"currently_syncing": "targeting_genders"},
                      'targeting_genders'),
            mock.call({"currently_syncing": "targeting_genders"}, None),
            mock.call({"currently_syncing": "targeting_genders"},
                      'targeting_languages'),
            mock.call({"currently_syncing": "targeting_genders"}, None),
            mock.call({"currently_syncing": "targeting_genders"}, None)
        ]
        # verify currently syncing is written for expected streams
        self.assertEqual(mocked_currently_syncing_sync.mock_calls,
                         expected_currently_syncing_calls_from_sync)
Esempio n. 2
0
    def test_bookmark_no_parent(self, mocked_metadata, mocked_process_record,
                                mocked_schema, mocked_client_get,
                                mocked_access_token):
        """Test bookmark write when no parent is in the endpoint """
        state = {}

        sync(self.client, self.config, MockCatalog(['organizations']), state)
        expected_bookmark = '{"bookmarks": {"organizations": {"updated_at": "2022-04-16T05:44:39.787000Z"}}, "currently_syncing": null}'
        state = json.dumps(state)

        # Check whether bookmark is written as expected
        self.assertEqual(state, expected_bookmark,
                         "Not getting expected bookmark value")
Esempio n. 3
0
    def test_bookmark_with_grand_parent(self, mocked_metadata,
                                        mocked_process_record, mocked_schema,
                                        mocked_client_get,
                                        mocked_access_token):
        """Test bookmark write when grandparent, it's child and child's child are there in the endpoint"""
        state = {}

        sync(self.client, self.config,
             MockCatalog(['organizations', 'ad_accounts', 'pixels']), state)

        expected_bookmark = '{"bookmarks": {"pixels": {"updated_at(parent_ad_account_id:adaccount_id)": "2022-04-16T05:44:39.787000Z"}, "ad_accounts": {"updated_at(parent_organization_id:organization_id)": "2022-04-16T05:44:39.787000Z"}, "organizations": {"updated_at": "2022-04-16T05:44:39.787000Z"}}, "currently_syncing": null}'
        state = json.dumps(state)

        # Check whether bookmark is written as expected
        self.assertEqual(state, expected_bookmark,
                         "Not getting expected bookmark value")
Esempio n. 4
0
    def test_currently_syncing_with_interrupt_old_stream_selected(
            self, mocked_write_bookmark, mocked_currently_syncing_streams,
            mocked_currently_syncing_sync, mocked_metadata, mocked_schema,
            mocked_process_records, mock_get, mocked_get_access_token):
        """Test currently syncing stream with interrupt, but the interrupted stream is not selected
           as a result, the state should set currently syncing as None at the end"""

        # set 'targeting_genders' as 'currently_syncing' in state file, but it is not selected
        state = {"currently_syncing": "targeting_genders"}
        sync(self.client, self.config, MockCatalog(["targeting_age_groups"]),
             state)

        # create expected calls for which currently syncing is to be written
        expected_currently_syncing_calls_from_sync = [
            mock.call({"currently_syncing": "targeting_genders"}, None)
        ]
        # verify currently syncing is set as None at the end
        self.assertEqual(mocked_currently_syncing_sync.mock_calls,
                         expected_currently_syncing_calls_from_sync)
Esempio n. 5
0
    def test_currently_syncing_with_grand_parent(
            self, mocked_write_bookmark, mocked_currently_syncing_streams,
            mocked_currently_syncing_sync, mocked_metadata, mocked_schema,
            mocked_process_records, mock_get, mocked_get_access_token):
        """Test currently syncing stream when parent, it"s child and child"s child is present"""

        sync(self.client, self.config, MockCatalog(["pixels"]), {})

        # create expected calls for which currently syncing is to be written
        expected_currently_syncing_calls_from_sync = [
            mock.call({}, 'organizations'),
            mock.call({}, None),
            mock.call({}, None)
        ]
        expected_currently_syncing_calls_from_streams = [
            mock.call({}, 'ad_accounts'),
            mock.call({}, 'pixels')
        ]
        # verify currently syncing is written for expected streams
        self.assertEqual(mocked_currently_syncing_sync.mock_calls,
                         expected_currently_syncing_calls_from_sync)
        self.assertEqual(mocked_currently_syncing_streams.mock_calls,
                         expected_currently_syncing_calls_from_streams)
Esempio n. 6
0
def main():

    parsed_args = singer.utils.parse_args(REQUIRED_CONFIG_KEYS)

    with SnapchatClient(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 = {}
        if parsed_args.config:
            config = parsed_args.config

        if parsed_args.discover:
            do_discover()
        elif parsed_args.catalog:
            sync(client=client,
                 config=config,
                 catalog=parsed_args.catalog,
                 state=state)