From 2cc3853f7554015a921e3263456a73809444af9e Mon Sep 17 00:00:00 2001 From: Fabio Ambauen <1833932+open-dynaMIX@users.noreply.github.com> Date: Tue, 7 Nov 2023 10:41:37 +0100 Subject: [PATCH 1/3] chore: dependency updates, snapshot updates, black, isort --- .github/workflows/tests.yml | 6 +++--- tests/requirements.txt | 22 +++++++++++----------- tests/snapshots/snap_tests.py | 2 ++ tests/tests.py | 2 +- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 5d0a74d..33eb1d5 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,7 +10,7 @@ jobs: tests: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build the webui container run: docker-compose -f docker-compose.yml build --pull working-directory: ./tests @@ -20,7 +20,7 @@ jobs: lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup Python uses: actions/setup-python@v4 with: @@ -36,7 +36,7 @@ jobs: commit-lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 - name: Setup Python diff --git a/tests/requirements.txt b/tests/requirements.txt index bbec53f..351899c 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -1,17 +1,17 @@ -black==22.12.0 -flake8==6.0.0 -flake8-bugbear==23.7.10 +black==23.10.1 +flake8==6.1.0 +flake8-bugbear==23.9.16 flake8-debugger==4.1.2 -flake8-isort==6.0.0 +flake8-isort==6.1.1 flake8-string-format==0.3.0 flake8-tuple==0.4.1 -gitlint==0.18.0 -ipython==8.12.0 +gitlint==0.19.1 +ipython==8.17.2 isort==5.12.0 pexpect==4.8.0 -pre-commit==3.3.3 -pytest==7.3.1 -pytest-randomly==3.12.0 -python-semantic-release==7.33.3 -requests==2.30.0 +pre-commit==3.5.0 +pytest==7.4.3 +pytest-randomly==3.15.0 +python-semantic-release==8.3.0 +requests==2.31.0 snapshottest==0.6.0 diff --git a/tests/snapshots/snap_tests.py b/tests/snapshots/snap_tests.py index 240f5cb..e6417ea 100644 --- a/tests/snapshots/snap_tests.py +++ b/tests/snapshots/snap_tests.py @@ -220,6 +220,7 @@ "filename": "./environment/test_media/01 - dummy.mp3", "id": 1, "playing": True, + "title": "First dummy", }, {"filename": "./environment/test_media/02 - dummy.mp3", "id": 2}, {"filename": "./environment/test_media/03 - dummy.mp3", "id": 3}, @@ -233,6 +234,7 @@ { "albumart": False, "audio-channels": 2, + "auto-forced-only": False, "codec": "mp3", "decoder-desc": "mp3float (MP3 (MPEG audio layer 3))", "default": False, diff --git a/tests/tests.py b/tests/tests.py index a60e8b2..c03900f 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -224,7 +224,7 @@ def test_speed(mpv_instance): ("speed_adjust", "0.9", 0.9), ("speed_set", "", 1), ) - for (endpoint, arg, value) in TESTS: + for endpoint, arg, value in TESTS: assert send(endpoint, arg=arg, status="speed") == value @staticmethod From a4ed3d9f8622baa299e7fd21f0944136e6b85dc9 Mon Sep 17 00:00:00 2001 From: Fabio Ambauen <1833932+open-dynaMIX@users.noreply.github.com> Date: Tue, 7 Nov 2023 11:03:56 +0100 Subject: [PATCH 2/3] chore: switch from spanshottest to syrupy --- tests/__snapshots__/tests.ambr | 319 +++++++++++++++++++++++++++++++++ tests/requirements.txt | 2 +- tests/snapshots/__init__.py | 0 tests/snapshots/snap_tests.py | 261 --------------------------- 4 files changed, 320 insertions(+), 262 deletions(-) create mode 100644 tests/__snapshots__/tests.ambr delete mode 100644 tests/snapshots/__init__.py delete mode 100644 tests/snapshots/snap_tests.py diff --git a/tests/__snapshots__/tests.ambr b/tests/__snapshots__/tests.ambr new file mode 100644 index 0000000..2fa98c7 --- /dev/null +++ b/tests/__snapshots__/tests.ambr @@ -0,0 +1,319 @@ +# serializer version: 1 +# name: TestsRequests.test_collections[api/collections-200-mpv_instance0] + list([ + dict({ + 'is-directory': True, + 'path': '/app/scripts/simple-mpv-webui/tests/environment/collection', + }), + ]) +# --- +# name: TestsRequests.test_collections[api/collections/%2Fapp%2Fscripts%2Fsimple-mpv-webui%2Ftests%2Fenvironment%2Fcollection-200-mpv_instance0] + list([ + dict({ + 'is-directory': False, + 'path': "/app/scripts/simple-mpv-webui/tests/environment/collection/'file b'.log", + }), + dict({ + 'is-directory': True, + 'path': '/app/scripts/simple-mpv-webui/tests/environment/collection/A folder', + }), + dict({ + 'is-directory': False, + 'path': '/app/scripts/simple-mpv-webui/tests/environment/collection/file a.log', + }), + dict({ + 'is-directory': False, + 'path': ''' + /app/scripts/simple-mpv-webui/tests/environment/collection/line + break + ''', + }), + ]) +# --- +# name: TestsRequests.test_post_wrong_args[add-&-foo] + dict({ + 'message': 'Parameter name contains invalid characters', + }) +# --- +# name: TestsRequests.test_post_wrong_args[add-foo-&] + dict({ + 'message': 'Parameter needs to be an integer or float', + }) +# --- +# name: TestsRequests.test_post_wrong_args[add_audio_delay-&-None] + dict({ + 'message': 'Parameter needs to be an integer or float', + }) +# --- +# name: TestsRequests.test_post_wrong_args[add_chapter-&-None] + dict({ + 'message': 'Parameter needs to be an integer or float', + }) +# --- +# name: TestsRequests.test_post_wrong_args[add_sub_delay-&-None] + dict({ + 'message': 'Parameter needs to be an integer or float', + }) +# --- +# name: TestsRequests.test_post_wrong_args[add_volume-&-None] + dict({ + 'message': 'Parameter needs to be an integer or float', + }) +# --- +# name: TestsRequests.test_post_wrong_args[cycle-&-foo] + dict({ + 'message': 'Parameter name contains invalid characters', + }) +# --- +# name: TestsRequests.test_post_wrong_args[cycle-foo-&] + dict({ + 'message': 'Cycle paramater is not "up" or "down"', + }) +# --- +# name: TestsRequests.test_post_wrong_args[loadfile-None-None] + dict({ + 'message': 'No url provided!', + }) +# --- +# name: TestsRequests.test_post_wrong_args[loadfile-http://foo-invalid] + dict({ + 'message': "Invalid mode: 'foo'", + }) +# --- +# name: TestsRequests.test_post_wrong_args[loop_file-&-None] + dict({ + 'message': 'Invalid parameter!', + }) +# --- +# name: TestsRequests.test_post_wrong_args[loop_file-None-None] + dict({ + 'message': 'Invalid parameter!', + }) +# --- +# name: TestsRequests.test_post_wrong_args[loop_playlist-&-None] + dict({ + 'message': 'Invalid parameter!', + }) +# --- +# name: TestsRequests.test_post_wrong_args[multiply-&-23] + dict({ + 'message': 'Parameter name contains invalid characters', + }) +# --- +# name: TestsRequests.test_post_wrong_args[multiply-23-&] + dict({ + 'message': 'Parameter needs to be an integer or float', + }) +# --- +# name: TestsRequests.test_post_wrong_args[multiply-23-None] + dict({ + 'message': 'Parameter needs to be an integer or float', + }) +# --- +# name: TestsRequests.test_post_wrong_args[playlist_jump-&-None] + dict({ + 'message': 'Parameter needs to be an integer or float', + }) +# --- +# name: TestsRequests.test_post_wrong_args[playlist_jump-None-None] + dict({ + 'message': 'Parameter needs to be an integer or float', + }) +# --- +# name: TestsRequests.test_post_wrong_args[playlist_move-&-23] + dict({ + 'message': 'Parameter needs to be an integer or float', + }) +# --- +# name: TestsRequests.test_post_wrong_args[playlist_move-23-&] + dict({ + 'message': 'Parameter needs to be an integer or float', + }) +# --- +# name: TestsRequests.test_post_wrong_args[playlist_move-23-None] + dict({ + 'message': 'Parameter needs to be an integer or float', + }) +# --- +# name: TestsRequests.test_post_wrong_args[playlist_move_up-&-None] + dict({ + 'message': 'Parameter needs to be an integer or float', + }) +# --- +# name: TestsRequests.test_post_wrong_args[playlist_move_up-None-None] + dict({ + 'message': 'Parameter needs to be an integer or float', + }) +# --- +# name: TestsRequests.test_post_wrong_args[playlist_remove-&-None] + dict({ + 'message': 'Parameter needs to be an integer or float', + }) +# --- +# name: TestsRequests.test_post_wrong_args[playlist_remove-None-None] + dict({ + 'message': 'Parameter needs to be an integer or float', + }) +# --- +# name: TestsRequests.test_post_wrong_args[seek-None-None] + dict({ + 'message': 'Parameter needs to be an integer or float', + }) +# --- +# name: TestsRequests.test_post_wrong_args[seek-g-None] + dict({ + 'message': 'Parameter needs to be an integer or float', + }) +# --- +# name: TestsRequests.test_post_wrong_args[set-&-foo] + dict({ + 'message': 'Parameter name contains invalid characters', + }) +# --- +# name: TestsRequests.test_post_wrong_args[set-foo- ] + dict({ + 'message': 'Parameter value contains invalid characters', + }) +# --- +# name: TestsRequests.test_post_wrong_args[set_audio_delay-&-None] + dict({ + 'message': 'Parameter needs to be an integer or float', + }) +# --- +# name: TestsRequests.test_post_wrong_args[set_position-&-None] + dict({ + 'message': 'Parameter needs to be an integer or float', + }) +# --- +# name: TestsRequests.test_post_wrong_args[set_position-None-None] + dict({ + 'message': 'Parameter needs to be an integer or float', + }) +# --- +# name: TestsRequests.test_post_wrong_args[set_sub_delay-&-None] + dict({ + 'message': 'Parameter needs to be an integer or float', + }) +# --- +# name: TestsRequests.test_post_wrong_args[set_volume-&-None] + dict({ + 'message': 'Parameter needs to be an integer or float', + }) +# --- +# name: TestsRequests.test_post_wrong_args[speed_adjust-&-None] + dict({ + 'message': 'Parameter needs to be an integer or float', + }) +# --- +# name: TestsRequests.test_post_wrong_args[speed_set-&-None] + dict({ + 'message': 'Parameter needs to be an integer or float', + }) +# --- +# name: TestsRequests.test_post_wrong_args[toggle-&-None] + dict({ + 'message': 'Parameter name contains invalid characters', + }) +# --- +# name: TestsRequests.test_post_wrong_args[toggle-None-None] + dict({ + 'message': 'Parameter name contains invalid characters', + }) +# --- +# name: test_status + dict({ + 'audio-delay': 0, + 'audio-devices': list([ + dict({ + 'active': True, + 'description': 'Autoselect device', + 'name': 'auto', + }), + dict({ + 'active': False, + 'description': 'Default (alsa)', + 'name': 'alsa', + }), + dict({ + 'active': False, + 'description': 'Default (jack)', + 'name': 'jack', + }), + dict({ + 'active': False, + 'description': 'Default (sdl)', + 'name': 'sdl', + }), + ]), + 'chapter': 0, + 'chapter-list': list([ + ]), + 'chapters': 0, + 'duration': 6.024, + 'end': None, + 'filename': '01 - dummy.mp3', + 'fullscreen': False, + 'loop-file': False, + 'loop-playlist': False, + 'metadata': dict({ + 'album': 'Dummy Album', + 'artist': 'Dummy Artist', + 'comment': '0', + 'date': '2020', + 'encoder': 'Lavc57.10', + 'genre': 'Jazz', + 'title': 'First dummy', + }), + 'pause': True, + 'playlist': list([ + dict({ + 'current': True, + 'filename': './environment/test_media/01 - dummy.mp3', + 'id': 1, + 'playing': True, + 'title': 'First dummy', + }), + dict({ + 'filename': './environment/test_media/02 - dummy.mp3', + 'id': 2, + }), + dict({ + 'filename': './environment/test_media/03 - dummy.mp3', + 'id': 3, + }), + ]), + 'position': -0.0, + 'remaining': 6.024, + 'speed': 1, + 'start': None, + 'sub-delay': 0, + 'track-list': list([ + dict({ + 'albumart': False, + 'audio-channels': 2, + 'auto-forced-only': False, + 'codec': 'mp3', + 'decoder-desc': 'mp3float (MP3 (MPEG audio layer 3))', + 'default': False, + 'demux-bitrate': 32000, + 'demux-channel-count': 2, + 'demux-channels': 'stereo', + 'demux-samplerate': 48000, + 'dependent': False, + 'external': False, + 'ff-index': 0, + 'forced': False, + 'hearing-impaired': False, + 'id': 1, + 'image': False, + 'main-selection': 0, + 'selected': True, + 'type': 'audio', + 'visual-impaired': False, + }), + ]), + 'volume': 0, + 'volume-max': 130, + 'webui-version': '3.0.0', + }) +# --- diff --git a/tests/requirements.txt b/tests/requirements.txt index 351899c..4635271 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -14,4 +14,4 @@ pytest==7.4.3 pytest-randomly==3.15.0 python-semantic-release==8.3.0 requests==2.31.0 -snapshottest==0.6.0 +syrupy==4.6.0 diff --git a/tests/snapshots/__init__.py b/tests/snapshots/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/snapshots/snap_tests.py b/tests/snapshots/snap_tests.py deleted file mode 100644 index e6417ea..0000000 --- a/tests/snapshots/snap_tests.py +++ /dev/null @@ -1,261 +0,0 @@ -# -*- coding: utf-8 -*- -# snapshottest: v1 - https://goo.gl/zC4yUc -from __future__ import unicode_literals - -from snapshottest import Snapshot - -snapshots = Snapshot() - -snapshots["TestsRequests.test_collections[api/collections-200-mpv_instance0] 1"] = [ - { - "is-directory": True, - "path": "/app/scripts/simple-mpv-webui/tests/environment/collection", - } -] - -snapshots[ - "TestsRequests.test_collections[api/collections/%2Fapp%2Fscripts%2Fsimple-mpv-webui%2Ftests%2Fenvironment%2Fcollection-200-mpv_instance0] 1" -] = [ - { - "is-directory": False, - "path": "/app/scripts/simple-mpv-webui/tests/environment/collection/'file b'.log", - }, - { - "is-directory": True, - "path": "/app/scripts/simple-mpv-webui/tests/environment/collection/A folder", - }, - { - "is-directory": False, - "path": "/app/scripts/simple-mpv-webui/tests/environment/collection/file a.log", - }, - { - "is-directory": False, - "path": """/app/scripts/simple-mpv-webui/tests/environment/collection/line -break""", - }, -] - -snapshots["TestsRequests.test_post_wrong_args[add-&-foo] 1"] = { - "message": "Parameter name contains invalid characters" -} - -snapshots["TestsRequests.test_post_wrong_args[add-foo-&] 1"] = { - "message": "Parameter needs to be an integer or float" -} - -snapshots["TestsRequests.test_post_wrong_args[add_audio_delay-&-None] 1"] = { - "message": "Parameter needs to be an integer or float" -} - -snapshots["TestsRequests.test_post_wrong_args[add_chapter-&-None] 1"] = { - "message": "Parameter needs to be an integer or float" -} - -snapshots["TestsRequests.test_post_wrong_args[add_sub_delay-&-None] 1"] = { - "message": "Parameter needs to be an integer or float" -} - -snapshots["TestsRequests.test_post_wrong_args[add_volume-&-None] 1"] = { - "message": "Parameter needs to be an integer or float" -} - -snapshots["TestsRequests.test_post_wrong_args[cycle-&-foo] 1"] = { - "message": "Parameter name contains invalid characters" -} - -snapshots["TestsRequests.test_post_wrong_args[cycle-foo-&] 1"] = { - "message": 'Cycle paramater is not "up" or "down"' -} - -snapshots["TestsRequests.test_post_wrong_args[loadfile-None-None] 1"] = { - "message": "No url provided!" -} - -snapshots["TestsRequests.test_post_wrong_args[loadfile-http://foo-invalid] 1"] = { - "message": "Invalid mode: 'foo'" -} - -snapshots["TestsRequests.test_post_wrong_args[loop_file-&-None] 1"] = { - "message": "Invalid parameter!" -} - -snapshots["TestsRequests.test_post_wrong_args[loop_file-None-None] 1"] = { - "message": "Invalid parameter!" -} - -snapshots["TestsRequests.test_post_wrong_args[loop_playlist-&-None] 1"] = { - "message": "Invalid parameter!" -} - -snapshots["TestsRequests.test_post_wrong_args[multiply-&-23] 1"] = { - "message": "Parameter name contains invalid characters" -} - -snapshots["TestsRequests.test_post_wrong_args[multiply-23-&] 1"] = { - "message": "Parameter needs to be an integer or float" -} - -snapshots["TestsRequests.test_post_wrong_args[multiply-23-None] 1"] = { - "message": "Parameter needs to be an integer or float" -} - -snapshots["TestsRequests.test_post_wrong_args[playlist_jump-&-None] 1"] = { - "message": "Parameter needs to be an integer or float" -} - -snapshots["TestsRequests.test_post_wrong_args[playlist_jump-None-None] 1"] = { - "message": "Parameter needs to be an integer or float" -} - -snapshots["TestsRequests.test_post_wrong_args[playlist_move-&-23] 1"] = { - "message": "Parameter needs to be an integer or float" -} - -snapshots["TestsRequests.test_post_wrong_args[playlist_move-23-&] 1"] = { - "message": "Parameter needs to be an integer or float" -} - -snapshots["TestsRequests.test_post_wrong_args[playlist_move-23-None] 1"] = { - "message": "Parameter needs to be an integer or float" -} - -snapshots["TestsRequests.test_post_wrong_args[playlist_move_up-&-None] 1"] = { - "message": "Parameter needs to be an integer or float" -} - -snapshots["TestsRequests.test_post_wrong_args[playlist_move_up-None-None] 1"] = { - "message": "Parameter needs to be an integer or float" -} - -snapshots["TestsRequests.test_post_wrong_args[playlist_remove-&-None] 1"] = { - "message": "Parameter needs to be an integer or float" -} - -snapshots["TestsRequests.test_post_wrong_args[playlist_remove-None-None] 1"] = { - "message": "Parameter needs to be an integer or float" -} - -snapshots["TestsRequests.test_post_wrong_args[seek-None-None] 1"] = { - "message": "Parameter needs to be an integer or float" -} - -snapshots["TestsRequests.test_post_wrong_args[seek-g-None] 1"] = { - "message": "Parameter needs to be an integer or float" -} - -snapshots["TestsRequests.test_post_wrong_args[set-&-foo] 1"] = { - "message": "Parameter name contains invalid characters" -} - -snapshots["TestsRequests.test_post_wrong_args[set-foo- ] 1"] = { - "message": "Parameter value contains invalid characters" -} - -snapshots["TestsRequests.test_post_wrong_args[set_audio_delay-&-None] 1"] = { - "message": "Parameter needs to be an integer or float" -} - -snapshots["TestsRequests.test_post_wrong_args[set_position-&-None] 1"] = { - "message": "Parameter needs to be an integer or float" -} - -snapshots["TestsRequests.test_post_wrong_args[set_position-None-None] 1"] = { - "message": "Parameter needs to be an integer or float" -} - -snapshots["TestsRequests.test_post_wrong_args[set_sub_delay-&-None] 1"] = { - "message": "Parameter needs to be an integer or float" -} - -snapshots["TestsRequests.test_post_wrong_args[set_volume-&-None] 1"] = { - "message": "Parameter needs to be an integer or float" -} - -snapshots["TestsRequests.test_post_wrong_args[speed_adjust-&-None] 1"] = { - "message": "Parameter needs to be an integer or float" -} - -snapshots["TestsRequests.test_post_wrong_args[speed_set-&-None] 1"] = { - "message": "Parameter needs to be an integer or float" -} - -snapshots["TestsRequests.test_post_wrong_args[toggle-&-None] 1"] = { - "message": "Parameter name contains invalid characters" -} - -snapshots["TestsRequests.test_post_wrong_args[toggle-None-None] 1"] = { - "message": "Parameter name contains invalid characters" -} - -snapshots["test_status 1"] = { - "audio-delay": 0, - "audio-devices": [ - {"active": True, "description": "Autoselect device", "name": "auto"}, - {"active": False, "description": "Default (alsa)", "name": "alsa"}, - {"active": False, "description": "Default (jack)", "name": "jack"}, - {"active": False, "description": "Default (sdl)", "name": "sdl"}, - ], - "chapter": 0, - "chapter-list": [], - "chapters": 0, - "duration": 6.024, - "end": None, - "filename": "01 - dummy.mp3", - "fullscreen": False, - "loop-file": False, - "loop-playlist": False, - "metadata": { - "album": "Dummy Album", - "artist": "Dummy Artist", - "comment": "0", - "date": "2020", - "encoder": "Lavc57.10", - "genre": "Jazz", - "title": "First dummy", - }, - "pause": True, - "playlist": [ - { - "current": True, - "filename": "./environment/test_media/01 - dummy.mp3", - "id": 1, - "playing": True, - "title": "First dummy", - }, - {"filename": "./environment/test_media/02 - dummy.mp3", "id": 2}, - {"filename": "./environment/test_media/03 - dummy.mp3", "id": 3}, - ], - "position": -0.0, - "remaining": 6.024, - "speed": 1, - "start": None, - "sub-delay": 0, - "track-list": [ - { - "albumart": False, - "audio-channels": 2, - "auto-forced-only": False, - "codec": "mp3", - "decoder-desc": "mp3float (MP3 (MPEG audio layer 3))", - "default": False, - "demux-bitrate": 32000, - "demux-channel-count": 2, - "demux-channels": "stereo", - "demux-samplerate": 48000, - "dependent": False, - "external": False, - "ff-index": 0, - "forced": False, - "hearing-impaired": False, - "id": 1, - "image": False, - "main-selection": 0, - "selected": True, - "type": "audio", - "visual-impaired": False, - } - ], - "volume": 0, - "volume-max": 130, - "webui-version": "3.0.0", -} From d8c903c03a29c26121c58d82356f45f79891d311 Mon Sep 17 00:00:00 2001 From: Fabio Ambauen <1833932+open-dynaMIX@users.noreply.github.com> Date: Tue, 7 Nov 2023 11:50:20 +0100 Subject: [PATCH 3/3] chore: set default timeout for requests --- tests/tests.py | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/tests/tests.py b/tests/tests.py index c03900f..7a5d29b 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -6,6 +6,16 @@ import requests from requests.auth import HTTPBasicAuth +REQUEST_TIMEOUT = 5 + + +def get(uri, auth=None, headers=None, timeout=REQUEST_TIMEOUT): + return requests.get(uri, auth=auth, headers=headers, timeout=timeout) + + +def post(uri, data=None): + return requests.post(uri, data=data, timeout=REQUEST_TIMEOUT) + def get_uri(suffix, v=None, port=8080): host = "localhost" @@ -17,14 +27,14 @@ def get_uri(suffix, v=None, port=8080): def get_status(): - resp = requests.get(get_uri("api/status")) + resp = get(get_uri("api/status")) assert resp.status_code == 200 return resp.json() def is_responding(uri): try: - requests.get(uri) + get(uri) except requests.exceptions.ConnectionError: return False return True @@ -43,7 +53,7 @@ def send(command, arg=None, arg2=None, expect=200, status=None): for a in [arg, arg2]: if a is not None: api += f"/{a}" - resp = requests.post(get_uri(api)) + resp = post(get_uri(api)) assert resp.status_code == expect if status is not None: return get_status()[status] @@ -97,7 +107,7 @@ class TestsRequests: ], ) def test_static(mpv_instance, uri, status_code, content_type): - resp = requests.get(get_uri(uri)) + resp = get(get_uri(uri)) assert resp.status_code == status_code if status_code != 200: return @@ -113,7 +123,7 @@ def test_static(mpv_instance, uri, status_code, content_type): @staticmethod @pytest.mark.parametrize("uri", ["", "/", "//", "///"]) def test_index(mpv_instance, uri): - resp = requests.get(get_uri(uri)) + resp = get(get_uri(uri)) assert resp.status_code == 200 resp.headers.pop("Content-Length") @@ -206,7 +216,7 @@ def test_post_wrong_args(mpv_instance, snapshot, endpoint, arg, arg2): for a in [arg, arg2]: if a is not None: api += f"/{a}" - response = requests.post(get_uri(api)) + response = post(get_uri(api)) assert response.status_code == 400 snapshot.assert_match(response.json()) @@ -408,7 +418,7 @@ def test_not_allowed_methods(mpv_instance, endpoint, method, expected): ], ) def test_collections(self, endpoint, expected_status, mpv_instance, snapshot): - resp = requests.get(f"{get_uri(endpoint)}") + resp = get(get_uri(endpoint)) assert resp.status_code == expected_status @@ -493,7 +503,7 @@ def send_loadfile(url, mode=None, expect=200): indirect=["mpv_instance"], ) def test_static_dir_config(mpv_instance, status_code): - resp = requests.get(get_uri("static.json")) + resp = get(get_uri("static.json")) assert resp.status_code == status_code if status_code == 200: @@ -588,7 +598,7 @@ def test_disablers(mpv_instance, v4_works, v6_works): ) def test_auth(htpasswd, mpv_instance, auth, status_code): try: - resp = requests.get(get_uri("api/status"), auth=auth, timeout=0.5) + resp = get(get_uri("api/status"), auth=auth, timeout=0.5) except requests.exceptions.ReadTimeout: assert status_code is None return @@ -648,9 +658,7 @@ def test_logging(htpasswd, mpv_instance, use_auth, username, password, status_co auth = None if use_auth and username: auth = HTTPBasicAuth(username, password) - resp = requests.get( - get_uri("api/status"), auth=auth, headers={"Referer": "https://referer"} - ) + resp = get(get_uri("api/status"), auth=auth, headers={"Referer": "https://referer"}) assert resp.status_code == status_code # example log line