test(worker): setup testing
This commit is contained in:
parent
ab6cebb6ed
commit
7184fb3235
|
@ -18,4 +18,3 @@ jobs:
|
||||||
uses: ./.github/workflows/_python.yml
|
uses: ./.github/workflows/_python.yml
|
||||||
with:
|
with:
|
||||||
context: worker
|
context: worker
|
||||||
test: false
|
|
||||||
|
|
|
@ -29,3 +29,8 @@ flags:
|
||||||
paths:
|
paths:
|
||||||
- shared/
|
- shared/
|
||||||
carryforward: true
|
carryforward: true
|
||||||
|
|
||||||
|
worker:
|
||||||
|
paths:
|
||||||
|
- worker/
|
||||||
|
carryforward: true
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
all: lint
|
all: lint test
|
||||||
|
|
||||||
include ../tools/python.mk
|
include ../tools/python.mk
|
||||||
|
|
||||||
|
@ -8,7 +8,9 @@ PIP_INSTALL := \
|
||||||
PYLINT_ARG := libretime_worker || true
|
PYLINT_ARG := libretime_worker || true
|
||||||
MYPY_ARG := libretime_worker || true
|
MYPY_ARG := libretime_worker || true
|
||||||
BANDIT_ARG := libretime_worker || true
|
BANDIT_ARG := libretime_worker || true
|
||||||
|
PYTEST_ARG = --cov=libretime_worker tests
|
||||||
|
|
||||||
format: .format
|
format: .format
|
||||||
lint: .format-check .pylint .mypy .bandit
|
lint: .format-check .pylint .mypy .bandit
|
||||||
|
test: .pytest
|
||||||
clean: .clean
|
clean: .clean
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
import os
|
||||||
|
|
||||||
|
os.environ.setdefault("LIBRETIME_DEBUG", "true")
|
||||||
|
os.environ.setdefault("LIBRETIME_GENERAL_PUBLIC_URL", "http://localhost")
|
||||||
|
os.environ.setdefault("LIBRETIME_GENERAL_API_KEY", "testing")
|
|
@ -0,0 +1,25 @@
|
||||||
|
import pytest
|
||||||
|
from requests import Response
|
||||||
|
|
||||||
|
from libretime_worker.tasks import extract_filename
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"url, header, expected",
|
||||||
|
[
|
||||||
|
("http://example.com/from-url.mp3", None, "from-url.mp3"),
|
||||||
|
(
|
||||||
|
"http://example.com/from-url.mp3",
|
||||||
|
'attachment; filename="from-header.mp3"',
|
||||||
|
"from-header.mp3",
|
||||||
|
),
|
||||||
|
("http://example.com/from-url.mp3", "attachment", "from-url.mp3"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_extract_filename(url, header, expected):
|
||||||
|
resp = Response()
|
||||||
|
resp.url = url
|
||||||
|
if header is not None:
|
||||||
|
resp.headers["Content-Disposition"] = header
|
||||||
|
|
||||||
|
assert extract_filename(resp) == expected
|
Loading…
Reference in New Issue