-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: store entire score object and return same score response as… (
#714) * refactor: store entire score object and return same score response as other endpoints * chore: remaining tests for updated historical endpoint * chore: test score serialization
- Loading branch information
1 parent
ad17dc2
commit db51bf8
Showing
5 changed files
with
297 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
|
||
from registry.models import serialize_score | ||
|
||
|
||
@pytest.mark.django_db | ||
class TestSerializeScore: | ||
def test_successful_serialization(self, scorer_score): | ||
"""Test successful serialization of a score object""" | ||
# Use the existing scorer_score fixture | ||
score = scorer_score | ||
|
||
# Serialize the score | ||
result = serialize_score(score) | ||
|
||
# Verify the structure and content | ||
assert isinstance(result, dict) | ||
assert "model" in result | ||
assert "fields" in result | ||
assert "error" not in result | ||
|
||
# Verify the model name | ||
assert ( | ||
result["model"] == "registry.score" | ||
) # adjust if your model is named differently | ||
|
||
# Verify key fields are present | ||
assert "status" in result["fields"] | ||
assert "passport" in result["fields"] | ||
|
||
@patch("django.core.serializers.serialize") | ||
def test_serialization_error(self, mock_serialize, scorer_score): | ||
"""Test handling of serialization errors""" | ||
# Use the existing scorer_score fixture | ||
score = scorer_score | ||
|
||
# Make serialize throw an exception | ||
mock_serialize.side_effect = Exception("Serialization failed") | ||
|
||
# Attempt to serialize | ||
result = serialize_score(score) | ||
|
||
# Verify error handling | ||
assert result == {"error": "Error serializing score"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.