@@ -36,6 +36,7 @@ def setUp(self) -> None:
3636 async def test_get_status (self ):
3737 query = Query (name = "No Name" , query_id = 1276442 , params = [])
3838 dune = AsyncDuneClient (self .valid_api_key )
39+ await dune .connect ()
3940 job_id = (await dune .execute (query )).execution_id
4041 status = await dune .get_status (job_id )
4142 self .assertTrue (
@@ -45,6 +46,7 @@ async def test_get_status(self):
4546
4647 async def test_refresh (self ):
4748 dune = AsyncDuneClient (self .valid_api_key )
49+ await dune .connect ()
4850 results = (await dune .refresh (self .query )).get_rows ()
4951 self .assertGreater (len (results ), 0 )
5052 await dune .close_session ()
@@ -62,6 +64,7 @@ async def test_parameters_recognized(self):
6264 self .assertEqual (query .parameters (), new_params )
6365
6466 dune = AsyncDuneClient (self .valid_api_key )
67+ await dune .connect ()
6568 results = await dune .refresh (query )
6669 self .assertEqual (
6770 results .get_rows (),
@@ -78,6 +81,7 @@ async def test_parameters_recognized(self):
7881
7982 async def test_endpoints (self ):
8083 dune = AsyncDuneClient (self .valid_api_key )
84+ await dune .connect ()
8185 execution_response = await dune .execute (self .query )
8286 self .assertIsInstance (execution_response , ExecutionResponse )
8387 job_id = execution_response .execution_id
@@ -93,6 +97,7 @@ async def test_endpoints(self):
9397
9498 async def test_cancel_execution (self ):
9599 dune = AsyncDuneClient (self .valid_api_key )
100+ await dune .connect ()
96101 query = Query (
97102 name = "Long Running Query" ,
98103 query_id = 1229120 ,
@@ -109,6 +114,7 @@ async def test_cancel_execution(self):
109114
110115 async def test_invalid_api_key_error (self ):
111116 dune = AsyncDuneClient (api_key = "Invalid Key" )
117+ await dune .connect ()
112118 with self .assertRaises (DuneError ) as err :
113119 await dune .execute (self .query )
114120 self .assertEqual (
@@ -131,6 +137,7 @@ async def test_invalid_api_key_error(self):
131137
132138 async def test_query_not_found_error (self ):
133139 dune = AsyncDuneClient (self .valid_api_key )
140+ await dune .connect ()
134141 query = copy .copy (self .query )
135142 query .query_id = 99999999 # Invalid Query Id.
136143
@@ -144,6 +151,7 @@ async def test_query_not_found_error(self):
144151
145152 async def test_internal_error (self ):
146153 dune = AsyncDuneClient (self .valid_api_key )
154+ await dune .connect ()
147155 query = copy .copy (self .query )
148156 # This query ID is too large!
149157 query .query_id = 9999999999999
@@ -158,6 +166,7 @@ async def test_internal_error(self):
158166
159167 async def test_invalid_job_id_error (self ):
160168 dune = AsyncDuneClient (self .valid_api_key )
169+ await dune .connect ()
161170
162171 with self .assertRaises (DuneError ) as err :
163172 await dune .get_status ("Wonky Job ID" )
@@ -168,6 +177,25 @@ async def test_invalid_job_id_error(self):
168177 )
169178 await dune .close_session ()
170179
180+ async def test_disconnect (self ):
181+ dune = AsyncDuneClient (self .valid_api_key )
182+ await dune .connect ()
183+ results = (await dune .refresh (self .query )).get_rows ()
184+ self .assertGreater (len (results ), 0 )
185+ await dune .close_session ()
186+ self .assertTrue (cl ._session .closed )
187+
188+ async def test_refresh_context_manager_singleton (self ):
189+ dune = AsyncDuneClient (self .valid_api_key )
190+ async with dune as cl :
191+ results = (await cl .refresh (self .query )).get_rows ()
192+ self .assertGreater (len (results ), 0 )
193+
194+ async def test_refresh_context_manager (self ):
195+ async with AsyncDuneClient (self .valid_api_key ) as cl :
196+ results = (await cl .refresh (self .query )).get_rows ()
197+ self .assertGreater (len (results ), 0 )
198+
171199
172200if __name__ == "__main__" :
173201 unittest .main ()
0 commit comments