diff --git a/tests/e2e/test_client.py b/tests/e2e/test_client.py index e4e7b6b..4733a8a 100644 --- a/tests/e2e/test_client.py +++ b/tests/e2e/test_client.py @@ -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() @@ -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(), [ @@ -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"