-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test chart data endpoint w/ duckdb #148
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,7 @@ test = [ | |
"responses", | ||
] | ||
dev = [ | ||
"duckdb", | ||
"pre-commit", | ||
"ruff < 0.9", | ||
"sqlfluff >= 3.2.5" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,13 +38,19 @@ def cache_api_data(s3_client, s3_bucket_name: str, db: str, target: str) -> None | |
"study": dp.split("__")[0], | ||
"name": dp.split("__")[1], | ||
} | ||
versions = column_types[dp_detail["study"]][dp_detail["name"]] | ||
studies = column_types.get(dp_detail["study"], {"name": None}) | ||
versions = studies.get(dp_detail["name"], None) | ||
if versions is None: | ||
print(f"{dp} not found in column_types") | ||
continue | ||
for version in versions: | ||
if version != dp: | ||
continue | ||
dp_dict = { | ||
**dp_detail, | ||
**versions[version], | ||
"version": version, | ||
"id": f"{dp_detail['study']}__{dp_detail['name']}__{version}", | ||
"version": version.split("__")[2], | ||
"id": f"{dp_detail['study']}__{dp_detail['name']}__{version.split('__')[2]}", | ||
Comment on lines
+51
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Is Like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I buy it |
||
} | ||
if "__flat" in dp: | ||
dp_dict["type"] = "flat" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,10 +22,13 @@ | |
aggregator | ||
""" | ||
|
||
import datetime | ||
import os | ||
import re | ||
from unittest import mock | ||
|
||
import boto3 | ||
import duckdb | ||
import pytest | ||
from moto import mock_athena, mock_s3, mock_sns | ||
|
||
|
@@ -155,7 +158,7 @@ def mock_notification(): | |
|
||
|
||
@pytest.fixture | ||
def mock_db(): | ||
def mock_athena_db(): | ||
"""Leaving this unused here for now - there are some low level inconsistencies | ||
between moto and AWS wrangler w.r.t. how workgroups are mocked out, but we might | ||
be able to use this in the future/mock AWSwranger below the entrypoint if we are | ||
|
@@ -176,6 +179,36 @@ def mock_db(): | |
athena.stop() | ||
|
||
|
||
@pytest.fixture | ||
def mock_db(tmp_path): | ||
def _compat_regexp_like(string: str | None, pattern: str | None) -> bool: | ||
match = re.search(pattern, string) | ||
return match is not None | ||
|
||
def _compat_from_iso8601_timestamp( | ||
value: str | datetime.datetime, | ||
) -> datetime.datetime: | ||
if type(value) is str: | ||
return datetime.datetime.fromisoformat(value) | ||
return value | ||
|
||
db = duckdb.connect(tmp_path / "duck.db") | ||
db.create_function( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Obviously you thought about this, but let's spill a tiny amount of digital ink. Pros/cons of having tests depend on cumulus-library and grabbing its DuckdbDatabase class? Not worth it yet, I'm guessing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, a couple thoughts
|
||
# DuckDB's version is regexp_matches. | ||
"regexp_like", | ||
_compat_regexp_like, | ||
None, | ||
duckdb.typing.BOOLEAN, | ||
) | ||
db.create_function( | ||
"from_iso8601_timestamp", | ||
_compat_from_iso8601_timestamp, | ||
None, | ||
duckdb.typing.TIMESTAMP, | ||
) | ||
yield db | ||
|
||
|
||
def test_mock_bucket(): | ||
s3_client = boto3.client("s3", region_name="us-east-1") | ||
item = s3_client.list_objects_v2(Bucket=os.environ["TEST_BUCKET"]) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this line about? Did you mean to leave that comment like that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was from an in process attempt to fix the underlying jinja template, which moved away from; will delete