mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-09-17 22:29:55 +00:00
frozen dataclasses
This commit is contained in:
@ -61,11 +61,11 @@ def test_from_pacman(pyalpm_package_ahriman: pyalpm.Package, aur_package_ahriman
|
||||
"""
|
||||
model = AURPackage.from_pacman(pyalpm_package_ahriman)
|
||||
# some fields are missing so we are changing them
|
||||
model.id = aur_package_ahriman.id
|
||||
model.package_base_id = aur_package_ahriman.package_base_id
|
||||
model.first_submitted = aur_package_ahriman.first_submitted
|
||||
model.url_path = aur_package_ahriman.url_path
|
||||
model.maintainer = aur_package_ahriman.maintainer
|
||||
object.__setattr__(model, "id", aur_package_ahriman.id)
|
||||
object.__setattr__(model, "package_base_id", aur_package_ahriman.package_base_id)
|
||||
object.__setattr__(model, "first_submitted", aur_package_ahriman.first_submitted)
|
||||
object.__setattr__(model, "url_path", aur_package_ahriman.url_path)
|
||||
object.__setattr__(model, "maintainer", aur_package_ahriman.maintainer)
|
||||
|
||||
assert model == aur_package_ahriman
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
import datetime
|
||||
import time
|
||||
|
||||
from ahriman.models.build_status import BuildStatus, BuildStatusEnum
|
||||
@ -53,43 +52,3 @@ def test_build_status_eq(build_status_failed: BuildStatus) -> None:
|
||||
"""
|
||||
other = BuildStatus.from_json(build_status_failed.view())
|
||||
assert other == build_status_failed
|
||||
|
||||
|
||||
def test_build_status_eq_self(build_status_failed: BuildStatus) -> None:
|
||||
"""
|
||||
must be equal itself
|
||||
"""
|
||||
assert build_status_failed == build_status_failed
|
||||
|
||||
|
||||
def test_build_status_ne_by_status(build_status_failed: BuildStatus) -> None:
|
||||
"""
|
||||
must be not equal by status
|
||||
"""
|
||||
other = BuildStatus.from_json(build_status_failed.view())
|
||||
other.status = BuildStatusEnum.Success
|
||||
assert build_status_failed != other
|
||||
|
||||
|
||||
def test_build_status_ne_by_timestamp(build_status_failed: BuildStatus) -> None:
|
||||
"""
|
||||
must be not equal by timestamp
|
||||
"""
|
||||
other = BuildStatus.from_json(build_status_failed.view())
|
||||
other.timestamp = datetime.datetime.utcnow().timestamp()
|
||||
assert build_status_failed != other
|
||||
|
||||
|
||||
def test_build_status_ne_other(build_status_failed: BuildStatus) -> None:
|
||||
"""
|
||||
must be not equal to random object
|
||||
"""
|
||||
assert build_status_failed != object()
|
||||
|
||||
|
||||
def test_build_status_repr(build_status_failed: BuildStatus) -> None:
|
||||
"""
|
||||
must return string in __repr__ function
|
||||
"""
|
||||
assert build_status_failed.__repr__()
|
||||
assert isinstance(build_status_failed.__repr__(), str)
|
||||
|
@ -69,7 +69,7 @@ def test_chown(repository_paths: RepositoryPaths, mocker: MockerFixture) -> None
|
||||
"""
|
||||
must correctly set owner for the directory
|
||||
"""
|
||||
repository_paths.owner = _get_owner(repository_paths.root, same=False)
|
||||
object.__setattr__(repository_paths, "owner", _get_owner(repository_paths.root, same=False))
|
||||
mocker.patch.object(RepositoryPaths, "root_owner", (42, 42))
|
||||
chown_mock = mocker.patch("os.chown")
|
||||
|
||||
@ -82,7 +82,7 @@ def test_chown_parent(repository_paths: RepositoryPaths, mocker: MockerFixture)
|
||||
"""
|
||||
must correctly set owner for the directory including parents
|
||||
"""
|
||||
repository_paths.owner = _get_owner(repository_paths.root, same=False)
|
||||
object.__setattr__(repository_paths, "owner", _get_owner(repository_paths.root, same=False))
|
||||
mocker.patch.object(RepositoryPaths, "root_owner", (42, 42))
|
||||
chown_mock = mocker.patch("os.chown")
|
||||
|
||||
@ -98,7 +98,7 @@ def test_chown_skip(repository_paths: RepositoryPaths, mocker: MockerFixture) ->
|
||||
"""
|
||||
must skip ownership set in case if it is same as root
|
||||
"""
|
||||
repository_paths.owner = _get_owner(repository_paths.root, same=True)
|
||||
object.__setattr__(repository_paths, "owner", _get_owner(repository_paths.root, same=True))
|
||||
mocker.patch.object(RepositoryPaths, "root_owner", (42, 42))
|
||||
chown_mock = mocker.patch("os.chown")
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
from dataclasses import replace
|
||||
|
||||
from ahriman.models.user import User
|
||||
from ahriman.models.user_access import UserAccess
|
||||
|
||||
@ -6,10 +8,10 @@ def test_from_option(user: User) -> None:
|
||||
"""
|
||||
must generate user from options
|
||||
"""
|
||||
user.access = UserAccess.Read
|
||||
user = replace(user, access=UserAccess.Read)
|
||||
assert User.from_option(user.username, user.password) == user
|
||||
# default is read access
|
||||
user.access = UserAccess.Full
|
||||
user = replace(user, access=UserAccess.Full)
|
||||
assert User.from_option(user.username, user.password) != user
|
||||
assert User.from_option(user.username, user.password, user.access) == user
|
||||
|
||||
@ -40,7 +42,7 @@ def test_check_credentials_empty_hash(user: User) -> None:
|
||||
"""
|
||||
current_password = user.password
|
||||
assert not user.check_credentials(current_password, "salt")
|
||||
user.password = ""
|
||||
user = replace(user, password="")
|
||||
assert not user.check_credentials(current_password, "salt")
|
||||
|
||||
|
||||
@ -48,9 +50,9 @@ def test_hash_password_empty_hash(user: User) -> None:
|
||||
"""
|
||||
must return empty string after hash in case if password not set
|
||||
"""
|
||||
user.password = ""
|
||||
user = replace(user, password="")
|
||||
assert user.hash_password("salt") == user
|
||||
user.password = None
|
||||
user = replace(user, password=None)
|
||||
assert user.hash_password("salt") == user
|
||||
|
||||
|
||||
@ -71,7 +73,7 @@ def test_verify_access_read(user: User) -> None:
|
||||
"""
|
||||
user with read access must be able to only request read
|
||||
"""
|
||||
user.access = UserAccess.Read
|
||||
user = replace(user, access=UserAccess.Read)
|
||||
assert user.verify_access(UserAccess.Read)
|
||||
assert not user.verify_access(UserAccess.Full)
|
||||
|
||||
@ -80,7 +82,7 @@ def test_verify_access_write(user: User) -> None:
|
||||
"""
|
||||
user with write access must be able to do anything
|
||||
"""
|
||||
user.access = UserAccess.Full
|
||||
user = replace(user, access=UserAccess.Full)
|
||||
assert user.verify_access(UserAccess.Read)
|
||||
assert user.verify_access(UserAccess.Full)
|
||||
|
||||
|
@ -13,7 +13,7 @@ def test_from_identity_expired(user_identity: UserIdentity) -> None:
|
||||
"""
|
||||
must construct None from expired identity
|
||||
"""
|
||||
user_identity.expire_at -= 60
|
||||
user_identity = UserIdentity(username=user_identity.username, expire_at=user_identity.expire_at - 60)
|
||||
assert UserIdentity.from_identity(f"{user_identity.username} {user_identity.expire_at}") is None
|
||||
|
||||
|
||||
@ -53,7 +53,7 @@ def test_is_expired(user_identity: UserIdentity) -> None:
|
||||
"""
|
||||
assert not user_identity.is_expired()
|
||||
|
||||
user_identity.expire_at -= 60
|
||||
user_identity = UserIdentity(username=user_identity.username, expire_at=user_identity.expire_at - 60)
|
||||
assert user_identity.is_expired()
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user