Skip to content

Commit

Permalink
Add integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
1-alex98 committed Sep 27, 2022
1 parent 796413d commit 6bb54ed
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/integration_tests/test_message_queue_service.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import asyncio
import json
from unittest import mock

import aio_pika
import pytest
from aio_pika.abc import AbstractIncomingMessage

from server.config import config
from server.decorators import with_logger
Expand Down Expand Up @@ -175,3 +177,21 @@ async def test_declaring_exchange_without_initialization(mq_uninit_service):
assert service._is_ready
assert service._connection is not None
assert service._exchanges.get(exchange_name) is not None


async def test_listening_to_incoming_messages(mq_service: MessageQueueService):
callback = Callback()
await mq_service.listen_to_message("test", "routing.test", callback.callback_listening)
await mq_service.declare_exchange(config.MQ_EXCHANGE_NAME)
await mq_service.publish(config.MQ_EXCHANGE_NAME, "routing.test", {"test": "test"})
await callback.called_future


class Callback:

def __init__(self) -> None:
self.called_future = asyncio.Future()

def callback_listening(self, message: AbstractIncomingMessage):
assert json.loads(message.body)["test"] == "test"
self.called_future.set_result(None)
46 changes: 46 additions & 0 deletions tests/integration_tests/test_tournament_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import pytest

from server import TournamentService
from server.config import config
from server.message_queue_service import MessageQueueService
from tests.integration_tests.conftest import (
connect_and_sign_in,
read_until_command
)

pytestmark = pytest.mark.rabbitmq


async def test_create_game_by_message(message_queue_service: MessageQueueService,
tournament_service: TournamentService, lobby_server):
_, _, proto1 = await connect_and_sign_in(
("test", "test_password"), lobby_server
)
await message_queue_service.declare_exchange(config.MQ_EXCHANGE_NAME)
await message_queue_service.publish(config.MQ_EXCHANGE_NAME, "request.match.create",
{
"request_id": "9124e8c9-c62f-43c3-bb64-94f3093f2997",
"game_name": "My game name",
"participants": [
{
"team": 1,
"slot": 1,
"faction": 1,
"player_id": 1
}
],
"featured_mod": "faf",
"map_name": "SCMP_001",
"game_options": {
"test": "test"
}
}, correlation_id="9124e8c9-c62f-43c3-bb64-94f3093f2997"
)
msg = await read_until_command(proto1, "is_ready")
assert msg == {
'command': 'is_ready',
'featured_mod': 'faf',
'game_name': 'My game name',
'request_id': '9124e8c9-c62f-43c3-bb64-94f3093f2997',
'response_time_seconds': 30
}

0 comments on commit 6bb54ed

Please sign in to comment.