mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-07-29 13:49:57 +00:00
port part of settings to database (#54)
This commit is contained in:
34
tests/ahriman/models/test_migration.py
Normal file
34
tests/ahriman/models/test_migration.py
Normal file
@ -0,0 +1,34 @@
|
||||
import pytest
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.core.exceptions import MigrationError
|
||||
from ahriman.models.migration_result import MigrationResult
|
||||
|
||||
|
||||
def test_is_outdated() -> None:
|
||||
"""
|
||||
must return False for outdated schema
|
||||
"""
|
||||
assert MigrationResult(old_version=0, new_version=1).is_outdated
|
||||
assert not MigrationResult(old_version=1, new_version=1).is_outdated
|
||||
|
||||
|
||||
def test_is_outdated_validation(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must call validation before version check
|
||||
"""
|
||||
validate_mock = mocker.patch("ahriman.models.migration_result.MigrationResult.validate")
|
||||
assert MigrationResult(old_version=0, new_version=1).is_outdated
|
||||
validate_mock.assert_called_once_with()
|
||||
|
||||
|
||||
def test_validate() -> None:
|
||||
"""
|
||||
must raise exception on invalid migration versions
|
||||
"""
|
||||
with pytest.raises(MigrationError):
|
||||
MigrationResult(old_version=-1, new_version=0).validate()
|
||||
|
||||
with pytest.raises(MigrationError):
|
||||
MigrationResult(old_version=1, new_version=0).validate()
|
0
tests/ahriman/models/test_migration_result.py
Normal file
0
tests/ahriman/models/test_migration_result.py
Normal file
@ -44,3 +44,10 @@ def test_from_package(package_description_ahriman: PackageDescription,
|
||||
package_description = PackageDescription.from_package(pyalpm_package_description_ahriman,
|
||||
package_description_ahriman.filepath)
|
||||
assert package_description_ahriman == package_description
|
||||
|
||||
|
||||
def test_from_json_view(package_description_ahriman: PackageDescription) -> None:
|
||||
"""
|
||||
must generate same description from json view
|
||||
"""
|
||||
assert PackageDescription.from_json(package_description_ahriman.view()) == package_description_ahriman
|
||||
|
@ -111,33 +111,6 @@ def test_chown_invalid_path(repository_paths: RepositoryPaths) -> None:
|
||||
repository_paths.chown(repository_paths.root.parent)
|
||||
|
||||
|
||||
def test_manual_for(repository_paths: RepositoryPaths, package_ahriman: Package) -> None:
|
||||
"""
|
||||
must return correct path for manual directory
|
||||
"""
|
||||
path = repository_paths.manual_for(package_ahriman.base)
|
||||
assert path.name == package_ahriman.base
|
||||
assert path.parent == repository_paths.manual
|
||||
|
||||
|
||||
def test_patches_for(repository_paths: RepositoryPaths, package_ahriman: Package) -> None:
|
||||
"""
|
||||
must return correct path for patches directory
|
||||
"""
|
||||
path = repository_paths.patches_for(package_ahriman.base)
|
||||
assert path.name == package_ahriman.base
|
||||
assert path.parent == repository_paths.patches
|
||||
|
||||
|
||||
def test_sources_for(repository_paths: RepositoryPaths, package_ahriman: Package) -> None:
|
||||
"""
|
||||
must return correct path for sources directory
|
||||
"""
|
||||
path = repository_paths.sources_for(package_ahriman.base)
|
||||
assert path.name == package_ahriman.base
|
||||
assert path.parent == repository_paths.sources
|
||||
|
||||
|
||||
def test_tree_clear(repository_paths: RepositoryPaths, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must remove any package related files
|
||||
|
@ -27,7 +27,7 @@ def test_check_credentials_hash_password(user: User) -> None:
|
||||
must generate and validate user password
|
||||
"""
|
||||
current_password = user.password
|
||||
user.password = user.hash_password("salt")
|
||||
user = user.hash_password("salt")
|
||||
assert user.check_credentials(current_password, "salt")
|
||||
assert not user.check_credentials(current_password, "salt1")
|
||||
assert not user.check_credentials(user.password, "salt")
|
||||
@ -48,9 +48,9 @@ def test_hash_password_empty_hash(user: User) -> None:
|
||||
must return empty string after hash in case if password not set
|
||||
"""
|
||||
user.password = ""
|
||||
assert user.hash_password("salt") == ""
|
||||
assert user.hash_password("salt") == user
|
||||
user.password = None
|
||||
assert user.hash_password("salt") == ""
|
||||
assert user.hash_password("salt") == user
|
||||
|
||||
|
||||
def test_generate_password() -> None:
|
||||
|
Reference in New Issue
Block a user