mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-07-29 13:49:57 +00:00
add more tests
This commit is contained in:
@ -0,0 +1,16 @@
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.report.html import HTML
|
||||
from ahriman.models.package import Package
|
||||
|
||||
|
||||
def test_generate(configuration: Configuration, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must generate report
|
||||
"""
|
||||
write_mock = mocker.patch("pathlib.Path.write_text")
|
||||
|
||||
report = HTML("x86_64", configuration)
|
||||
report.generate([package_ahriman])
|
||||
write_mock.assert_called_once()
|
||||
|
@ -0,0 +1,27 @@
|
||||
import pytest
|
||||
|
||||
from pathlib import Path
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.exceptions import ReportFailed
|
||||
from ahriman.core.report.report import Report
|
||||
from ahriman.models.report_settings import ReportSettings
|
||||
|
||||
|
||||
def test_report_failure(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must raise ReportFailed on errors
|
||||
"""
|
||||
mocker.patch("ahriman.core.report.html.HTML.generate", side_effect=Exception())
|
||||
with pytest.raises(ReportFailed):
|
||||
Report.run("x86_64", configuration, ReportSettings.HTML.name, Path("path"))
|
||||
|
||||
|
||||
def test_report_html(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must generate html report
|
||||
"""
|
||||
report_mock = mocker.patch("ahriman.core.report.html.HTML.generate")
|
||||
Report.run("x86_64", configuration, ReportSettings.HTML.name, Path("path"))
|
||||
report_mock.assert_called_once()
|
||||
|
@ -0,0 +1,16 @@
|
||||
from pathlib import Path
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.upload.rsync import Rsync
|
||||
|
||||
|
||||
def test_sync(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must run sync command
|
||||
"""
|
||||
check_output_mock = mocker.patch("ahriman.core.upload.rsync.Rsync._check_output")
|
||||
|
||||
upload = Rsync("x86_64", configuration)
|
||||
upload.sync(Path("path"))
|
||||
check_output_mock.assert_called_once()
|
||||
|
@ -0,0 +1,16 @@
|
||||
from pathlib import Path
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.upload.s3 import S3
|
||||
|
||||
|
||||
def test_sync(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must run sync command
|
||||
"""
|
||||
check_output_mock = mocker.patch("ahriman.core.upload.s3.S3._check_output")
|
||||
|
||||
upload = S3("x86_64", configuration)
|
||||
upload.sync(Path("path"))
|
||||
check_output_mock.assert_called_once()
|
||||
|
@ -0,0 +1,36 @@
|
||||
import pytest
|
||||
|
||||
from pathlib import Path
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.exceptions import SyncFailed
|
||||
from ahriman.core.upload.upload import Upload
|
||||
from ahriman.models.upload_settings import UploadSettings
|
||||
|
||||
|
||||
def test_upload_failure(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must raise SyncFailed on errors
|
||||
"""
|
||||
mocker.patch("ahriman.core.upload.rsync.Rsync.sync", side_effect=Exception())
|
||||
with pytest.raises(SyncFailed):
|
||||
Upload.run("x86_64", configuration, UploadSettings.Rsync.name, Path("path"))
|
||||
|
||||
|
||||
def test_upload_rsync(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must upload via rsync
|
||||
"""
|
||||
upload_mock = mocker.patch("ahriman.core.upload.rsync.Rsync.sync")
|
||||
Upload.run("x86_64", configuration, UploadSettings.Rsync.name, Path("path"))
|
||||
upload_mock.assert_called_once()
|
||||
|
||||
|
||||
def test_upload_s3(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must upload via s3
|
||||
"""
|
||||
upload_mock = mocker.patch("ahriman.core.upload.s3.S3.sync")
|
||||
Upload.run("x86_64", configuration, UploadSettings.S3.name, Path("path"))
|
||||
upload_mock.assert_called_once()
|
||||
|
Reference in New Issue
Block a user