Verified Commit fdd9145e authored by David Runge's avatar David Runge
Browse files

Merge branch 'issues/3'

* issues/3:
  Add tests target against system packages
  tox: Remove unneeded environment variable
  Validate PRIVATE_TOKEN in config
parents 980d104b 9a45575e
Pipeline #9931 passed with stages
in 51 seconds
......@@ -4,7 +4,7 @@ image: archlinux:latest
stages:
- check
- coverage
- test
linter:
before_script:
......@@ -18,4 +18,11 @@ coverage:
- pacman --noconfirm -Syu --needed python-poetry python-tox
script:
- tox -e coverage
stage: coverage
stage: test
system_test:
before_script:
- pacman --noconfirm -Syu --needed python-pydantic python-dotenv python-pyxdg python-email-validator python-torrentool python-gitlab python-orjson python-prometheus_client python-toml python-pytest
script:
- pytest -vv tests/ -m "not integration"
stage: test
......@@ -231,3 +231,28 @@ class Settings(BaseSettings):
raise ValueError(f"The GPGKEY string has to represent a PGP key ID in long format (40 chars): {gpgkey}")
return gpgkey
@validator("PRIVATE_TOKEN")
def validate_private_token(cls, private_token: str) -> str:
"""A validator for the PRIVATE_TOKEN attribute
Parameters
----------
private_token: str
The private token string to validate
Raises
------
ValueError
If the private token string is not valid
Returns
-------
str
A gpgkey string in long-format
"""
if len(private_token) < 20:
raise ValueError("The PRIVATE_TOKEN string has to represent a valid private token (20 chars).")
return private_token
......@@ -2,7 +2,7 @@ import random
import tempfile
from contextlib import nullcontext as does_not_raise
from pathlib import Path
from string import ascii_uppercase
from string import ascii_letters, ascii_uppercase
from typing import ContextManager, List
from unittest.mock import patch
......@@ -13,36 +13,48 @@ from arch_release_promotion import config
@mark.parametrize(
"gpgkey, packager, expectation",
"gpgkey, packager, private_token, expectation",
[
(
"".join(random.choice(ascii_uppercase) for x in range(40)),
"Foobar McFoo <foobar@archlinux.org>",
"".join(random.choice(ascii_letters) for x in range(20)),
does_not_raise(),
),
(
"".join(random.choice(ascii_uppercase) for x in range(40)),
"",
"".join(random.choice(ascii_letters) for x in range(20)),
raises(ValueError),
),
(
"".join(random.choice(ascii_uppercase) for x in range(40)),
"Foobar McFoo <foobar@archlinux.org>",
"".join(random.choice(ascii_letters) for x in range(10)),
raises(ValueError),
),
(
"".join(random.choice(ascii_uppercase) for x in range(40)),
"Foobar McFoo",
"".join(random.choice(ascii_letters) for x in range(20)),
raises(ValueError),
),
(
"".join(random.choice(ascii_uppercase) for x in range(40)),
"<foobar@archlinux.org>",
"".join(random.choice(ascii_letters) for x in range(20)),
raises(ValueError),
),
(
"".join(random.choice(ascii_uppercase) for x in range(40)),
"Foobar McFoo <foobar@mc.fooface>",
"".join(random.choice(ascii_letters) for x in range(20)),
raises(ValueError),
),
(
"".join(random.choice(ascii_uppercase) for x in range(10)),
"Foobar McFoo <foobar@archlinux.org>",
"".join(random.choice(ascii_letters) for x in range(20)),
raises(ValueError),
),
],
......@@ -50,11 +62,13 @@ from arch_release_promotion import config
def test_settings(
gpgkey: str,
packager: str,
private_token: str,
expectation: ContextManager[str],
) -> None:
conf = tempfile.NamedTemporaryFile(mode="w", encoding="utf-8", suffix=".conf", delete=False)
conf.write(f"GPGKEY='{gpgkey}'\n")
conf.write(f"PACKAGER='{packager}'\n")
conf.write(f"PRIVATE_TOKEN={private_token}\n")
conf.close()
with patch("arch_release_promotion.config.MAKEPKG_CONFIGS", [Path(conf.name)]):
......
......@@ -16,8 +16,6 @@ commands =
poetry run coverage run
poetry run coverage xml
poetry run coverage report --fail-under=100.0
setenv =
PRIVATE_TOKEN=thisisnotarealtoken
[testenv:linter]
whitelist_externals = poetry
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment