11import copy
2- import os
32import time
43import unittest
54import warnings
65from pathlib import Path
76
8- import dotenv
97import pandas as pd
108import pytest
119
2321from dune_client .query import QueryBase
2422from dune_client .types import QueryParameter
2523
26- dotenv .load_dotenv ()
27-
2824
2925class TestDuneClient (unittest .TestCase ):
3026 def setUp (self ) -> None :
@@ -43,7 +39,6 @@ def setUp(self) -> None:
4339 name = "Query that returns multiple rows" ,
4440 query_id = 3435763 ,
4541 )
46- self .valid_api_key = os .environ ["DUNE_API_KEY" ]
4742
4843 def copy_query_and_change_parameters (self ) -> QueryBase :
4944 new_query = copy .copy (self .query )
@@ -79,19 +74,19 @@ def test_default_constructor_reads_env(self):
7974
8075 def test_get_execution_status (self ):
8176 query = QueryBase (name = "No Name" , query_id = 1276442 , params = [])
82- dune = DuneClient (self . valid_api_key )
77+ dune = DuneClient ()
8378 job_id = dune .execute_query (query ).execution_id
8479 status = dune .get_execution_status (job_id )
8580 assert status .state in [ExecutionState .EXECUTING , ExecutionState .PENDING ]
8681
8782 def test_run_query (self ):
88- dune = DuneClient (self . valid_api_key )
83+ dune = DuneClient ()
8984 results = dune .run_query (self .query ).get_rows ()
9085 assert len (results ) > 0
9186
9287 def test_run_query_paginated (self ):
9388 # Arrange
94- dune = DuneClient (self . valid_api_key )
89+ dune = DuneClient ()
9590
9691 # Act
9792 results = dune .run_query (self .multi_rows_query , batch_size = 1 ).get_rows ()
@@ -107,7 +102,7 @@ def test_run_query_paginated(self):
107102
108103 def test_run_query_with_filters (self ):
109104 # Arrange
110- dune = DuneClient (self . valid_api_key )
105+ dune = DuneClient ()
111106
112107 # Act
113108 results = dune .run_query (self .multi_rows_query , filters = "number < 3" ).get_rows ()
@@ -116,18 +111,18 @@ def test_run_query_with_filters(self):
116111 assert results == [{"number" : 1 }, {"number" : 2 }]
117112
118113 def test_run_query_performance_large (self ):
119- dune = DuneClient (self . valid_api_key )
114+ dune = DuneClient ()
120115 results = dune .run_query (self .query , performance = "large" ).get_rows ()
121116 assert len (results ) > 0
122117
123118 def test_run_query_dataframe (self ):
124- dune = DuneClient (self . valid_api_key )
119+ dune = DuneClient ()
125120 pd = dune .run_query_dataframe (self .query )
126121 assert len (pd ) > 0
127122
128123 def test_parameters_recognized (self ):
129124 new_query = self .copy_query_and_change_parameters ()
130- dune = DuneClient (self . valid_api_key )
125+ dune = DuneClient ()
131126 results = dune .run_query (new_query )
132127 assert results .get_rows () == [
133128 {
@@ -139,7 +134,7 @@ def test_parameters_recognized(self):
139134 ]
140135
141136 def test_endpoints (self ):
142- dune = DuneClient (self . valid_api_key )
137+ dune = DuneClient ()
143138 execution_response = dune .execute_query (self .query )
144139 assert isinstance (execution_response , ExecutionResponse )
145140 job_id = execution_response .execution_id
@@ -151,7 +146,7 @@ def test_endpoints(self):
151146 assert len (results ) > 0
152147
153148 def test_cancel_execution (self ):
154- dune = DuneClient (self . valid_api_key )
149+ dune = DuneClient ()
155150 query = QueryBase (
156151 name = "Long Running Query" ,
157152 query_id = 1229120 ,
@@ -181,7 +176,7 @@ def test_invalid_api_key_error(self):
181176 assert str (err .value ) == "Can't build ResultsResponse from {'error': 'invalid API Key'}"
182177
183178 def test_query_not_found_error (self ):
184- dune = DuneClient (self . valid_api_key )
179+ dune = DuneClient ()
185180 query = copy .copy (self .query )
186181 query .query_id = 99999999 # Invalid Query Id.
187182
@@ -190,7 +185,7 @@ def test_query_not_found_error(self):
190185 assert str (err .value ) == "Can't build ExecutionResponse from {'error': 'Query not found'}"
191186
192187 def test_internal_error (self ):
193- dune = DuneClient (self . valid_api_key )
188+ dune = DuneClient ()
194189 query = copy .copy (self .query )
195190 # This query ID is too large!
196191 query .query_id = 9999999999999
@@ -203,7 +198,7 @@ def test_internal_error(self):
203198 )
204199
205200 def test_invalid_job_id_error (self ):
206- dune = DuneClient (self . valid_api_key )
201+ dune = DuneClient ()
207202 with pytest .raises (DuneError ) as err :
208203 dune .get_execution_status ("Wonky Job ID" )
209204 assert (
@@ -212,18 +207,18 @@ def test_invalid_job_id_error(self):
212207 )
213208
214209 def test_get_latest_result_with_query_object (self ):
215- dune = DuneClient (self . valid_api_key )
210+ dune = DuneClient ()
216211 results = dune .get_latest_result (self .query ).get_rows ()
217212 assert len (results ) > 0
218213
219214 def test_get_latest_result_with_query_id (self ):
220- dune = DuneClient (self . valid_api_key )
215+ dune = DuneClient ()
221216 results = dune .get_latest_result (self .query .query_id ).get_rows ()
222217 assert len (results ) > 0
223218
224219 @unittest .skip ("Requires custom namespace and table_name input." )
225220 def test_upload_csv_success (self ):
226- client = DuneClient (self . valid_api_key )
221+ client = DuneClient ()
227222 assert client .upload_csv (
228223 table_name = "e2e-test" ,
229224 description = "best data" ,
@@ -234,7 +229,7 @@ def test_upload_csv_success(self):
234229 def test_create_table_success (self ):
235230 # Make sure the table doesn't already exist.
236231 # You will need to change the namespace to your own.
237- client = DuneClient (self . valid_api_key )
232+ client = DuneClient ()
238233
239234 namespace = "bh2smith"
240235 table_name = "dataset_e2e_test"
@@ -275,7 +270,7 @@ def test_create_table_error(self):
275270 def test_insert_table_csv_success (self ):
276271 # Make sure the table already exists and csv matches table schema.
277272 # You will need to change the namespace to your own.
278- client = DuneClient (self . valid_api_key )
273+ client = DuneClient ()
279274 namespace = "bh2smith"
280275 table_name = "dataset_e2e_test"
281276 client .create_table (
@@ -293,7 +288,7 @@ def test_insert_table_csv_success(self):
293288
294289 @unittest .skip ("Requires custom namespace and table_name input." )
295290 def test_clear_data (self ):
296- client = DuneClient (self . valid_api_key )
291+ client = DuneClient ()
297292 namespace = "bh2smith"
298293 table_name = "dataset_e2e_test"
299294 assert client .clear_data (namespace , table_name ) == ClearTableResult (
@@ -304,7 +299,7 @@ def test_clear_data(self):
304299 def test_insert_table_json_success (self ):
305300 # Make sure the table already exists and json matches table schema.
306301 # You will need to change the namespace to your own.
307- client = DuneClient (self . valid_api_key )
302+ client = DuneClient ()
308303 with Path ("./tests/fixtures/sample_table_insert.json" ).open ("rb" ) as data :
309304 assert client .insert_table (
310305 namespace = "test" ,
@@ -317,7 +312,7 @@ def test_insert_table_json_success(self):
317312 def test_delete_table_success (self ):
318313 # Make sure the table doesn't already exist.
319314 # You will need to change the namespace to your own.
320- client = DuneClient (self . valid_api_key )
315+ client = DuneClient ()
321316
322317 namespace = "test"
323318 table_name = "dataset_e2e_test"
@@ -330,7 +325,7 @@ def test_delete_table_success(self):
330325
331326 def test_download_csv_with_pagination (self ):
332327 # Arrange
333- client = DuneClient (self . valid_api_key )
328+ client = DuneClient ()
334329 client .run_query (self .multi_rows_query )
335330
336331 # Act
@@ -347,7 +342,7 @@ def test_download_csv_with_pagination(self):
347342
348343 def test_download_csv_with_filters (self ):
349344 # Arrange
350- client = DuneClient (self . valid_api_key )
345+ client = DuneClient ()
351346 client .run_query (self .multi_rows_query )
352347
353348 # Act
@@ -363,7 +358,7 @@ def test_download_csv_with_filters(self):
363358 ]
364359
365360 def test_download_csv_success_by_id (self ):
366- client = DuneClient (self . valid_api_key )
361+ client = DuneClient ()
367362 new_query = self .copy_query_and_change_parameters ()
368363 # Run query with new parameters
369364 client .run_query (new_query )
@@ -380,7 +375,7 @@ def test_download_csv_success_by_id(self):
380375 ]
381376
382377 def test_download_csv_success_with_params (self ):
383- client = DuneClient (self . valid_api_key )
378+ client = DuneClient ()
384379 # Download CSV with query and given parameters.
385380 result_csv = client .download_csv (self .query )
386381 # Expect the result to be relative to values of given parameters.
@@ -402,8 +397,7 @@ def test_download_csv_success_with_params(self):
402397@unittest .skip ("This is an enterprise only endpoint that can no longer be tested." )
403398class TestCRUDOps (unittest .TestCase ):
404399 def setUp (self ) -> None :
405- self .valid_api_key = os .environ ["DUNE_API_KEY" ]
406- self .client = DuneClient (self .valid_api_key , client_version = "alpha/v1" )
400+ self .client = DuneClient (client_version = "alpha/v1" )
407401 self .existing_query_id = 2713571
408402
409403 @unittest .skip ("Works fine, but creates too many queries" )
0 commit comments