-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
106 additions
and
15 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
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,42 @@ | ||
import asyncio | ||
|
||
import pytest | ||
|
||
from rabbit.background_tasks import BackgroundTasks | ||
from rabbit.job import async_echo_job | ||
|
||
|
||
@pytest.fixture | ||
def background_tasks(): | ||
return BackgroundTasks() | ||
|
||
|
||
async def test_background_tasks_add(background_tasks): | ||
background_tasks.add("test-task", async_echo_job, b'{"message": "test"}') | ||
assert len(background_tasks) == 1 | ||
|
||
|
||
async def test_background_tasks_multiple_add(background_tasks): | ||
background_tasks.add("test-task-1", async_echo_job, b'{"message": "test"}') | ||
background_tasks.add("test-task-1", async_echo_job, b'{"message": "test"}') | ||
background_tasks.add("test-task-2", async_echo_job, b'{"message": "test2"}') | ||
assert len(background_tasks) == 2 | ||
|
||
|
||
async def test_background_tasks_by_name(background_tasks): | ||
background_tasks.add("test-task", async_echo_job, b'{"message": "test"}') | ||
for task in background_tasks: | ||
assert task.get_name() == "test-task" | ||
|
||
|
||
async def test_background_tasks_getitem(background_tasks): | ||
background_tasks.add("test-task", async_echo_job, b'{"message": "test"}') | ||
assert isinstance(background_tasks["test-task"], asyncio.Task) | ||
|
||
|
||
def test_background_tasks_len(background_tasks): | ||
assert len(background_tasks) == 0 | ||
|
||
|
||
def test_background_tasks_repr(background_tasks): | ||
assert repr(background_tasks) == "BackgroundTasks(tasks=0, tasks_by_name=[])" |
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,14 @@ | ||
from rabbit.exceptions import ClientNotConnectedError, ExchangeNotFound | ||
|
||
|
||
def test_exchange_not_found_message(): | ||
assert ( | ||
str(ExchangeNotFound("test-exchange")) == "Exchange 'test-exchange' not found" | ||
) | ||
|
||
|
||
def test_client_not_connected_error(): | ||
assert ( | ||
str(ClientNotConnectedError()) | ||
== "AioRabbitClient was not connected with RabbitMQ" | ||
) |
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 |
---|---|---|
@@ -1,6 +1,14 @@ | ||
from rabbit.job import async_echo_job | ||
import pytest | ||
|
||
from rabbit.job import async_chaos_job, async_echo_job | ||
|
||
|
||
async def test_async_echo_job(): | ||
resp = await async_echo_job(b'{"process": 123}', skip_wait=True) | ||
assert resp == b'{"process": 123}' | ||
|
||
|
||
@pytest.mark.xfail(reason="The test may fail due to randomness issue") | ||
async def test_async_chaos_job(): | ||
resp = await async_chaos_job(b'{"process": 123}', skip_wait=True) | ||
assert resp == b'{"process": 123}' |
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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import attr | ||
import pytest | ||
|
||
|
||
def test_attributes(queue): | ||
values = ["queue", True, {}] | ||
for value in values: | ||
assert value in attr.asdict(queue).values() | ||
@pytest.mark.parametrize("attribute", ["name", "durable", "arguments"]) | ||
def test_attributes(queue, attribute): | ||
assert hasattr(queue, attribute) |
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