-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Adds tests for formatter and decorator
1 parent
a6a426c
commit 8d7055d
Showing
3 changed files
with
57 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import uuid | ||
|
||
from django_ai_assistant.decorators import with_cast_id | ||
from django_ai_assistant.helpers.formatters import cast_id | ||
from django_ai_assistant.models import Thread | ||
|
||
|
||
def test_cast_id_does_not_transform_regular_ids(): | ||
assert isinstance(cast_id(1, Thread), int) | ||
|
||
|
||
def test_cast_id_does_not_transform_str_ids(): | ||
assert isinstance(cast_id("dfjsdjfkndskjf", Thread), str) | ||
|
||
|
||
def test_cast_id_transforms_uuids(monkeypatch): | ||
def mock_get_internal_type(): | ||
return "UUIDField" | ||
|
||
monkeypatch.setattr(Thread._meta.pk, "get_internal_type", mock_get_internal_type) | ||
|
||
assert isinstance(cast_id("c8e6d7f7-7b2e-4d3b-8b9d-5b1d4b1f3e6b", Thread), uuid.UUID) | ||
|
||
|
||
def test_with_cast_id_transforms_regular_ids(): | ||
@with_cast_id | ||
def dummy_function(thread_id): | ||
return thread_id | ||
|
||
assert isinstance(dummy_function(thread_id=1), int) | ||
|
||
|
||
def test_with_cast_id_transforms_str_ids(): | ||
@with_cast_id | ||
def dummy_function(thread_id): | ||
return thread_id | ||
|
||
assert isinstance(dummy_function(thread_id="dfjsdjfkndskjf"), str) | ||
|
||
|
||
def test_with_cast_id_transforms_uuids(monkeypatch): | ||
def mock_get_internal_type(): | ||
return "UUIDField" | ||
|
||
monkeypatch.setattr(Thread._meta.pk, "get_internal_type", mock_get_internal_type) | ||
|
||
@with_cast_id | ||
def dummy_function(thread_id): | ||
return thread_id | ||
|
||
assert isinstance(dummy_function(thread_id="c8e6d7f7-7b2e-4d3b-8b9d-5b1d4b1f3e6b"), uuid.UUID) |
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