-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c41ba16
commit 554ee97
Showing
7 changed files
with
126 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
google-cloud-bigquery==3.19.0 | ||
polars==0.20.16 | ||
polars==0.20.16 | ||
pyarrow==15.0.2 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import os | ||
from unittest import mock | ||
|
||
import polars as pl | ||
import pyarrow as pa | ||
|
||
from klondike import BigQueryConnector | ||
|
||
from .test_utils import KlondikeTestCase | ||
|
||
########## | ||
|
||
|
||
class TestBigQuery(KlondikeTestCase): | ||
def setUp(self): | ||
super().setUp() | ||
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = self._credentials_path | ||
|
||
def tearDown(self): | ||
super().tearDown() | ||
del os.environ["GOOGLE_APPLICATION_CREDENTIALS"] | ||
|
||
def _build_mock_cursor(self, query_results=None): | ||
cursor = mock.MagicMock() | ||
cursor.execute.return_value = None | ||
cursor.fetchmany.side_effect = [query_results, []] | ||
|
||
if query_results: | ||
cursor.description = query_results | ||
|
||
# Create a mock that will play the role of the connection | ||
connection = mock.MagicMock() | ||
connection.cursor.return_value = cursor | ||
|
||
# Create a mock that will play the role of our GoogleBigQuery client | ||
client = mock.MagicMock() | ||
|
||
bq = BigQueryConnector() | ||
bq._client = client | ||
|
||
return bq | ||
|
||
def test_read_dataframe_from_bigquery(self): | ||
# sql = "select * from my_table" | ||
# tbl = pa.table( | ||
# { | ||
# "city": ["Brooklyn", "San Francisco", "Richmond"], | ||
# "state": ["New York", "California", "Virginia"], | ||
# } | ||
# ) | ||
|
||
# bq = self._build_mock_cursor(query_results=tbl) | ||
# df = bq.read_dataframe_from_bigquery(sql=sql) | ||
|
||
# assert isinstance(df, pl.DataFrame) | ||
pass | ||
|
||
def test_write_dataframe_to_bigquery(self): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import json | ||
import os | ||
import tempfile | ||
import unittest | ||
|
||
########## | ||
|
||
|
||
class KlondikeTestCase(unittest.TestCase): | ||
def setUp(self): | ||
self._temp_directory = tempfile.TemporaryDirectory() | ||
|
||
self._credentials_path = os.path.join( | ||
self._temp_directory.name, "service_account.json" | ||
) | ||
|
||
self._service_account = { | ||
"type": "foo", | ||
"project_id": "bar", | ||
"private_key_id": "biz", | ||
"private_key": "bap", | ||
"client_email": "bim", | ||
"client_id": "top", | ||
"auth_uri": "hat", | ||
"token_uri": "tap", | ||
"auth_provider_x509_cert_url": "dance", | ||
"client_x509_cert_url": "good", | ||
"universe_domain": "stuff", | ||
} | ||
|
||
with open(self._credentials_path, "w") as f: | ||
json.dump(self._service_account, f) | ||
|
||
def tearDown(self): | ||
self._temp_directory.cleanup() |