Skip to content

Commit 31ff7bb

Browse files
committed
Fixed tests.
1 parent 80a561c commit 31ff7bb

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

taskiq_nats/result_backend.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Any, Final, List, Optional, TypeVar, Union
22

33
import nats
4-
from nats import NATS
4+
from nats.aio.client import Client
55
from nats.js import JetStreamContext
66
from nats.js.errors import BucketNotFoundError, ObjectNotFoundError
77
from nats.js.object_store import ObjectStore
@@ -37,7 +37,7 @@ def __init__(
3737
self.serializer = serializer or PickleSerializer()
3838
self.connect_options: Final = connect_options
3939

40-
self.nats_client: NATS
40+
self.nats_client: Client
4141
self.nats_jetstream: JetStreamContext
4242
self.object_store: ObjectStore
4343

tests/test_result_backend.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -111,43 +111,39 @@ async def test_success_backend_default_result(
111111
assert result == default_taskiq_result
112112

113113

114-
async def test_success_backend_custom_result(
114+
async def test_error_backend_custom_result(
115115
nats_result_backend: NATSObjectStoreResultBackend[_ReturnType],
116116
custom_taskiq_result: TaskiqResult[_ReturnType],
117117
task_id: str,
118118
) -> None:
119119
"""
120-
Tests normal behavior with custom result in TaskiqResult.
120+
Tests that error is thrown on non-serializable result.
121121
122122
:param custom_taskiq_result: TaskiqResult with custom result.
123123
:param task_id: ID for task.
124124
:param redis_url: url to redis.
125125
"""
126-
await nats_result_backend.set_result(
127-
task_id=task_id,
128-
result=custom_taskiq_result,
129-
)
130-
result = await nats_result_backend.get_result(task_id=task_id)
131-
132-
assert (
133-
result.return_value.test_arg # type: ignore
134-
== custom_taskiq_result.return_value.test_arg # type: ignore
135-
)
136-
assert result.is_err == custom_taskiq_result.is_err
137-
assert result.execution_time == custom_taskiq_result.execution_time
138-
assert result.log == custom_taskiq_result.log
126+
with pytest.raises(ValueError):
127+
await nats_result_backend.set_result(
128+
task_id=task_id,
129+
result=custom_taskiq_result,
130+
)
139131

140132

141133
async def test_success_backend_is_result_ready(
142134
nats_result_backend: NATSObjectStoreResultBackend[_ReturnType],
143-
custom_taskiq_result: TaskiqResult[_ReturnType],
144135
task_id: str,
145136
) -> None:
146137
"""Tests `is_result_ready` method."""
147138
assert not await nats_result_backend.is_result_ready(task_id=task_id)
148139
await nats_result_backend.set_result(
149140
task_id=task_id,
150-
result=custom_taskiq_result,
141+
result=TaskiqResult(
142+
is_err=False,
143+
log=None,
144+
return_value="one",
145+
execution_time=1,
146+
),
151147
)
152148

153149
assert await nats_result_backend.is_result_ready(task_id=task_id)

0 commit comments

Comments
 (0)