Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add file component #24

Merged
merged 6 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ You can test the SDK by running
poetry run ci_test
```

In local development you can use
```
poetry run pytest -m "not file_component_sources"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should create a poetry script for that something like test.local or something like that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do

```

## Format & Lint
You can format code by running
```console
Expand Down
2 changes: 2 additions & 0 deletions docker-compose-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ services:
- "5002:5002"
- "49999:49999"
- "50000-50050:50000-50050/udp"
volumes:
- ./tests/fixtures:/app/jellyfish_resources/file_component_sources

test:
container_name: test
Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,8 @@ ignore = []

[tool.ruff.extend-per-file-ignores]
"jellyfish/_openapi_client/**" = ["E501"]

[tool.pytest.ini_options]
markers = [
"file_component_sources: Tests requiring files uploaded for File Component"
]
Binary file added tests/fixtures/audio.ogg
Binary file not shown.
Binary file added tests/fixtures/video.h264
Binary file not shown.
92 changes: 45 additions & 47 deletions tests/test_room_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import os
import uuid
from dataclasses import dataclass

import pytest

Expand Down Expand Up @@ -41,10 +42,28 @@
CODEC_H264 = "h264"

HLS_OPTIONS = ComponentOptionsHLS()
HLS_PROPERTIES = ComponentPropertiesHLS(
low_latency=False,
persistent=False,
playable=False,
subscribe_mode=ComponentPropertiesHLSSubscribeMode("auto"),
target_window_duration=None,
)
HLS_PROPERTIES.additional_properties = {"s3": None}

RTSP_OPTIONS = ComponentOptionsRTSP(
source_uri="rtsp://ef36c6dff23ecc5bbe311cc880d95dc8.se:2137/does/not/matter"
)
RTSP_PROPERTIES = ComponentPropertiesRTSP(
source_uri=RTSP_OPTIONS.source_uri,
keep_alive_interval=15000,
reconnect_delay=15000,
rtp_port=20000,
pierce_nat=True,
)

FILE_OPTIONS = ComponentOptionsFile(file_path="video.h264")
FILE_PROPERTIES = ComponentPropertiesFile(file_path=FILE_OPTIONS.file_path)


class TestAuthentication:
Expand Down Expand Up @@ -192,70 +211,49 @@ def test_invalid(self, room_api: RoomApi):
room_api.get_room("invalid_id")


class TestAddComponent:
def test_with_options_hls(self, room_api: RoomApi):
_, room = room_api.create_room(video_codec=CODEC_H264)
@dataclass
class ComponentTestData:
component: any
type: str
options: any
properties: any

response = room_api.add_component(room.id, options=HLS_OPTIONS)

component = room_api.get_room(room.id).components[0]
class TestAddComponent:
def test_with_options_hls(self, room_api):
data = ComponentTestData(ComponentHLS, "hls", HLS_OPTIONS, HLS_PROPERTIES)
self._test_component(room_api, data)

properties = ComponentPropertiesHLS(
low_latency=False,
persistent=False,
playable=False,
subscribe_mode=ComponentPropertiesHLSSubscribeMode("auto"),
target_window_duration=None,
)
properties.additional_properties = {"s3": None}
component_hls = ComponentHLS(id=component.id, type="hls", properties=properties)
def test_with_options_rtsp(self, room_api):
data = ComponentTestData(ComponentRTSP, "rtsp", RTSP_OPTIONS, RTSP_PROPERTIES)
self._test_component(room_api, data)

assert response == component_hls
assert component == component_hls
@pytest.mark.file_component_sources
def test_with_options_file(self, room_api):
data = ComponentTestData(ComponentFile, "file", FILE_OPTIONS, FILE_PROPERTIES)
self._test_component(room_api, data)

def test_with_options_rtsp(self, room_api: RoomApi):
def test_invalid_type(self, room_api: RoomApi):
_, room = room_api.create_room(video_codec=CODEC_H264)

response = room_api.add_component(room.id, options=RTSP_OPTIONS)
component = room_api.get_room(room.id).components[0]

component_rtsp = ComponentRTSP(
id=component.id,
type="rtsp",
properties=ComponentPropertiesRTSP(
source_uri=RTSP_OPTIONS.source_uri,
keep_alive_interval=RTSP_OPTIONS.keep_alive_interval,
reconnect_delay=RTSP_OPTIONS.reconnect_delay,
rtp_port=RTSP_OPTIONS.rtp_port,
pierce_nat=RTSP_OPTIONS.pierce_nat,
),
)

assert response == component_rtsp
assert component == component_rtsp

def test_with_options_file(self, room_api: RoomApi):
_, room = room_api.create_room()
with pytest.raises(ValueError):
room_api.add_component(room.id, options=PeerOptionsWebRTC())

response = room_api.add_component(room.id, options=FILE_OPTIONS)
def _test_component(self, room_api: RoomApi, test_data: ComponentTestData):
_, room = room_api.create_room(video_codec=CODEC_H264)

response = room_api.add_component(room.id, options=test_data.options)
component = room_api.get_room(room.id).components[0]

component_file = ComponentFile(
component_file = test_data.component(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be renamed?

id=component.id,
type="file",
properties=ComponentPropertiesFile(file_path=FILE_OPTIONS.file_path),
type=test_data.type,
properties=test_data.properties,
)

assert response == component_file
assert component == component_file

def test_invalid_type(self, room_api: RoomApi):
_, room = room_api.create_room(video_codec=CODEC_H264)

with pytest.raises(ValueError):
room_api.add_component(room.id, options=PeerOptionsWebRTC())


class TestDeleteComponent:
def test_valid_component(self, room_api: RoomApi):
Expand Down