Commit d5cdad27 authored by David Runge's avatar David Runge
Browse files

Merge branch 'issues/6' into 'master'

Add documentation and validators to models

Closes #6

See merge request !6
parents 3c443e22 1a61c3d1
Pipeline #5940 passed with stage
in 5 minutes and 49 seconds
This diff is collapsed.
...@@ -119,7 +119,7 @@ def test__desc_data_to_dict( ...@@ -119,7 +119,7 @@ def test__desc_data_to_dict(
desc="foo", desc="foo",
filename="foo", filename="foo",
isize=1, isize=1,
licenses=["foo"], license=["foo"],
md5sum="foo", md5sum="foo",
name="foo", name="foo",
packager="foo", packager="foo",
...@@ -139,7 +139,7 @@ def test__desc_data_to_dict( ...@@ -139,7 +139,7 @@ def test__desc_data_to_dict(
desc="foo", desc="foo",
filename="foo", filename="foo",
isize=1, isize=1,
licenses=["foo"], license=["foo"],
md5sum="foo", md5sum="foo",
name="foo", name="foo",
packager="foo", packager="foo",
...@@ -182,7 +182,7 @@ def test_repodbfile_render_desc_template() -> None: ...@@ -182,7 +182,7 @@ def test_repodbfile_render_desc_template() -> None:
desc="foo", desc="foo",
filename="foo", filename="foo",
isize=1, isize=1,
licenses=["foo"], license=["foo"],
md5sum="foo", md5sum="foo",
name="foo", name="foo",
packager="foo", packager="foo",
......
...@@ -148,7 +148,7 @@ def test__write_db_file(empty_dir: Path) -> None: ...@@ -148,7 +148,7 @@ def test__write_db_file(empty_dir: Path) -> None:
filename="foo", filename="foo",
files=["foo", "bar"], files=["foo", "bar"],
isize=1, isize=1,
licenses=["foo"], license=["foo"],
md5sum="foo", md5sum="foo",
name="foo", name="foo",
pgpsig="foo", pgpsig="foo",
...@@ -173,7 +173,7 @@ def test__write_db_file(empty_dir: Path) -> None: ...@@ -173,7 +173,7 @@ def test__write_db_file(empty_dir: Path) -> None:
filename="foo", filename="foo",
files=["foo", "bar"], files=["foo", "bar"],
isize=1, isize=1,
licenses=["foo"], license=["foo"],
md5sum="foo", md5sum="foo",
name="foo", name="foo",
pgpsig="foo", pgpsig="foo",
......
from typing import List, Optional, Tuple from contextlib import nullcontext as does_not_raise
from typing import ContextManager, List, Optional, Tuple
from pytest import mark from pytest import mark, raises
from repo_management import models from repo_management import models
...@@ -143,3 +144,97 @@ def test_output_package_base_get_packages_as_models( ...@@ -143,3 +144,97 @@ def test_output_package_base_get_packages_as_models(
output_package_base: models.OutputPackageBase, output_package_base: models.OutputPackageBase,
) -> None: ) -> None:
assert models_list == output_package_base.get_packages_as_models() assert models_list == output_package_base.get_packages_as_models()
@mark.parametrize(
"name, expectation",
[
(".foo", raises(ValueError)),
("-foo", raises(ValueError)),
("foo'", raises(ValueError)),
("foo", does_not_raise()),
],
)
def test_name(name: str, expectation: ContextManager[str]) -> None:
with expectation:
assert name == models.Name(name=name).name
@mark.parametrize(
"builddate, expectation",
[
(-1, raises(ValueError)),
(1, does_not_raise()),
],
)
def test_builddate(builddate: int, expectation: ContextManager[str]) -> None:
with expectation:
assert builddate == models.BuildDate(builddate=builddate).builddate
@mark.parametrize(
"csize, expectation",
[
(-1, raises(ValueError)),
(1, does_not_raise()),
],
)
def test_csize(csize: int, expectation: ContextManager[str]) -> None:
with expectation:
assert csize == models.CSize(csize=csize).csize
@mark.parametrize(
"isize, expectation",
[
(-1, raises(ValueError)),
(1, does_not_raise()),
],
)
def test_isize(isize: int, expectation: ContextManager[str]) -> None:
with expectation:
assert isize == models.ISize(isize=isize).isize
@mark.parametrize(
"version, expectation",
[
("1.2.3-0", raises(ValueError)),
(".1.2.3-1", raises(ValueError)),
("-1.2.3-1", raises(ValueError)),
(":1.2.3-1", raises(ValueError)),
("_1.2.3-1", raises(ValueError)),
("+1.2.3-1", raises(ValueError)),
("1.2.'3-1", raises(ValueError)),
("1.2.3-1", does_not_raise()),
("1:1.2.3-1", does_not_raise()),
("1:1.2.3r500.x.y.z.1-1", does_not_raise()),
],
)
def test_version_version_is_valid(version: str, expectation: ContextManager[str]) -> None:
with expectation:
assert version == models.Version(version=version).version
@mark.parametrize(
"version, other_version, expectation",
[
("1.2.3-1", "1.2.3-2", True),
("1.2.3-2", "1.2.3-1", False),
],
)
def test_version_is_older_than(version: str, other_version: str, expectation: bool) -> None:
model = models.Version(version=version)
assert model.is_older_than(other_version) is expectation
@mark.parametrize(
"version, other_version, expectation",
[
("1.2.3-1", "1.2.3-2", False),
("1.2.3-2", "1.2.3-1", True),
],
)
def test_version_is_newer_than(version: str, other_version: str, expectation: bool) -> None:
model = models.Version(version=version)
assert model.is_newer_than(other_version) is expectation
Markdown is supported
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