Skip to content

Commit ef87577

Browse files
Tanishq STanishq S
authored andcommitted
test: add unit tests for task_repository
1 parent f1e6ed9 commit ef87577

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
import pytest
3+
from oasst_backend.task_repository import validate_frontend_message_id
4+
from oasst_shared.exceptions.oasst_api_error import OasstError, OasstErrorCode
5+
6+
def test_validate_frontend_message_id_valid():
7+
"""Test that a valid string ID passes validation."""
8+
validate_frontend_message_id("valid-id-123")
9+
10+
def test_validate_frontend_message_id_empty():
11+
"""Test that an empty string raises an error."""
12+
with pytest.raises(OasstError) as excinfo:
13+
validate_frontend_message_id("")
14+
15+
assert excinfo.value.error_code == OasstErrorCode.INVALID_FRONTEND_MESSAGE_ID
16+
assert "message_id must not be empty" in str(excinfo.value)
17+
18+
def test_validate_frontend_message_id_none():
19+
"""Test that None raises an error."""
20+
with pytest.raises(OasstError) as excinfo:
21+
validate_frontend_message_id(None)
22+
23+
assert excinfo.value.error_code == OasstErrorCode.INVALID_FRONTEND_MESSAGE_ID
24+
assert "message_id must be string" in str(excinfo.value)
25+
26+
def test_validate_frontend_message_id_wrong_type():
27+
"""Test that a non-string type raises an error."""
28+
with pytest.raises(OasstError) as excinfo:
29+
validate_frontend_message_id(12345)
30+
31+
assert excinfo.value.error_code == OasstErrorCode.INVALID_FRONTEND_MESSAGE_ID
32+
assert "message_id must be string" in str(excinfo.value)

0 commit comments

Comments
 (0)