Skip to content

Commit f4bd085

Browse files
committed
Make adjustments for test runner
1 parent 80671f7 commit f4bd085

File tree

11 files changed

+21
-43
lines changed

11 files changed

+21
-43
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ jobs:
6666
key: ${{ runner.os }}-venv-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/*requirements.txt') }}
6767

6868
- name: Run the tests
69+
env:
70+
BROKER_URL: amqp://guest:guest@rabbitmq:5672/
6971
run: |
7072
source .venv/bin/activate
7173
make test

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ lint:
2525
mypy
2626

2727
test:
28-
cd src && pytest -x
28+
cd src && pytest -x -m "not rabbitmq"
29+
cd src && pytest -x -m rabbitmq
2930
cd src && pytest --dead-fixtures

compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ services:
1212
TZ: UTC
1313
tty: true
1414
command: /bin/bash
15+
volumes:
16+
- ./:/repo

env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
DEBUG=False
22

33
BROKER_URL=amqp://guest:guest@localhost:5672/
4-
BROKER_EXCHANGE=guest-exchange
4+
BROKER_EXCHANGE=websocket-notifications-exchange
55
BROKER_QUEUE=websockets-notifications-queue
66
BROKER_ROUTING_KEYS_CONSUME_FROM=["test-event-boobs"]
77

src/app/conf/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
class Settings(BaseSettings):
1010
BROKER_URL: AmqpDsn
1111
BROKER_EXCHANGE: str
12-
BROKER_QUEUE: str
12+
BROKER_QUEUE: str | None
1313
BROKER_ROUTING_KEYS_CONSUME_FROM: list[str]
1414
WEBSOCKETS_HOST: str
1515
WEBSOCKETS_PORT: int

src/conftest.py

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,13 @@
11
import pytest
22

3-
from app.conf import Settings
3+
from app.conf import get_app_settings
44

55
pytest_plugins = [
66
"app.fixtures",
77
"storage.fixtures",
88
]
99

1010

11-
@pytest.fixture(autouse=True)
12-
def settings(mocker):
13-
mock = mocker.patch(
14-
"app.conf.get_app_settings",
15-
return_value=Settings(
16-
BROKER_URL="amqp://guest:guest@localhost/",
17-
BROKER_EXCHANGE="test-exchange",
18-
BROKER_QUEUE="test-queue",
19-
BROKER_ROUTING_KEYS_CONSUME_FROM=["test-routing-key", "ya-test-routing-key"],
20-
WEBSOCKETS_HOST="localhost",
21-
WEBSOCKETS_PORT=50000,
22-
WEBSOCKETS_PATH="/v2/test-subscription-websocket",
23-
AUTH_JWKS_URL="https://auth.test.com/auth/realms/test-realm/protocol/openid-connect/certs",
24-
AUTH_SUPPORTED_SIGNING_ALGORITHMS=["RS256"],
25-
),
26-
)
27-
28-
return mock.return_value
11+
@pytest.fixture
12+
def settings():
13+
return get_app_settings()

src/consumer/consumer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def __post_init__(self) -> None:
3030

3131
self.broker_url: str = str(settings.BROKER_URL)
3232
self.exchange: str = settings.BROKER_EXCHANGE
33-
self.queue: str = settings.BROKER_QUEUE
33+
self.queue: str | None = settings.BROKER_QUEUE
3434
self.routing_keys_consume_from: list[str] = settings.BROKER_ROUTING_KEYS_CONSUME_FROM
3535

3636
async def consume(self, stop_signal: asyncio.Future) -> None:

src/consumer/tests/conftest.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,7 @@
88

99
@pytest.fixture(autouse=True)
1010
def _adjust_settings(settings):
11-
settings.BROKER_URL = "amqp://guest:guest@localhost/"
12-
settings.BROKER_EXCHANGE = "test-exchange"
13-
settings.BROKER_QUEUE = "test-queue"
14-
settings.BROKER_ROUTING_KEYS_CONSUME_FROM = [
15-
"event-routing-key",
16-
"ya-event-routing-key",
17-
]
11+
settings.BROKER_QUEUE = None # force consumer to create a queue with a random name
1812

1913

2014
@pytest.fixture

src/consumer/tests/tests_consumer.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import asyncio
22
import pytest
33

4+
pytestmark = [
5+
pytest.mark.rabbitmq,
6+
]
7+
48

59
@pytest.fixture
610
def run_consume_task(consumer):
@@ -10,16 +14,6 @@ def run(stop_signal: asyncio.Future):
1014
return run
1115

1216

13-
def test_consumer_attributes(consumer):
14-
assert consumer.broker_url == "amqp://guest:guest@localhost/"
15-
assert consumer.exchange == "test-exchange"
16-
assert consumer.queue == "test-queue"
17-
assert consumer.routing_keys_consume_from == [
18-
"event-routing-key",
19-
"ya-event-routing-key",
20-
]
21-
22-
2317
async def test_consumer_correctly_stopped_on_stop_signal(run_consume_task):
2418
stop_signal = asyncio.get_running_loop().create_future()
2519
consumer_task = run_consume_task(stop_signal)

src/tests/functional/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def force_token_validation(mocker, valid_token):
1717

1818
@pytest.fixture(autouse=True)
1919
def _adjust_settings(settings, unused_tcp_port):
20+
settings.BROKER_QUEUE = None # force consumer to create a queue with a random name
2021
settings.WEBSOCKETS_HOST = "0.0.0.0"
2122
settings.WEBSOCKETS_PORT = unused_tcp_port
2223

@@ -54,11 +55,10 @@ async def serve_app_runner(settings, websockets_handler, access_guardian, consum
5455
)
5556

5657
await asyncio.sleep(0.1) # give enough time to start the server
57-
assert serve_task.done() is False # be sure server is running
58+
assert serve_task.done() is False, "It's looks like app runner couldn't be started. Check the settings carefully."
5859
yield serve_task
5960

6061
stop_signal.set_result(None)
61-
await asyncio.sleep(0.2) # give enough time to stop the server; it's required to free all the consumed resources
6262

6363

6464
@pytest.fixture

src/tests/functional/tests_remove_registered_on_token_expiration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import pytest
33

44
pytestmark = [
5-
pytest.mark.slow,
5+
pytest.mark.rabbitmq,
66
]
77

88

0 commit comments

Comments
 (0)