diff --git a/python_apps/api_clients/api_clients/version2.py b/python_apps/api_clients/api_clients/version2.py index 4f86f5709..5ffb72048 100644 --- a/python_apps/api_clients/api_clients/version2.py +++ b/python_apps/api_clients/api_clients/version2.py @@ -59,7 +59,7 @@ class AirtimeApiClient: result = {"media": {}} for item in data: start = isoparse(item["starts"]) - key = start.strftime("%YYYY-%mm-%dd-%HH-%MM-%SS") + key = start.strftime("%Y-%m-%d-%H-%M-%S") end = isoparse(item["ends"]) show_instance = self.services.show_instance_url(id=item["instance_id"]) @@ -69,6 +69,7 @@ class AirtimeApiClient: "start": start.strftime("%Y-%m-%d-%H-%M-%S"), "end": end.strftime("%Y-%m-%d-%H-%M-%S"), "row_id": item["id"], + "show_name": show["name"], } current = result["media"][key] if item["file"]: @@ -90,6 +91,7 @@ class AirtimeApiClient: info = self.services.file_url(id=item["file_id"]) current["metadata"] = info current["uri"] = item["file"] + current["replay_gain"] = info["replay_gain"] current["filesize"] = info["filesize"] elif item["stream"]: current["independent_event"] = True diff --git a/python_apps/api_clients/setup.py b/python_apps/api_clients/setup.py index a04ada5e8..e8bb5ab75 100644 --- a/python_apps/api_clients/setup.py +++ b/python_apps/api_clients/setup.py @@ -22,6 +22,7 @@ setup( install_requires=[ "configobj", "python-dateutil>=2.7.0", + "requests", ], zip_safe=False, data_files=[], diff --git a/python_apps/api_clients/tests/version2_test.py b/python_apps/api_clients/tests/version2_test.py new file mode 100644 index 000000000..f822a7f4e --- /dev/null +++ b/python_apps/api_clients/tests/version2_test.py @@ -0,0 +1,108 @@ +import pytest +from api_clients.utils import RequestProvider +from api_clients.version2 import AirtimeApiClient, api_config + + +@pytest.fixture() +def config(): + return { + **api_config, + "general": { + "base_dir": "/test", + "base_port": 80, + "base_url": "localhost", + "api_key": "TEST_KEY", + }, + "api_base": "api", + } + + +class MockRequestProvider: + @staticmethod + def schedule_url(_post_data=None, params=None, **kwargs): + return [ + { + "id": 1, + "starts": "2021-07-05T11:00:00Z", + "ends": "2021-07-05T11:01:00.5000Z", + "instance_id": 2, + "file": "http://localhost/api/v2/file/3", + "file_id": 3, + "fade_in": "00:00:00.500000", + "fade_out": "00:00:01", + "cue_in": "00:00:00.142404", + "cue_out": "01:58:04.463583", + }, + ] + + @staticmethod + def show_instance_url(_post_data=None, params=None, **kwargs): + return { + "show_id": 4, + } + + @staticmethod + def show_url(_post_data=None, params=None, **kwargs): + return { + "name": "Test show", + } + + @staticmethod + def file_url(_post_data=None, params=None, **kwargs): + return { + "item_url": "http://localhost/api/v2/files/3/", + "name": "", + "mime": "audio/mp3", + "ftype": "audioclip", + "filepath": "imported/1/test.mp3", + "import_status": 0, + "currently_accessing": 0, + "mtime": "2021-07-01T23:13:43Z", + "utime": "2021-07-01T23:12:46Z", + "md5": "202ae33a642ce475bd8b265ddb11c139", + "track_title": "Test file.mp3", + "bit_rate": 320000, + "sample_rate": 44100, + "length": "01:58:04.463600", + "genre": "Test", + "channels": 2, + "file_exists": True, + "replay_gain": "-5.68", + "cuein": "00:00:00.142404", + "cueout": "01:58:04.463583", + "silan_check": False, + "hidden": False, + "is_scheduled": True, + "is_playlist": False, + "filesize": 283379568, + "track_type": "MUS", + "directory": "http://localhost/api/v2/music-dirs/1/", + "owner": "http://localhost/api/v2/users/1/", + } + + +def test_get_schedule(monkeypatch, config): + client = AirtimeApiClient(None, config) + client.services = MockRequestProvider() + schedule = client.get_schedule() + assert schedule == { + "media": { + "2021-07-05-11-00-00": { + "id": 3, + "type": "file", + "metadata": MockRequestProvider.file_url(), + "row_id": 1, + "uri": "http://localhost/api/v2/file/3", + "fade_in": 500.0, + "fade_out": 1000.0, + "cue_in": 0.142404, + "cue_out": 7084.463583, + "start": "2021-07-05-11-00-00", + "end": "2021-07-05-11-01-00", + "show_name": "Test show", + "replay_gain": "-5.68", + "independent_event": False, + "filesize": 283379568, + }, + }, + }