From f14ef50cd2c70d928769fe580cc8d5b76b4c478a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Ca=C3=B1uelo?= Date: Fri, 1 Dec 2023 09:52:40 +0100 Subject: [PATCH] tests: update unit and e2e tests, sync to latest pubsub changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ricardo CaƱuelo --- tests/e2e_tests/test_subscribe_handler.py | 6 +++--- tests/unit_tests/conftest.py | 6 ++++-- tests/unit_tests/test_pubsub.py | 4 ++-- tests/unit_tests/test_subscribe_handler.py | 4 ++-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/tests/e2e_tests/test_subscribe_handler.py b/tests/e2e_tests/test_subscribe_handler.py index 6f27d21bb..4413179ff 100644 --- a/tests/e2e_tests/test_subscribe_handler.py +++ b/tests/e2e_tests/test_subscribe_handler.py @@ -28,7 +28,7 @@ def test_subscribe_node_channel(test_client): ) pytest.node_channel_subscription_id = response.json()['id'] assert response.status_code == 200 - assert ('id', 'channel') == tuple(response.json().keys()) + assert ('id', 'channel', 'user') == tuple(response.json().keys()) assert response.json().get('channel') == 'node' @@ -51,7 +51,7 @@ def test_subscribe_test_channel(test_client): ) pytest.test_channel_subscription_id = response.json()['id'] assert response.status_code == 200 - assert ('id', 'channel') == tuple(response.json().keys()) + assert ('id', 'channel', 'user') == tuple(response.json().keys()) assert response.json().get('channel') == 'test_channel' @@ -75,5 +75,5 @@ def test_subscribe_user_group_channel(test_client): ) pytest.user_group_channel_subscription_id = response.json()['id'] assert response.status_code == 200 - assert ('id', 'channel') == tuple(response.json().keys()) + assert ('id', 'channel', 'user') == tuple(response.json().keys()) assert response.json().get('channel') == 'user_group' diff --git a/tests/unit_tests/conftest.py b/tests/unit_tests/conftest.py index 7b2e5690c..7a97ec2dd 100644 --- a/tests/unit_tests/conftest.py +++ b/tests/unit_tests/conftest.py @@ -28,7 +28,7 @@ ) from api.models import UserGroup from api.user_models import User -from api.pubsub import PubSub +from api.pubsub import PubSub, Subscription BEARER_TOKEN = "Bearer \ eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJib2IifQ.\ @@ -223,8 +223,10 @@ def mock_pubsub_subscriptions(mocker): """Mocks `_redis` and `_subscriptions` member of PubSub class instance""" pubsub = PubSub() redis_mock = fakeredis.aioredis.FakeRedis() + sub = Subscription(id=1, channel='test', user='test') mocker.patch.object(pubsub, '_redis', redis_mock) - subscriptions_mock = dict({1: pubsub._redis.pubsub()}) + subscriptions_mock = dict( + {1: {'sub': sub, 'redis_sub': pubsub._redis.pubsub()}}) mocker.patch.object(pubsub, '_subscriptions', subscriptions_mock) return pubsub diff --git a/tests/unit_tests/test_pubsub.py b/tests/unit_tests/test_pubsub.py index 90ce03e5a..481a95b57 100644 --- a/tests/unit_tests/test_pubsub.py +++ b/tests/unit_tests/test_pubsub.py @@ -23,7 +23,7 @@ async def test_subscribe_single_channel(mock_pubsub): PubSub._subscriptions dict should have one entry. This entry's key should be equal 1. """ - result = await mock_pubsub.subscribe('CHANNEL') + result = await mock_pubsub.subscribe('CHANNEL', 'test') assert result.channel == 'CHANNEL' assert result.id == 1 assert len(mock_pubsub._subscriptions) == 1 @@ -48,7 +48,7 @@ async def test_subscribe_multiple_channels(mock_pubsub): await mock_pubsub._redis.set(mock_pubsub.ID_KEY, 0) channels = ((1, 'CHANNEL1'), (2, 'CHANNEL2'), (3, 'CHANNEL3')) for expected_id, expected_channel in channels: - result = await mock_pubsub.subscribe(expected_channel) + result = await mock_pubsub.subscribe(expected_channel, 'test') assert result.channel == expected_channel assert result.id == expected_id assert len(mock_pubsub._subscriptions) == 3 diff --git a/tests/unit_tests/test_subscribe_handler.py b/tests/unit_tests/test_subscribe_handler.py index 555cea8a2..aaf2614da 100644 --- a/tests/unit_tests/test_subscribe_handler.py +++ b/tests/unit_tests/test_subscribe_handler.py @@ -18,7 +18,7 @@ def test_subscribe_endpoint(mock_subscribe, test_client): HTTP Response Code 200 OK JSON with 'id' and 'channel' keys """ - subscribe = Subscription(id=1, channel='abc') + subscribe = Subscription(id=1, channel='abc', user='test') mock_subscribe.return_value = subscribe response = test_client.post( @@ -29,4 +29,4 @@ def test_subscribe_endpoint(mock_subscribe, test_client): ) print("response.json()", response.json()) assert response.status_code == 200 - assert ('id', 'channel') == tuple(response.json().keys()) + assert ('id', 'channel', 'user') == tuple(response.json().keys())