Skip to content

Commit 73eecdb

Browse files
Migrate tests from docker compose
1 parent 34bc243 commit 73eecdb

File tree

8 files changed

+31
-146
lines changed

8 files changed

+31
-146
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on: [push]
55
jobs:
66
static-checks:
77
runs-on: ubuntu-latest
8-
strategy: &python-matrix
8+
strategy:
99
matrix:
1010
python-version:
1111
- "3.11"
@@ -38,21 +38,10 @@ jobs:
3838

3939
- name: Type check
4040
run: uv run pyright
41+
42+
- name: Type check
43+
run: uv run pytest
44+
env:
45+
FISHJAM_ID: ${{ secrets.CI_FISHJAM_ID }}
46+
FISHJAM_MANAGEMENT_TOKEN: ${{ secrets.CI_FISHJAM_MANAGEMENT_TOKEN }}
4147

42-
test:
43-
runs-on: ubuntu-latest
44-
strategy: *python-matrix
45-
env:
46-
PYTHON_VERSION: ${{ matrix.python-version }}
47-
name: test
48-
steps:
49-
- uses: actions/checkout@v4
50-
51-
- name: Log in to GitHub Container Registry
52-
run: echo "${{ secrets.PACKAGE_ACCESS_TOKEN }}" | docker login ghcr.io -u USERNAME --password-stdin
53-
54-
- name: Run tests
55-
run: docker compose -f docker-compose-test.yaml up test --exit-code-from test
56-
57-
- name: Tear down test containers
58-
run: docker compose -f docker-compose-test.yaml down

docker-compose-test.yaml

Lines changed: 0 additions & 75 deletions
This file was deleted.

tests/Dockerfile

Lines changed: 0 additions & 23 deletions
This file was deleted.

tests/agent/test_agent.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import asyncio
2-
import os
32
from contextlib import suppress
43

54
import pytest
@@ -14,15 +13,12 @@
1413
ServerMessagePeerMetadataUpdated,
1514
)
1615
from fishjam.events.allowed_notifications import AllowedNotification
17-
18-
HOST = "proxy" if os.getenv("DOCKER_TEST") == "TRUE" else "localhost"
19-
FISHJAM_ID = f"http://{HOST}:5555"
20-
SERVER_API_TOKEN = os.getenv("MANAGEMENT_TOKEN", "development")
16+
from tests.support.env import FISHJAM_ID, FISHJAM_MANAGEMENT_TOKEN
2117

2218

2319
@pytest.fixture
2420
def room_api():
25-
return FishjamClient(FISHJAM_ID, SERVER_API_TOKEN)
21+
return FishjamClient(FISHJAM_ID, FISHJAM_MANAGEMENT_TOKEN)
2622

2723

2824
@pytest.fixture
@@ -43,7 +39,7 @@ def agent(room: Room, room_api: FishjamClient):
4339
async def notifier():
4440
notifier = FishjamNotifier(
4541
fishjam_id=FISHJAM_ID,
46-
management_token=SERVER_API_TOKEN,
42+
management_token=FISHJAM_MANAGEMENT_TOKEN,
4743
)
4844

4945
@notifier.on_server_notification

tests/support/env.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import os
2+
3+
FISHJAM_ID = os.environ["FISHJAM_ID"]
4+
FISHJAM_MANAGEMENT_TOKEN = os.environ["FISHJAM_MANAGEMENT_TOKEN"]

tests/support/webhook_notifier.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,7 @@ def run_server(queue):
2626
global DATA_QUEUE
2727
DATA_QUEUE = queue
2828
app.run(port=5000, host="0.0.0.0", use_reloader=False, debug=False, threaded=True)
29+
30+
31+
WEBHOOK_SERVER_URL = "http://localhost:5000/"
32+
WEBHOOK_URL = f"{WEBHOOK_SERVER_URL}webhook"

tests/test_notifier.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# pylint: disable=locally-disabled, missing-class-docstring, missing-function-docstring, redefined-outer-name, too-few-public-methods, missing-module-docstring
22

33
import asyncio
4-
import os
54
import socket
65
import time
76
from multiprocessing import Process, Queue
@@ -20,15 +19,10 @@
2019
ServerMessageRoomDeleted,
2120
)
2221
from tests.support.asyncio_utils import assert_events, cancel
22+
from tests.support.env import FISHJAM_ID, FISHJAM_MANAGEMENT_TOKEN
2323
from tests.support.peer_socket import PeerSocket
24-
from tests.support.webhook_notifier import run_server
25-
26-
FISHJAM_HOST = "proxy" if os.getenv("DOCKER_TEST") == "TRUE" else "localhost"
27-
FISHJAM_URL = f"http://{FISHJAM_HOST}:5555"
28-
FISHJAM_ID = FISHJAM_URL
29-
SERVER_API_TOKEN = os.getenv("MANAGEMENT_TOKEN", "development")
30-
WEBHOOK_ADDRESS = "test" if os.getenv("DOCKER_TEST") == "TRUE" else "localhost"
31-
WEBHOOK_URL = f"http://{WEBHOOK_ADDRESS}:5000/webhook"
24+
from tests.support.webhook_notifier import WEBHOOK_SERVER_URL, WEBHOOK_URL, run_server
25+
3226
queue = Queue()
3327

3428

@@ -40,7 +34,7 @@ def start_server():
4034
timeout = 60 # wait maximum of 60 seconds
4135
while True:
4236
try:
43-
response = requests.get(f"http://{WEBHOOK_ADDRESS}:5000/", timeout=1_000)
37+
response = requests.get(WEBHOOK_SERVER_URL, timeout=1_000)
4438
if response.status_code == 200: # Or another condition
4539
break
4640
except (requests.ConnectionError, socket.error):
@@ -59,7 +53,7 @@ class TestConnectingToServer:
5953
async def test_valid_credentials(self):
6054
notifier = FishjamNotifier(
6155
fishjam_id=FISHJAM_ID,
62-
management_token=SERVER_API_TOKEN,
56+
management_token=FISHJAM_MANAGEMENT_TOKEN,
6357
)
6458

6559
@notifier.on_server_notification
@@ -77,14 +71,14 @@ def handle_notitifcation(_notification):
7771

7872
@pytest.fixture
7973
def room_api():
80-
return FishjamClient(FISHJAM_ID, SERVER_API_TOKEN)
74+
return FishjamClient(FISHJAM_ID, FISHJAM_MANAGEMENT_TOKEN)
8175

8276

8377
@pytest.fixture
8478
def notifier():
8579
notifier = FishjamNotifier(
8680
fishjam_id=FISHJAM_ID,
87-
management_token=SERVER_API_TOKEN,
81+
management_token=FISHJAM_MANAGEMENT_TOKEN,
8882
)
8983

9084
return notifier
@@ -133,7 +127,7 @@ async def test_peer_connected_disconnected(
133127
room = room_api.create_room(options=options)
134128

135129
peer, token = room_api.create_peer(room.id)
136-
peer_socket = PeerSocket(fishjam_url=FISHJAM_URL)
130+
peer_socket = PeerSocket(fishjam_url=FISHJAM_ID)
137131
peer_task = asyncio.create_task(peer_socket.connect(token))
138132

139133
await peer_socket.wait_ready()
@@ -168,7 +162,7 @@ async def test_peer_connected_room_deleted(
168162
room = room_api.create_room(options=options)
169163
_peer, token = room_api.create_peer(room.id)
170164

171-
peer_socket = PeerSocket(fishjam_url=FISHJAM_URL)
165+
peer_socket = PeerSocket(fishjam_url=FISHJAM_ID)
172166
peer_task = asyncio.create_task(peer_socket.connect(token))
173167

174168
await peer_socket.wait_ready()

tests/test_room_api.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import os
21
from unittest.mock import Mock, patch
32

43
import httpx
@@ -29,10 +28,7 @@
2928
VideoCodec,
3029
)
3130
from fishjam.version import get_version
32-
33-
HOST = "proxy" if os.getenv("DOCKER_TEST") == "TRUE" else "localhost"
34-
FISHJAM_ID = f"http://{HOST}:5555"
35-
MANAGEMENT_TOKEN = os.getenv("MANAGEMENT_TOKEN", "development")
31+
from tests.support.env import FISHJAM_ID, FISHJAM_MANAGEMENT_TOKEN
3632

3733
MAX_PEERS = 10
3834
CODEC_H264 = "h264"
@@ -49,7 +45,7 @@ def test_invalid_token(self):
4945
room_api.create_room()
5046

5147
def test_valid_token(self):
52-
room_api = FishjamClient(FISHJAM_ID, MANAGEMENT_TOKEN)
48+
room_api = FishjamClient(FISHJAM_ID, FISHJAM_MANAGEMENT_TOKEN)
5349

5450
room = room_api.create_room()
5551
all_rooms = room_api.get_all_rooms()
@@ -71,7 +67,7 @@ def mock_send(request, **kwargs):
7167
captured_headers = dict(request.headers)
7268
return mock_response
7369

74-
room_api = FishjamClient(FISHJAM_ID, MANAGEMENT_TOKEN)
70+
room_api = FishjamClient(FISHJAM_ID, FISHJAM_MANAGEMENT_TOKEN)
7571

7672
with patch.object(httpx.HTTPTransport, "handle_request", side_effect=mock_send):
7773
try:
@@ -89,7 +85,7 @@ def mock_send(request, **kwargs):
8985

9086
@pytest.fixture
9187
def room_api():
92-
return FishjamClient(FISHJAM_ID, MANAGEMENT_TOKEN)
88+
return FishjamClient(FISHJAM_ID, FISHJAM_MANAGEMENT_TOKEN)
9389

9490

9591
class TestCreateRoom:

0 commit comments

Comments
 (0)