|
3 | 3 | #
|
4 | 4 |
|
5 | 5 |
|
| 6 | +import logging |
6 | 7 | from functools import partial
|
7 | 8 |
|
8 | 9 | import pytest
|
| 10 | +from airbyte_cdk.sources.deprecated.base_source import ConfiguredAirbyteCatalog, Type |
9 | 11 | from source_hubspot.api import API, PROPERTIES_PARAM_MAX_LENGTH, split_properties
|
10 | 12 | from source_hubspot.client import Client
|
| 13 | +from source_hubspot.source import SourceHubspot |
11 | 14 |
|
12 | 15 | NUMBER_OF_PROPERTIES = 2000
|
13 | 16 |
|
| 17 | +logger = logging.getLogger("test_client") |
| 18 | + |
14 | 19 |
|
15 | 20 | @pytest.fixture(name="some_credentials")
|
16 | 21 | def some_credentials_fixture():
|
@@ -260,3 +265,51 @@ def test_stream_with_splitting_properties_with_new_record(self, requests_mock, c
|
260 | 265 | stream_records = list(test_stream.read(getter=partial(self.get, test_stream.url, api=api)))
|
261 | 266 |
|
262 | 267 | assert len(stream_records) == 6
|
| 268 | + |
| 269 | + |
| 270 | +@pytest.fixture(name="oauth_config") |
| 271 | +def oauth_config_fixture(): |
| 272 | + return { |
| 273 | + "start_date": "2021-10-10T00:00:00Z", |
| 274 | + "credentials": { |
| 275 | + "credentials_title": "OAuth Credentials", |
| 276 | + "redirect_uri": "https://airbyte.io", |
| 277 | + "client_id": "test_client_id", |
| 278 | + "client_secret": "test_client_secret", |
| 279 | + "refresh_token": "test_refresh_token", |
| 280 | + "access_token": "test_access_token", |
| 281 | + "token_expires": "2021-05-30T06:00:00Z", |
| 282 | + }, |
| 283 | + } |
| 284 | + |
| 285 | + |
| 286 | +@pytest.fixture(name="configured_catalog") |
| 287 | +def configured_catalog_fixture(): |
| 288 | + configured_catalog = { |
| 289 | + "streams": [ |
| 290 | + { |
| 291 | + "stream": { |
| 292 | + "name": "quotes", |
| 293 | + "json_schema": {}, |
| 294 | + "supported_sync_modes": ["full_refresh", "incremental"], |
| 295 | + "source_defined_cursor": True, |
| 296 | + "default_cursor_field": ["updatedAt"], |
| 297 | + }, |
| 298 | + "sync_mode": "incremental", |
| 299 | + "cursor_field": ["updatedAt"], |
| 300 | + "destination_sync_mode": "append", |
| 301 | + } |
| 302 | + ] |
| 303 | + } |
| 304 | + return ConfiguredAirbyteCatalog.parse_obj(configured_catalog) |
| 305 | + |
| 306 | + |
| 307 | +def test_it_should_not_read_quotes_stream_if_it_does_not_exist_in_client(oauth_config, configured_catalog): |
| 308 | + """ |
| 309 | + If 'quotes' stream is not in the client, it should skip it. |
| 310 | + """ |
| 311 | + source = SourceHubspot() |
| 312 | + |
| 313 | + all_records = list(source.read(logger, config=oauth_config, catalog=configured_catalog, state=None)) |
| 314 | + records = [record for record in all_records if record.type == Type.RECORD] |
| 315 | + assert not records |
0 commit comments