Skip to content

Commit 147df6d

Browse files
authored
Add tests for invalid API key and unknown action for LiveStatusConsumer (#236)
1 parent 1eb0a27 commit 147df6d

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

backend/frege/repositories/tests/test_consumers.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,35 @@ async def test_subscribe_to_repository_activity(self, api_key):
8989
response_action="repository/create",
9090
serializer=RepositorySerializer,
9191
)
92+
93+
async def test_invalid_api_key(self):
94+
communicator = WebsocketCommunicator(
95+
LiveStatusConsumer.as_asgi(), "/ws/test-live-status/"
96+
)
97+
try:
98+
connected, _ = await communicator.connect()
99+
assert connected
100+
await communicator.send_json_to(
101+
{"api_key": "invalid_key", "action": "subscribe_to_repository_activity", "request_id": 1}
102+
)
103+
response = await communicator.receive_json_from()
104+
assert response["response_status"] == 403
105+
assert await communicator.receive_nothing(), await communicator.show_queue()
106+
finally:
107+
await communicator.disconnect()
108+
109+
async def test_unknown_action(self, api_key):
110+
communicator = WebsocketCommunicator(
111+
LiveStatusConsumer.as_asgi(), "/ws/test-live-status/"
112+
)
113+
try:
114+
connected, _ = await communicator.connect()
115+
assert connected
116+
await communicator.send_json_to(
117+
{"api_key": api_key, "action": "non_existing_action", "request_id": 1}
118+
)
119+
response = await communicator.receive_json_from()
120+
assert response["response_status"] == 405
121+
assert await communicator.receive_nothing(), await communicator.show_queue()
122+
finally:
123+
await communicator.disconnect()

0 commit comments

Comments
 (0)