Skip to content

Commit

Permalink
fix download_csv tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bh2smith committed Sep 7, 2023
1 parent a40379a commit f1fec83
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions tests/e2e/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ def setUp(self) -> None:
)
self.valid_api_key = os.environ["DUNE_API_KEY"]

def copy_query_and_change_parameters(self) -> QueryBase:
new_query = copy.copy(self.query)
new_query.params = [
# Using all different values for parameters.
QueryParameter.text_type(name="TextField", value="different word"),
QueryParameter.number_type(name="NumberField", value=22),
QueryParameter.date_type(name="DateField", value="1991-01-01 00:00:00"),
QueryParameter.enum_type(name="ListField", value="Option 2"),
]
self.assertNotEqual(self.query.parameters(), new_query.parameters())
return new_query

def test_from_env_constructor(self):
try:
DuneClient.from_env()
Expand Down Expand Up @@ -66,19 +78,9 @@ def test_run_query_dataframe(self):
self.assertGreater(len(pd), 0)

def test_parameters_recognized(self):
query = copy.copy(self.query)
new_params = [
# Using all different values for parameters.
QueryParameter.text_type(name="TextField", value="different word"),
QueryParameter.number_type(name="NumberField", value=22),
QueryParameter.date_type(name="DateField", value="1991-01-01 00:00:00"),
QueryParameter.enum_type(name="ListField", value="Option 2"),
]
query.params = new_params
self.assertEqual(query.parameters(), new_params)

new_query = self.copy_query_and_change_parameters()
dune = DuneClient(self.valid_api_key)
results = dune.run_query(query)
results = dune.run_query(new_query)
self.assertEqual(
results.get_rows(),
[
Expand Down Expand Up @@ -197,16 +199,30 @@ def test_upload_csv_success(self):

def test_download_csv_success_by_id(self):
client = DuneClient(self.valid_api_key)
new_query = self.copy_query_and_change_parameters()
# Run query with new parameters
client.run_query(new_query)
# Download CSV by query_id
result_csv = client.download_csv(self.query.query_id)
# Expect that the csv returns the latest execution results (i.e. those that were just run)
self.assertEqual(
pandas.read_csv(result_csv.data).to_csv(index=False),
"text_field,number_field,date_field,list_field\n"
"Word,3.1415926535,2022-05-04 00:00:00.000,Option 1\n",
"different word,22,1991-01-01 00:00:00.000,Option 2\n",
)

def test_download_csv_success_with_params(self):
client = DuneClient(self.valid_api_key)
# Download CSV with query and given parameters.
result_csv = client.download_csv(self.query)
# Expect the result to be relative to values of given parameters.
#################################################################
# Note that we could compare results with
# ",".join([p.value for p in self.query.parameters()]) + "\n"
# but there seems to be a discrepancy with the date string values.
# Specifically 1991-01-01 00:00:00.000
# vs 1991-01-01 00:00:00
#################################################################
self.assertEqual(
pandas.read_csv(result_csv.data).to_csv(index=False),
"text_field,number_field,date_field,list_field\n"
Expand Down

0 comments on commit f1fec83

Please sign in to comment.