Skip to content

Commit

Permalink
Merge pull request #10 from cowprotocol/test-get-status
Browse files Browse the repository at this point in the history
handle case when expiry is not returned
  • Loading branch information
bh2smith authored Sep 5, 2022
2 parents c5094c3 + 42c7282 commit 20a6dd2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
6 changes: 4 additions & 2 deletions dune_client/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,19 @@ class TimeData:
"""A collection of all timestamp related values contained within Dune Response"""

submitted_at: datetime
expires_at: datetime
# For some reason... this field isn't always returned.
expires_at: Optional[datetime]
execution_started_at: datetime
execution_ended_at: Optional[datetime]

@classmethod
def from_dict(cls, data: dict[str, Any]) -> TimeData:
"""Constructor from dictionary. See unit test for sample input."""
end = data.get("execution_ended_at", None)
expires = data.get("expires_at", None)
return cls(
submitted_at=parse(data["submitted_at"]),
expires_at=parse(data["expires_at"]),
expires_at=None if expires is None else parse(expires),
execution_started_at=parse(data["execution_started_at"]),
execution_ended_at=None if end is None else parse(end),
)
Expand Down
7 changes: 7 additions & 0 deletions tests/e2e/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ def setUp(self) -> None:
dotenv.load_dotenv()
self.valid_api_key = os.environ["DUNE_API_KEY"]

def test_get_status(self):
query = Query(name="No Name", query_id=649345, params=[])
dune = DuneClient(self.valid_api_key)
job_id = dune.execute(query).execution_id
status = dune.get_status(job_id)
self.assertEqual(status.state, ExecutionState.EXECUTING)

def test_refresh(self):
dune = DuneClient(self.valid_api_key)
results = dune.refresh(self.query)
Expand Down
7 changes: 3 additions & 4 deletions tests/unit/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def setUp(self) -> None:
"query_id": self.query_id,
"state": "QUERY_STATE_EXECUTING",
"submitted_at": "2022-08-29T06:33:24.913138Z",
"expires_at": "1970-01-01T00:00:00Z",
"execution_started_at": "2022-08-29T06:33:24.916543331Z",
}
self.results_response_data = {
Expand Down Expand Up @@ -75,16 +74,16 @@ def test_parse_time_data(self):
expected_with_end, TimeData.from_dict(self.results_response_data)
)

expected_without_end = TimeData(
expected_with_empty_optionals = TimeData(
submitted_at=datetime(2022, 8, 29, 6, 33, 24, 913138, tzinfo=tzutc()),
expires_at=datetime(1970, 1, 1, 0, 0, tzinfo=tzutc()),
expires_at=None,
execution_started_at=datetime(
2022, 8, 29, 6, 33, 24, 916543, tzinfo=tzutc()
),
execution_ended_at=None,
)
self.assertEqual(
expected_without_end, TimeData.from_dict(self.status_response_data)
expected_with_empty_optionals, TimeData.from_dict(self.status_response_data)
)

def test_parse_status_response(self):
Expand Down

0 comments on commit 20a6dd2

Please sign in to comment.