Skip to content

Commit

Permalink
fix(api): refactor request handling; fix Allow header
Browse files Browse the repository at this point in the history
This commit refactors the handling of requests in the API. All
endpoints are added as functions to a table. A new `response` table is
introduced. Every endpoint function returns such response.
This allows for more generic request handling, while offering even more
customizability per request. As a side effect, the `Allow:` header now
contains the correct methods instead of hardcoded `GET,POST`.
  • Loading branch information
open-dynaMIX committed Jan 4, 2021
1 parent 853209d commit 1163b90
Show file tree
Hide file tree
Showing 2 changed files with 576 additions and 384 deletions.
23 changes: 19 additions & 4 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,27 @@ def shuffle():

@staticmethod
@pytest.mark.parametrize(
"method",
["head", "patch", "not_a_valid_http_method"],
"endpoint,method,expected",
[
("api/status", "head", "GET"),
("api/status", "patch", "GET"),
("api/status", "post", "GET"),
("api/status", "not_a_valid_http_method", "GET"),
("webui.js", "head", "GET"),
("webui.js", "patch", "GET"),
("webui.js", "post", "GET"),
("webui.js", "not_a_valid_http_method", "GET"),
("api/play", "head", "POST"),
("api/play", "patch", "POST"),
("api/play", "get", "POST"),
("api/play", "not_a_valid_http_method", "POST"),
],
)
def test_not_allowed_methods(mpv_instance, method):
resp = requests.request(method, f"{get_uri('api/status')}")
def test_not_allowed_methods(mpv_instance, endpoint, method, expected):
resp = requests.request(method, f"{get_uri(endpoint)}")
assert resp.status_code == 405
assert "Allow" in resp.headers
assert resp.headers["Allow"] == expected


def test_loadfile(mpv_instance):
Expand Down
Loading

0 comments on commit 1163b90

Please sign in to comment.