-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathtest_cloud_sql_reads.py
191 lines (168 loc) · 6.19 KB
/
test_cloud_sql_reads.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
"""Integration tests for reading from cache."""
from __future__ import annotations
import airbyte as ab
import pytest
from airbyte import cloud
from airbyte.caches.base import CacheBase
from airbyte.caches.bigquery import BigQueryCache
from airbyte.caches.snowflake import SnowflakeCache
from airbyte.caches.postgres import PostgresCache
from airbyte.caches.duckdb import DuckDBCache
from airbyte.cloud.sync_results import SyncResult
from sqlalchemy.engine.base import Engine
@pytest.fixture
def deployable_source() -> ab.Source:
return ab.get_source(
"source-faker",
config={"count": 100},
)
@pytest.fixture
def previous_job_run_id() -> int:
return 10136196
@pytest.mark.parametrize(
"deployed_connection_id",
[
pytest.param(
"c7b4d838-a612-495a-9d91-a14e477add51", # https://cloud.airbyte.com/workspaces/a0cc325a-d358-4df4-bdd4-c09d753b6afb/connections/c7b4d838-a612-495a-9d91-a14e477add51/status
id="Faker->Snowflake",
),
pytest.param(
"0e1d6b32-b8e3-4b68-91a3-3a314599c782", # https://cloud.airbyte.com/workspaces/a0cc325a-d358-4df4-bdd4-c09d753b6afb/connections/0e1d6b32-b8e3-4b68-91a3-3a314599c782/status
id="Faker->BigQuery",
),
pytest.param(
"", id="Faker->Postgres", marks=pytest.mark.skip(reason="Not yet supported")
),
pytest.param(
"",
id="Faker->MotherDuck",
marks=pytest.mark.skip(reason="Not yet supported"),
),
],
)
def test_read_from_deployed_connection(
cloud_workspace: cloud.CloudWorkspace,
deployed_connection_id: str,
with_snowflake_password_env_var,
with_bigquery_credentials_env_vars,
) -> None:
"""Test reading from a cache."""
# Run sync and get result:
sync_result = cloud_workspace.get_connection(
connection_id=deployed_connection_id
).get_sync_result()
# Test sync result:
assert sync_result
assert sync_result.is_job_complete()
cache = sync_result.get_sql_cache()
sqlalchemy_url = cache.get_sql_alchemy_url()
engine: Engine = sync_result.get_sql_engine()
assert "users" in sync_result.stream_names
dataset: ab.CachedDataset = sync_result.get_dataset(stream_name="users")
assert dataset.stream_name == "users"
pandas_df = dataset.to_pandas()
assert pandas_df.shape[0] == 100
assert pandas_df.shape[1] in { # Column count diff depending on when it was created
20,
21,
}
# Check that no values are null
for col in pandas_df.columns:
assert pandas_df[col].notnull().all()
@pytest.mark.parametrize(
"deployed_connection_id, cache_type",
[
pytest.param(
"c7b4d838-a612-495a-9d91-a14e477add51", # https://cloud.airbyte.com/workspaces/a0cc325a-d358-4df4-bdd4-c09d753b6afb/connections/c7b4d838-a612-495a-9d91-a14e477add51/status
SnowflakeCache,
id="Faker->Snowflake",
),
pytest.param(
"0e1d6b32-b8e3-4b68-91a3-3a314599c782", # https://cloud.airbyte.com/workspaces/a0cc325a-d358-4df4-bdd4-c09d753b6afb/connections/0e1d6b32-b8e3-4b68-91a3-3a314599c782/status
BigQueryCache,
id="Faker->BigQuery",
),
pytest.param(
"",
PostgresCache,
id="Faker->Postgres",
marks=pytest.mark.skip(reason="Not yet supported"),
),
pytest.param(
"",
DuckDBCache,
id="Faker->MotherDuck",
marks=pytest.mark.skip(reason="Not yet supported"),
),
],
)
def test_translate_cloud_job_to_sql_cache(
cloud_workspace: cloud.CloudWorkspace,
deployed_connection_id: str,
cache_type: type[CacheBase],
previous_job_run_id: int,
with_bigquery_credentials_env_vars,
with_snowflake_password_env_var,
) -> None:
"""Test reading from a cache."""
# Run sync and get result:
sync_result: SyncResult | None = cloud_workspace.get_connection(
connection_id=deployed_connection_id
).get_sync_result(
job_id=previous_job_run_id,
)
assert sync_result, f"Failed to get sync result for job {previous_job_run_id}"
# Test sync result:
assert sync_result.is_job_complete()
cache = sync_result.get_sql_cache()
assert isinstance(cache, cache_type), f"Expected {cache_type}, got {type(cache)}"
sqlalchemy_url = cache.get_sql_alchemy_url()
engine: Engine = sync_result.get_sql_engine()
@pytest.mark.parametrize(
"deployed_connection_id",
[
pytest.param("c7b4d838-a612-495a-9d91-a14e477add51", id="Faker->Snowflake"),
pytest.param("0e1d6b32-b8e3-4b68-91a3-3a314599c782", id="Faker->BigQuery"),
pytest.param(
"", id="Faker->Postgres", marks=pytest.mark.skip(reason="Not yet supported")
),
pytest.param(
"",
id="Faker->MotherDuck",
marks=pytest.mark.skip(reason="Not yet supported"),
),
],
)
def test_read_from_previous_job(
cloud_workspace: cloud.CloudWorkspace,
deployed_connection_id: str,
previous_job_run_id: int,
with_bigquery_credentials_env_vars,
with_snowflake_password_env_var,
) -> None:
"""Test reading from a cache."""
# Run sync and get result:
sync_result: SyncResult | None = cloud_workspace.get_connection(
connection_id=deployed_connection_id
).get_sync_result(
job_id=previous_job_run_id,
)
assert sync_result, f"Failed to get sync result for job {previous_job_run_id}"
# Test sync result:
assert sync_result.is_job_complete()
cache = sync_result.get_sql_cache()
sqlalchemy_url = cache.get_sql_alchemy_url()
engine: Engine = sync_result.get_sql_engine()
assert "users" in sync_result.stream_names
dataset: ab.CachedDataset = sync_result.get_dataset(stream_name="users")
assert dataset.stream_name == "users"
pandas_df = dataset.to_pandas()
assert pandas_df.shape[0] == 100
assert pandas_df.shape[1] in { # Column count diff depending on when it was created
20,
21,
}
for col in pandas_df.columns:
# Check that no values are null
assert pandas_df[col].notnull().all()