-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor Part I: Deprecate & Rename Old Routes #64
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,28 +38,28 @@ def test_from_env_constructor(self): | |
except KeyError: | ||
self.fail("DuneClient.from_env raised unexpectedly!") | ||
|
||
def test_get_status(self): | ||
def test_get_execution_status(self): | ||
query = QueryBase(name="No Name", query_id=1276442, params=[]) | ||
dune = DuneClient(self.valid_api_key) | ||
job_id = dune.execute(query).execution_id | ||
status = dune.get_status(job_id) | ||
job_id = dune.execute_query(query).execution_id | ||
status = dune.get_execution_status(job_id) | ||
self.assertTrue( | ||
status.state in [ExecutionState.EXECUTING, ExecutionState.PENDING] | ||
) | ||
|
||
def test_refresh(self): | ||
def test_run_query(self): | ||
dune = DuneClient(self.valid_api_key) | ||
results = dune.refresh(self.query).get_rows() | ||
results = dune.run_query(self.query).get_rows() | ||
self.assertGreater(len(results), 0) | ||
|
||
def test_refresh_performance_large(self): | ||
def test_run_query_performance_large(self): | ||
dune = DuneClient(self.valid_api_key) | ||
results = dune.refresh(self.query, performance="large").get_rows() | ||
results = dune.run_query(self.query, performance="large").get_rows() | ||
self.assertGreater(len(results), 0) | ||
|
||
def test_refresh_into_dataframe(self): | ||
def test_run_query_dataframe(self): | ||
dune = DuneClient(self.valid_api_key) | ||
pd = dune.refresh_into_dataframe(self.query) | ||
pd = dune.run_query_dataframe(self.query) | ||
self.assertGreater(len(pd), 0) | ||
|
||
def test_parameters_recognized(self): | ||
|
@@ -75,7 +75,7 @@ def test_parameters_recognized(self): | |
self.assertEqual(query.parameters(), new_params) | ||
|
||
dune = DuneClient(self.valid_api_key) | ||
results = dune.refresh(query) | ||
results = dune.run_query(query) | ||
self.assertEqual( | ||
results.get_rows(), | ||
[ | ||
|
@@ -90,14 +90,14 @@ def test_parameters_recognized(self): | |
|
||
def test_endpoints(self): | ||
dune = DuneClient(self.valid_api_key) | ||
execution_response = dune.execute(self.query) | ||
execution_response = dune.execute_query(self.query) | ||
self.assertIsInstance(execution_response, ExecutionResponse) | ||
job_id = execution_response.execution_id | ||
status = dune.get_status(job_id) | ||
status = dune.get_execution_status(job_id) | ||
self.assertIsInstance(status, ExecutionStatusResponse) | ||
while dune.get_status(job_id).state != ExecutionState.COMPLETED: | ||
while dune.get_execution_status(job_id).state != ExecutionState.COMPLETED: | ||
time.sleep(1) | ||
results = dune.get_result(job_id).result.rows | ||
results = dune.get_execution_results(job_id).result.rows | ||
self.assertGreater(len(results), 0) | ||
|
||
def test_cancel_execution(self): | ||
|
@@ -106,31 +106,31 @@ def test_cancel_execution(self): | |
name="Long Running Query", | ||
query_id=1229120, | ||
) | ||
execution_response = dune.execute(query) | ||
execution_response = dune.execute_query(query) | ||
job_id = execution_response.execution_id | ||
# POST Cancellation | ||
success = dune.cancel_execution(job_id) | ||
self.assertTrue(success) | ||
|
||
results = dune.get_result(job_id) | ||
results = dune.get_execution_results(job_id) | ||
self.assertEqual(results.state, ExecutionState.CANCELLED) | ||
|
||
def test_invalid_api_key_error(self): | ||
dune = DuneClient(api_key="Invalid Key") | ||
with self.assertRaises(DuneError) as err: | ||
dune.execute(self.query) | ||
dune.execute_query(self.query) | ||
self.assertEqual( | ||
str(err.exception), | ||
"Can't build ExecutionResponse from {'error': 'invalid API Key'}", | ||
) | ||
with self.assertRaises(DuneError) as err: | ||
dune.get_status("wonky job_id") | ||
dune.get_execution_status("wonky job_id") | ||
self.assertEqual( | ||
str(err.exception), | ||
"Can't build ExecutionStatusResponse from {'error': 'invalid API Key'}", | ||
) | ||
with self.assertRaises(DuneError) as err: | ||
dune.get_result("wonky job_id") | ||
dune.get_execution_results("wonky job_id") | ||
self.assertEqual( | ||
str(err.exception), | ||
"Can't build ResultsResponse from {'error': 'invalid API Key'}", | ||
|
@@ -142,7 +142,7 @@ def test_query_not_found_error(self): | |
query.query_id = 99999999 # Invalid Query Id. | ||
|
||
with self.assertRaises(DuneError) as err: | ||
dune.execute(query) | ||
dune.execute_query(query) | ||
self.assertEqual( | ||
str(err.exception), | ||
"Can't build ExecutionResponse from {'error': 'Query not found'}", | ||
|
@@ -155,7 +155,7 @@ def test_internal_error(self): | |
query.query_id = 9999999999999 | ||
|
||
with self.assertRaises(DuneError) as err: | ||
dune.execute(query) | ||
dune.execute_query(query) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now, looking at the code and having refreshed my memory: question for you:
with functions like
instead of:
for me, the two idiomatic options would be:
Right now, I see bits of OO in here, but inconsistently:
this is just food for thought, the goal here is to improve the code for readability and dev experience in a simple, pragmatic way. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I definitely agree some things like this could be approached differently. In all of the ways suggested above. These things have been on my mind for quite some time. I believe the reason we went for Maybe it can be made compatible with multiple approaches (i.e. introduce some method overrides where users can pass Query object or |
||
self.assertEqual( | ||
str(err.exception), | ||
"Can't build ExecutionResponse from {'error': 'An internal error occured'}", | ||
|
@@ -164,7 +164,7 @@ def test_internal_error(self): | |
def test_invalid_job_id_error(self): | ||
dune = DuneClient(self.valid_api_key) | ||
with self.assertRaises(DuneError) as err: | ||
dune.get_status("Wonky Job ID") | ||
dune.get_execution_status("Wonky Job ID") | ||
self.assertEqual( | ||
str(err.exception), | ||
"Can't build ExecutionStatusResponse from " | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deprecate and replace w/
get_query_result()
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is different than
get_query_result
. Get latest, fetches the latest results buy query ID (as opposed to execution/job ID).I suppose we could do as you suggest, but I personally find the two to be rather different.
cf:
https://dune.com/docs/api/api-reference/latest_results/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so I don't forget, I need to review this again, but we should have a
get_query_result()
that uses aQuery
and simply returns the latest available query result (using the API that exists for that).This method has the clear difference that it doesnt use up any execution credits, which is important.