Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ classifiers = [
"Operating System :: OS Independent",
]
dependencies = [
"aiohttp~=3.10.0",
"aiohttp~=3.12.15",
"dataclasses-json~=0.6.4",
"python-dateutil~=2.8.2",
"requests~=2.31.0",
"python-dateutil~=2.9.0",
"requests~=2.32.5",
"ndjson~=0.3.1",
"Deprecated~=1.2.14",
"Deprecated~=1.2.18",
]
dynamic = ["version"]

Expand All @@ -48,7 +48,6 @@ dev = [
# Optional features
"pandas>=1.0.0",
"pandas-stubs>=1.0.0",
"python-dotenv>=1.0.0",
"aiounittest>=1.4.2",
"colorlover>=0.3.0",
"plotly>=5.9.0",
Expand Down
24 changes: 10 additions & 14 deletions tests/e2e/test_async_client.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import os
import unittest

import aiounittest
import dotenv
import pandas as pd

from dune_client.client_async import AsyncDuneClient
Expand All @@ -16,31 +14,29 @@ def setUp(self) -> None:
name="Query that returns multiple rows",
query_id=3435763,
)
dotenv.load_dotenv()
self.valid_api_key = os.environ["DUNE_API_KEY"]

async def test_disconnect(self):
dune = AsyncDuneClient(self.valid_api_key)
dune = AsyncDuneClient()
await dune.connect()
results = (await dune.refresh(self.query)).get_rows()
assert len(results) > 0
await dune.disconnect()
assert dune._session.closed

async def test_refresh_context_manager_singleton(self):
dune = AsyncDuneClient(self.valid_api_key)
dune = AsyncDuneClient()
async with dune as cl:
results = (await cl.refresh(self.query)).get_rows()
assert len(results) > 0

async def test_refresh_context_manager(self):
async with AsyncDuneClient(self.valid_api_key) as cl:
async with AsyncDuneClient() as cl:
results = (await cl.refresh(self.query)).get_rows()
assert len(results) > 0

async def test_refresh_with_pagination(self):
# Arrange
async with AsyncDuneClient(self.valid_api_key) as cl:
async with AsyncDuneClient() as cl:
# Act
results = (await cl.refresh(self.multi_rows_query, batch_size=1)).get_rows()

Expand All @@ -55,7 +51,7 @@ async def test_refresh_with_pagination(self):

async def test_refresh_with_filters(self):
# Arrange
async with AsyncDuneClient(self.valid_api_key) as cl:
async with AsyncDuneClient() as cl:
# Act
results = (await cl.refresh(self.multi_rows_query, filters="number < 3")).get_rows()

Expand All @@ -64,7 +60,7 @@ async def test_refresh_with_filters(self):

async def test_refresh_csv_with_pagination(self):
# Arrange
async with AsyncDuneClient(self.valid_api_key) as cl:
async with AsyncDuneClient() as cl:
# Act
result_csv = await cl.refresh_csv(self.multi_rows_query, batch_size=1)

Expand All @@ -79,7 +75,7 @@ async def test_refresh_csv_with_pagination(self):

async def test_refresh_csv_with_filters(self):
# Arrange
async with AsyncDuneClient(self.valid_api_key) as cl:
async with AsyncDuneClient() as cl:
# Act
result_csv = await cl.refresh_csv(self.multi_rows_query, filters="number < 3")

Expand All @@ -91,17 +87,17 @@ async def test_refresh_csv_with_filters(self):

@unittest.skip("Large performance tier doesn't currently work.")
async def test_refresh_context_manager_performance_large(self):
async with AsyncDuneClient(self.valid_api_key) as cl:
async with AsyncDuneClient() as cl:
results = (await cl.refresh(self.query, performance="large")).get_rows()
assert len(results) > 0

async def test_get_latest_result_with_query_object(self):
async with AsyncDuneClient(self.valid_api_key) as cl:
async with AsyncDuneClient() as cl:
results = (await cl.get_latest_result(self.query)).get_rows()
assert len(results) > 0

async def test_get_latest_result_with_query_id(self):
async with AsyncDuneClient(self.valid_api_key) as cl:
async with AsyncDuneClient() as cl:
results = (await cl.get_latest_result(self.query.query_id)).get_rows()
assert len(results) > 0

Expand Down
56 changes: 25 additions & 31 deletions tests/e2e/test_client.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import copy
import os
import time
import unittest
import warnings
from pathlib import Path

import dotenv
import pandas as pd
import pytest

Expand All @@ -23,8 +21,6 @@
from dune_client.query import QueryBase
from dune_client.types import QueryParameter

dotenv.load_dotenv()


class TestDuneClient(unittest.TestCase):
def setUp(self) -> None:
Expand All @@ -43,7 +39,6 @@ def setUp(self) -> None:
name="Query that returns multiple rows",
query_id=3435763,
)
self.valid_api_key = os.environ["DUNE_API_KEY"]

def copy_query_and_change_parameters(self) -> QueryBase:
new_query = copy.copy(self.query)
Expand Down Expand Up @@ -79,19 +74,19 @@ def test_default_constructor_reads_env(self):

def test_get_execution_status(self):
query = QueryBase(name="No Name", query_id=1276442, params=[])
dune = DuneClient(self.valid_api_key)
dune = DuneClient()
job_id = dune.execute_query(query).execution_id
status = dune.get_execution_status(job_id)
assert status.state in [ExecutionState.EXECUTING, ExecutionState.PENDING]

def test_run_query(self):
dune = DuneClient(self.valid_api_key)
dune = DuneClient()
results = dune.run_query(self.query).get_rows()
assert len(results) > 0

def test_run_query_paginated(self):
# Arrange
dune = DuneClient(self.valid_api_key)
dune = DuneClient()

# Act
results = dune.run_query(self.multi_rows_query, batch_size=1).get_rows()
Expand All @@ -107,7 +102,7 @@ def test_run_query_paginated(self):

def test_run_query_with_filters(self):
# Arrange
dune = DuneClient(self.valid_api_key)
dune = DuneClient()

# Act
results = dune.run_query(self.multi_rows_query, filters="number < 3").get_rows()
Expand All @@ -116,18 +111,18 @@ def test_run_query_with_filters(self):
assert results == [{"number": 1}, {"number": 2}]

def test_run_query_performance_large(self):
dune = DuneClient(self.valid_api_key)
dune = DuneClient()
results = dune.run_query(self.query, performance="large").get_rows()
assert len(results) > 0

def test_run_query_dataframe(self):
dune = DuneClient(self.valid_api_key)
dune = DuneClient()
pd = dune.run_query_dataframe(self.query)
assert len(pd) > 0

def test_parameters_recognized(self):
new_query = self.copy_query_and_change_parameters()
dune = DuneClient(self.valid_api_key)
dune = DuneClient()
results = dune.run_query(new_query)
assert results.get_rows() == [
{
Expand All @@ -139,7 +134,7 @@ def test_parameters_recognized(self):
]

def test_endpoints(self):
dune = DuneClient(self.valid_api_key)
dune = DuneClient()
execution_response = dune.execute_query(self.query)
assert isinstance(execution_response, ExecutionResponse)
job_id = execution_response.execution_id
Expand All @@ -151,7 +146,7 @@ def test_endpoints(self):
assert len(results) > 0

def test_cancel_execution(self):
dune = DuneClient(self.valid_api_key)
dune = DuneClient()
query = QueryBase(
name="Long Running Query",
query_id=1229120,
Expand Down Expand Up @@ -181,7 +176,7 @@ def test_invalid_api_key_error(self):
assert str(err.value) == "Can't build ResultsResponse from {'error': 'invalid API Key'}"

def test_query_not_found_error(self):
dune = DuneClient(self.valid_api_key)
dune = DuneClient()
query = copy.copy(self.query)
query.query_id = 99999999 # Invalid Query Id.

Expand All @@ -190,7 +185,7 @@ def test_query_not_found_error(self):
assert str(err.value) == "Can't build ExecutionResponse from {'error': 'Query not found'}"

def test_internal_error(self):
dune = DuneClient(self.valid_api_key)
dune = DuneClient()
query = copy.copy(self.query)
# This query ID is too large!
query.query_id = 9999999999999
Expand All @@ -203,7 +198,7 @@ def test_internal_error(self):
)

def test_invalid_job_id_error(self):
dune = DuneClient(self.valid_api_key)
dune = DuneClient()
with pytest.raises(DuneError) as err:
dune.get_execution_status("Wonky Job ID")
assert (
Expand All @@ -212,18 +207,18 @@ def test_invalid_job_id_error(self):
)

def test_get_latest_result_with_query_object(self):
dune = DuneClient(self.valid_api_key)
dune = DuneClient()
results = dune.get_latest_result(self.query).get_rows()
assert len(results) > 0

def test_get_latest_result_with_query_id(self):
dune = DuneClient(self.valid_api_key)
dune = DuneClient()
results = dune.get_latest_result(self.query.query_id).get_rows()
assert len(results) > 0

@unittest.skip("Requires custom namespace and table_name input.")
def test_upload_csv_success(self):
client = DuneClient(self.valid_api_key)
client = DuneClient()
assert client.upload_csv(
table_name="e2e-test",
description="best data",
Expand All @@ -234,7 +229,7 @@ def test_upload_csv_success(self):
def test_create_table_success(self):
# Make sure the table doesn't already exist.
# You will need to change the namespace to your own.
client = DuneClient(self.valid_api_key)
client = DuneClient()

namespace = "bh2smith"
table_name = "dataset_e2e_test"
Expand Down Expand Up @@ -275,7 +270,7 @@ def test_create_table_error(self):
def test_insert_table_csv_success(self):
# Make sure the table already exists and csv matches table schema.
# You will need to change the namespace to your own.
client = DuneClient(self.valid_api_key)
client = DuneClient()
namespace = "bh2smith"
table_name = "dataset_e2e_test"
client.create_table(
Expand All @@ -293,7 +288,7 @@ def test_insert_table_csv_success(self):

@unittest.skip("Requires custom namespace and table_name input.")
def test_clear_data(self):
client = DuneClient(self.valid_api_key)
client = DuneClient()
namespace = "bh2smith"
table_name = "dataset_e2e_test"
assert client.clear_data(namespace, table_name) == ClearTableResult(
Expand All @@ -304,7 +299,7 @@ def test_clear_data(self):
def test_insert_table_json_success(self):
# Make sure the table already exists and json matches table schema.
# You will need to change the namespace to your own.
client = DuneClient(self.valid_api_key)
client = DuneClient()
with Path("./tests/fixtures/sample_table_insert.json").open("rb") as data:
assert client.insert_table(
namespace="test",
Expand All @@ -317,7 +312,7 @@ def test_insert_table_json_success(self):
def test_delete_table_success(self):
# Make sure the table doesn't already exist.
# You will need to change the namespace to your own.
client = DuneClient(self.valid_api_key)
client = DuneClient()

namespace = "test"
table_name = "dataset_e2e_test"
Expand All @@ -330,7 +325,7 @@ def test_delete_table_success(self):

def test_download_csv_with_pagination(self):
# Arrange
client = DuneClient(self.valid_api_key)
client = DuneClient()
client.run_query(self.multi_rows_query)

# Act
Expand All @@ -347,7 +342,7 @@ def test_download_csv_with_pagination(self):

def test_download_csv_with_filters(self):
# Arrange
client = DuneClient(self.valid_api_key)
client = DuneClient()
client.run_query(self.multi_rows_query)

# Act
Expand All @@ -363,7 +358,7 @@ def test_download_csv_with_filters(self):
]

def test_download_csv_success_by_id(self):
client = DuneClient(self.valid_api_key)
client = DuneClient()
new_query = self.copy_query_and_change_parameters()
# Run query with new parameters
client.run_query(new_query)
Expand All @@ -380,7 +375,7 @@ def test_download_csv_success_by_id(self):
]

def test_download_csv_success_with_params(self):
client = DuneClient(self.valid_api_key)
client = DuneClient()
# 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.
Expand All @@ -402,8 +397,7 @@ def test_download_csv_success_with_params(self):
@unittest.skip("This is an enterprise only endpoint that can no longer be tested.")
class TestCRUDOps(unittest.TestCase):
def setUp(self) -> None:
self.valid_api_key = os.environ["DUNE_API_KEY"]
self.client = DuneClient(self.valid_api_key, client_version="alpha/v1")
self.client = DuneClient(client_version="alpha/v1")
self.existing_query_id = 2713571

@unittest.skip("Works fine, but creates too many queries")
Expand Down
10 changes: 1 addition & 9 deletions tests/e2e/test_custom_endpoints.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
import os
import unittest
import warnings

import dotenv

from dune_client.client import DuneClient

dotenv.load_dotenv()


@unittest.skip("endpoint no longer exists - {'error': 'Custom endpoint not found'}")
class TestCustomEndpoints(unittest.TestCase):
def setUp(self) -> None:
self.valid_api_key = os.environ["DUNE_API_KEY"]

def test_getting_custom_endpoint_results(self):
dune = DuneClient(self.valid_api_key)
dune = DuneClient()
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
results = dune.get_custom_endpoint_result("dune", "new-test")
Expand Down
Loading