mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-08-27 03:49:57 +00:00
It has been broken since reporter improvements, because it effectivelly 1) didn't call remove functions in database 2) used empty repository identifier for web service With those changes it also raises exception when you try to call id on empty identifier
71 lines
2.1 KiB
Python
71 lines
2.1 KiB
Python
import pytest
|
|
|
|
from ahriman.models.repository_id import RepositoryId
|
|
|
|
|
|
def test_id() -> None:
|
|
"""
|
|
must correctly generate id
|
|
"""
|
|
assert RepositoryId("arch", "repo").id == "arch-repo"
|
|
|
|
|
|
def test_id_empty() -> None:
|
|
"""
|
|
must raise exception on empty identifier
|
|
"""
|
|
with pytest.raises(ValueError):
|
|
assert RepositoryId("", "").id
|
|
|
|
|
|
def test_is_empty() -> None:
|
|
"""
|
|
must check if repository id is empty or not
|
|
"""
|
|
assert RepositoryId("", "").is_empty
|
|
assert RepositoryId("arch", "").is_empty
|
|
assert RepositoryId("", "repo").is_empty
|
|
assert not RepositoryId("arch", "repo").is_empty
|
|
|
|
|
|
def test_query() -> None:
|
|
"""
|
|
must generate query request parameters
|
|
"""
|
|
assert RepositoryId("x86_64", "a").query() == [("architecture", "x86_64"), ("repository", "a")]
|
|
assert RepositoryId("i686", "a").query() == [("architecture", "i686"), ("repository", "a")]
|
|
assert RepositoryId("x86_64", "b").query() == [("architecture", "x86_64"), ("repository", "b")]
|
|
|
|
|
|
def test_view() -> None:
|
|
"""
|
|
must generate json view
|
|
"""
|
|
repository_id = RepositoryId("x86_64", "a")
|
|
assert repository_id.view() == {"architecture": repository_id.architecture, "repository": repository_id.name}
|
|
|
|
repository_id = RepositoryId("x86_64", "b")
|
|
assert repository_id.view() == {"architecture": repository_id.architecture, "repository": repository_id.name}
|
|
|
|
repository_id = RepositoryId("i686", "a")
|
|
assert repository_id.view() == {"architecture": repository_id.architecture, "repository": repository_id.name}
|
|
|
|
|
|
def test_lt() -> None:
|
|
"""
|
|
must correctly compare instances
|
|
"""
|
|
assert RepositoryId("x86_64", "a") < RepositoryId("x86_64", "b")
|
|
assert RepositoryId("x86_64", "b") > RepositoryId("x86_64", "a")
|
|
|
|
assert RepositoryId("i686", "a") < RepositoryId("x86_64", "a")
|
|
assert RepositoryId("x86_64", "a") > RepositoryId("i686", "a")
|
|
|
|
|
|
def test_lt_invalid() -> None:
|
|
"""
|
|
must raise ValueError if other is not valid repository id
|
|
"""
|
|
with pytest.raises(ValueError):
|
|
assert RepositoryId("x86_64", "a") < 42
|