Skip to content

Commit

Permalink
fix(api): evidence is None case
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-schultz committed Nov 18, 2024
1 parent f667417 commit b93b787
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions api/v2/api/api_stamps.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,11 @@ def get_score_history(
score_data = extract_score_data(score_event.data)

# Get evidence data, defaulting to empty dict if not present
evidence = score_data.get("evidence", {})
evidence = score_data.get("evidence", {}) or {}
threshold = evidence.get("threshold", "0")

# Handle score extraction for both formats
if "evidence" in score_data and "rawScore" in score_data["evidence"]:
if "evidence" in score_data and "rawScore" in evidence:
score = score_data["evidence"]["rawScore"]
else:
score = score_data.get("score", "0")
Expand Down
30 changes: 30 additions & 0 deletions api/v2/test/test_historical_score_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,36 @@ def test_get_historical_score_missing_fields(
assert response_data["expiration_timestamp"] is None
assert response_data["stamp_scores"] is None

@freeze_time("2023-01-01")
def test_get_historical_score_ne_evidence(
self,
scorer_account,
scorer_api_key,
scorer_community_with_binary_scorer,
):
# Create score event with minimal data
Event.objects.create(
action=Event.Action.SCORE_UPDATE,
address=scorer_account.address,
community=scorer_community_with_binary_scorer,
data={"score": 78.762, "evidence": None},
)

client = Client()
response = client.get(
f"{self.base_url}/{scorer_community_with_binary_scorer.id}/score/{scorer_account.address}/history?created_at=2023-01-01",
HTTP_AUTHORIZATION="Token " + scorer_api_key,
)
response_data = response.json()

assert response.status_code == 200
assert response_data["score"] == "78.762"
assert response_data["threshold"] == "0"
assert response_data["passing_score"] is True
assert response_data["last_score_timestamp"] is None
assert response_data["expiration_timestamp"] is None
assert response_data["stamp_scores"] is None

def test_get_historical_score_no_score_found(
self,
scorer_account,
Expand Down

0 comments on commit b93b787

Please sign in to comment.