Skip to content

Commit

Permalink
tests: update unit and e2e tests, sync to latest pubsub changes
Browse files Browse the repository at this point in the history
Signed-off-by: Ricardo Cañuelo <[email protected]>
  • Loading branch information
Ricardo Cañuelo committed Dec 13, 2023
1 parent cff871a commit 0fcdfd2
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
6 changes: 3 additions & 3 deletions tests/e2e_tests/test_subscribe_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'


Expand All @@ -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'


Expand All @@ -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'
6 changes: 4 additions & 2 deletions tests/unit_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.\
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/test_pubsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/test_subscribe_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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())

0 comments on commit 0fcdfd2

Please sign in to comment.