test(worker): setup testing

This commit is contained in:
jo 2022-09-09 11:52:19 +02:00 committed by Kyle Robbertze
parent ab6cebb6ed
commit 7184fb3235
5 changed files with 38 additions and 2 deletions

View File

@ -18,4 +18,3 @@ jobs:
uses: ./.github/workflows/_python.yml
with:
context: worker
test: false

View File

@ -29,3 +29,8 @@ flags:
paths:
- shared/
carryforward: true
worker:
paths:
- worker/
carryforward: true

View File

@ -1,4 +1,4 @@
all: lint
all: lint test
include ../tools/python.mk
@ -8,7 +8,9 @@ PIP_INSTALL := \
PYLINT_ARG := libretime_worker || true
MYPY_ARG := libretime_worker || true
BANDIT_ARG := libretime_worker || true
PYTEST_ARG = --cov=libretime_worker tests
format: .format
lint: .format-check .pylint .mypy .bandit
test: .pytest
clean: .clean

5
worker/tests/conftest.py Normal file
View File

@ -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")

View File

@ -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