2021-07-11 00:58:28 +02:00
|
|
|
from unittest.mock import call, patch
|
2021-07-06 18:06:54 +02:00
|
|
|
|
2021-12-20 22:21:58 +01:00
|
|
|
import pytest
|
|
|
|
|
2021-07-06 18:06:54 +02:00
|
|
|
import spoc
|
|
|
|
|
2021-07-11 00:58:28 +02:00
|
|
|
def test_apperror():
|
|
|
|
exception = spoc.AppError('someapp')
|
2021-07-06 18:06:54 +02:00
|
|
|
|
2021-07-11 00:58:28 +02:00
|
|
|
assert exception.app_name == 'someapp'
|
2021-07-06 18:06:54 +02:00
|
|
|
|
2021-07-11 00:58:28 +02:00
|
|
|
def test_appalreadyinstallederror():
|
|
|
|
exception = spoc.AppAlreadyInstalledError('someapp')
|
|
|
|
|
|
|
|
assert exception.app_name == 'someapp'
|
|
|
|
assert isinstance(exception, spoc.AppError)
|
|
|
|
|
|
|
|
def test_appnotinstallederror():
|
|
|
|
exception = spoc.AppNotInstalledError('someapp')
|
|
|
|
|
|
|
|
assert exception.app_name == 'someapp'
|
|
|
|
assert isinstance(exception, spoc.AppError)
|
|
|
|
|
|
|
|
def test_appnotinrepoerror():
|
|
|
|
exception = spoc.AppNotInRepoError('someapp')
|
|
|
|
|
|
|
|
assert exception.app_name == 'someapp'
|
|
|
|
assert isinstance(exception, spoc.AppError)
|
|
|
|
|
|
|
|
def test_appnotupdateableerror():
|
|
|
|
exception = spoc.AppNotUpdateableError('someapp')
|
|
|
|
|
|
|
|
assert exception.app_name == 'someapp'
|
|
|
|
assert isinstance(exception, spoc.AppError)
|
|
|
|
|
|
|
|
@patch('spoc.podman.get_apps', return_value={'someapp': '0.2', 'anotherapp': '0.1'})
|
|
|
|
def test_list_installed(get_apps):
|
|
|
|
apps = spoc.list_installed()
|
2021-07-06 18:06:54 +02:00
|
|
|
|
|
|
|
get_apps.assert_called_once()
|
|
|
|
|
2021-07-11 00:58:28 +02:00
|
|
|
assert apps == {'anotherapp': '0.1', 'someapp': '0.2'}
|
2021-07-06 18:06:54 +02:00
|
|
|
|
2021-07-11 00:58:28 +02:00
|
|
|
@patch('spoc.repo.get_apps',
|
|
|
|
return_value={'someapp': {'version': '0.2'}, 'anotherapp': {'version': '0.1'}})
|
|
|
|
def test_list_online(get_apps):
|
|
|
|
apps = spoc.list_online()
|
2021-07-06 18:06:54 +02:00
|
|
|
|
|
|
|
get_apps.assert_called_once()
|
|
|
|
|
2021-07-11 00:58:28 +02:00
|
|
|
assert apps == {'anotherapp': '0.1', 'someapp': '0.2'}
|
|
|
|
|
2021-07-06 18:06:54 +02:00
|
|
|
@patch('spoc.repo.get_apps',
|
|
|
|
return_value={'someapp': {'version': '0.2'}, 'anotherapp': {'version': '0.1'}})
|
|
|
|
@patch('spoc.podman.get_apps', return_value={'someapp': '0.1'})
|
2021-07-11 00:58:28 +02:00
|
|
|
def test_list_updates(podman_get_apps, repo_get_apps):
|
|
|
|
apps = spoc.list_updates()
|
2021-07-06 18:06:54 +02:00
|
|
|
|
|
|
|
repo_get_apps.assert_called_once()
|
|
|
|
podman_get_apps.assert_called_once()
|
|
|
|
|
2021-07-11 00:58:28 +02:00
|
|
|
assert apps == {'someapp': '0.1 -> 0.2'}
|
|
|
|
|
|
|
|
@patch('spoc.repo.get_apps', return_value={'someapp': {'version': '0.1'}})
|
|
|
|
@patch('spoc.podman.get_apps', return_value={})
|
|
|
|
@patch('spoc.app.install')
|
|
|
|
def test_install(app_install, podman_get_apps, repo_get_apps):
|
|
|
|
spoc.install.__wrapped__('someapp')
|
|
|
|
#spoc.install('someapp')
|
2021-07-06 18:06:54 +02:00
|
|
|
|
2021-07-11 00:58:28 +02:00
|
|
|
podman_get_apps.assert_called_once()
|
|
|
|
repo_get_apps.assert_called_once()
|
|
|
|
app_install.assert_called_once_with('someapp')
|
2021-07-06 18:06:54 +02:00
|
|
|
|
2021-07-11 00:58:28 +02:00
|
|
|
@patch('spoc.repo.get_apps', return_value={'someapp': {'version': '0.1'}})
|
|
|
|
@patch('spoc.podman.get_apps', return_value={'someapp': '0.1'})
|
|
|
|
@patch('spoc.app.install')
|
|
|
|
def test_install_already_installed(app_install, podman_get_apps, repo_get_apps):
|
|
|
|
with pytest.raises(spoc.AppAlreadyInstalledError):
|
|
|
|
spoc.install.__wrapped__('someapp')
|
2021-07-06 18:06:54 +02:00
|
|
|
|
2021-07-11 00:58:28 +02:00
|
|
|
podman_get_apps.assert_called_once()
|
|
|
|
repo_get_apps.assert_not_called()
|
|
|
|
app_install.assert_not_called()
|
2021-07-06 18:06:54 +02:00
|
|
|
|
2021-07-11 00:58:28 +02:00
|
|
|
@patch('spoc.repo.get_apps', return_value={})
|
|
|
|
@patch('spoc.podman.get_apps', return_value={})
|
2021-07-06 18:06:54 +02:00
|
|
|
@patch('spoc.app.install')
|
2021-07-11 00:58:28 +02:00
|
|
|
def test_install_not_in_repo(app_install, podman_get_apps, repo_get_apps):
|
|
|
|
with pytest.raises(spoc.AppNotInRepoError):
|
|
|
|
spoc.install.__wrapped__('someapp')
|
2021-07-06 18:06:54 +02:00
|
|
|
|
2021-07-11 00:58:28 +02:00
|
|
|
podman_get_apps.assert_called_once()
|
|
|
|
repo_get_apps.assert_called_once()
|
|
|
|
app_install.assert_not_called()
|
2021-07-06 18:06:54 +02:00
|
|
|
|
2021-07-11 00:58:28 +02:00
|
|
|
@patch('spoc.list_updates', return_value={'someapp': '0.1 -> 0.2'})
|
|
|
|
@patch('spoc.podman.get_apps', return_value={'someapp': '0.1'})
|
2021-07-06 18:06:54 +02:00
|
|
|
@patch('spoc.app.update')
|
2021-07-11 00:58:28 +02:00
|
|
|
def test_update(app_update, podman_get_apps, list_updates):
|
|
|
|
spoc.update.__wrapped__('someapp')
|
2021-07-06 18:06:54 +02:00
|
|
|
|
2021-07-11 00:58:28 +02:00
|
|
|
podman_get_apps.assert_called_once()
|
|
|
|
list_updates.assert_called_once()
|
2021-07-06 18:06:54 +02:00
|
|
|
app_update.assert_called_once_with('someapp')
|
|
|
|
|
2021-07-11 00:58:28 +02:00
|
|
|
@patch('spoc.list_updates', return_value={})
|
|
|
|
@patch('spoc.podman.get_apps', return_value={})
|
|
|
|
@patch('spoc.app.update')
|
|
|
|
def test_update_not_installed(app_update, podman_get_apps, list_updates):
|
|
|
|
with pytest.raises(spoc.AppNotInstalledError):
|
|
|
|
spoc.update.__wrapped__('someapp')
|
|
|
|
|
|
|
|
podman_get_apps.assert_called_once()
|
|
|
|
list_updates.assert_not_called()
|
|
|
|
app_update.assert_not_called()
|
|
|
|
|
|
|
|
@patch('spoc.list_updates', return_value={})
|
|
|
|
@patch('spoc.podman.get_apps', return_value={'someapp': '0.1'})
|
|
|
|
@patch('spoc.app.update')
|
|
|
|
def test_update_not_updateable(app_update, podman_get_apps, list_updates):
|
|
|
|
with pytest.raises(spoc.AppNotUpdateableError):
|
|
|
|
spoc.update.__wrapped__('someapp')
|
|
|
|
|
|
|
|
podman_get_apps.assert_called_once()
|
|
|
|
list_updates.assert_called_once()
|
|
|
|
app_update.assert_not_called()
|
|
|
|
|
|
|
|
@patch('spoc.podman.get_apps', return_value={'someapp': '0.1'})
|
2021-07-06 18:06:54 +02:00
|
|
|
@patch('spoc.app.uninstall')
|
2021-07-11 00:58:28 +02:00
|
|
|
def test_uninstall(app_uninstall, podman_get_apps):
|
|
|
|
spoc.uninstall.__wrapped__('someapp')
|
2021-07-06 18:06:54 +02:00
|
|
|
|
2021-07-11 00:58:28 +02:00
|
|
|
podman_get_apps.assert_called_once()
|
2021-07-06 18:06:54 +02:00
|
|
|
app_uninstall.assert_called_once_with('someapp')
|
|
|
|
|
2021-07-11 00:58:28 +02:00
|
|
|
@patch('spoc.podman.get_apps', return_value={})
|
|
|
|
@patch('spoc.app.uninstall')
|
|
|
|
def test_uninstall_not_installed(app_uninstall, podman_get_apps):
|
|
|
|
with pytest.raises(spoc.AppNotInstalledError):
|
|
|
|
spoc.uninstall.__wrapped__('someapp')
|
|
|
|
|
|
|
|
podman_get_apps.assert_called_once()
|
|
|
|
app_uninstall.assert_not_called()
|
|
|
|
|
|
|
|
@patch('spoc.podman.get_apps', return_value={'someapp': '0.1'})
|
2021-07-06 18:06:54 +02:00
|
|
|
@patch('spoc.podman.start_pod')
|
2021-07-11 00:58:28 +02:00
|
|
|
def test_start(start_pod, podman_get_apps):
|
|
|
|
spoc.start.__wrapped__('someapp')
|
2021-07-06 18:06:54 +02:00
|
|
|
|
2021-07-11 00:58:28 +02:00
|
|
|
podman_get_apps.assert_called_once()
|
2021-07-06 18:06:54 +02:00
|
|
|
start_pod.assert_called_once_with('someapp')
|
|
|
|
|
2021-07-11 00:58:28 +02:00
|
|
|
@patch('spoc.podman.get_apps', return_value={})
|
|
|
|
@patch('spoc.podman.start_pod')
|
|
|
|
def test_start_not_installed(start_pod, podman_get_apps):
|
|
|
|
with pytest.raises(spoc.AppNotInstalledError):
|
|
|
|
spoc.start.__wrapped__('someapp')
|
|
|
|
|
|
|
|
podman_get_apps.assert_called_once()
|
|
|
|
start_pod.assert_not_called()
|
|
|
|
|
|
|
|
@patch('spoc.podman.get_apps', return_value={'someapp': '0.1'})
|
2021-07-06 18:06:54 +02:00
|
|
|
@patch('spoc.podman.stop_pod')
|
2021-07-11 00:58:28 +02:00
|
|
|
def test_stop(stop_pod, podman_get_apps):
|
|
|
|
spoc.stop.__wrapped__('someapp')
|
2021-07-06 18:06:54 +02:00
|
|
|
|
2021-07-11 00:58:28 +02:00
|
|
|
podman_get_apps.assert_called_once()
|
2021-07-06 18:06:54 +02:00
|
|
|
stop_pod.assert_called_once_with('someapp')
|
|
|
|
|
2021-07-11 00:58:28 +02:00
|
|
|
@patch('spoc.podman.get_apps', return_value={})
|
|
|
|
@patch('spoc.podman.stop_pod')
|
|
|
|
def test_stop_not_installed(stop_pod, podman_get_apps):
|
|
|
|
with pytest.raises(spoc.AppNotInstalledError):
|
|
|
|
spoc.stop.__wrapped__('someapp')
|
|
|
|
|
|
|
|
podman_get_apps.assert_called_once()
|
|
|
|
stop_pod.assert_not_called()
|
|
|
|
|
|
|
|
@patch('spoc.podman.get_apps', return_value={'someapp': '0.1'})
|
2021-07-06 18:06:54 +02:00
|
|
|
@patch('spoc.podman.get_pod_status', return_value='RESULT')
|
2021-07-11 00:58:28 +02:00
|
|
|
def test_status(get_pod_status, podman_get_apps):
|
|
|
|
status = spoc.status('someapp')
|
2021-07-06 18:06:54 +02:00
|
|
|
|
2021-07-11 00:58:28 +02:00
|
|
|
podman_get_apps.assert_called_once()
|
2021-07-06 18:06:54 +02:00
|
|
|
get_pod_status.assert_called_once_with('someapp')
|
2021-07-11 00:58:28 +02:00
|
|
|
assert status == 'RESULT'
|
|
|
|
|
2021-07-11 16:11:57 +02:00
|
|
|
@patch('spoc.podman.get_apps')
|
|
|
|
@patch('spoc.podman.get_pod_status', return_value='RESULT')
|
|
|
|
def test_status_all(get_pod_status, podman_get_apps):
|
|
|
|
status = spoc.status()
|
|
|
|
|
|
|
|
podman_get_apps.assert_not_called()
|
|
|
|
get_pod_status.assert_called_once_with(None)
|
|
|
|
assert status == 'RESULT'
|
|
|
|
|
2021-07-11 00:58:28 +02:00
|
|
|
@patch('spoc.podman.get_apps', return_value={})
|
|
|
|
@patch('spoc.podman.get_pod_status')
|
|
|
|
def test_status_not_installed(get_pod_status, podman_get_apps):
|
|
|
|
with pytest.raises(spoc.AppNotInstalledError):
|
|
|
|
spoc.status('someapp')
|
|
|
|
|
|
|
|
podman_get_apps.assert_called_once()
|
|
|
|
get_pod_status.assert_not_called()
|
|
|
|
|
|
|
|
@patch('spoc.podman.get_apps', return_value={'someapp': '0.1'})
|
2021-07-06 18:06:54 +02:00
|
|
|
@patch('spoc.autostart.set_app')
|
2021-07-11 00:58:28 +02:00
|
|
|
def test_set_autostart(set_app, podman_get_apps):
|
|
|
|
spoc.set_autostart.__wrapped__('someapp', True)
|
2021-07-06 18:06:54 +02:00
|
|
|
|
2021-07-11 00:58:28 +02:00
|
|
|
podman_get_apps.assert_called_once()
|
|
|
|
set_app.assert_called_once_with('someapp', True)
|
|
|
|
|
|
|
|
@patch('spoc.podman.get_apps', return_value={})
|
|
|
|
@patch('spoc.autostart.set_app')
|
|
|
|
def test_set_autostart_not_installed(set_app, podman_get_apps):
|
|
|
|
with pytest.raises(spoc.AppNotInstalledError):
|
|
|
|
spoc.set_autostart.__wrapped__('someapp', True)
|
|
|
|
|
|
|
|
podman_get_apps.assert_called_once()
|
|
|
|
set_app.assert_not_called()
|
2021-07-06 18:06:54 +02:00
|
|
|
|
|
|
|
@patch('spoc.autostart.get_apps', return_value={'someapp', 'anotherapp'})
|
|
|
|
@patch('spoc.podman.start_pod')
|
|
|
|
def test_start_autostarted(start_pod, get_apps):
|
2021-07-11 00:58:28 +02:00
|
|
|
spoc.start_autostarted.__wrapped__()
|
2021-07-06 18:06:54 +02:00
|
|
|
|
|
|
|
get_apps.assert_called_once()
|
|
|
|
start_pod.assert_has_calls([
|
|
|
|
call('someapp'),
|
|
|
|
call('anotherapp'),
|
|
|
|
], any_order=True)
|
|
|
|
|
|
|
|
@patch('spoc.podman.get_apps', return_value={'someapp': '0.1', 'anotherapp': '0.1'})
|
|
|
|
@patch('spoc.podman.stop_pod')
|
|
|
|
def test_stop_all(stop_pod, get_apps):
|
2021-07-11 00:58:28 +02:00
|
|
|
spoc.stop_all.__wrapped__()
|
2021-07-06 18:06:54 +02:00
|
|
|
|
|
|
|
get_apps.assert_called_once()
|
|
|
|
stop_pod.assert_has_calls([
|
|
|
|
call('someapp'),
|
|
|
|
call('anotherapp'),
|
|
|
|
], any_order=True)
|
|
|
|
|
2021-07-11 00:58:28 +02:00
|
|
|
@patch('spoc.config.write_auth')
|
|
|
|
@patch('spoc.repo.load')
|
|
|
|
def test_login(repo_load, write_auth):
|
|
|
|
spoc.login.__wrapped__('somehost', 'someuser', 'somepass')
|
2021-07-06 18:06:54 +02:00
|
|
|
|
2021-07-11 00:58:28 +02:00
|
|
|
write_auth.assert_called_once_with('somehost', 'someuser', 'somepass')
|
|
|
|
repo_load.assert_called_once_with(force=True)
|
2021-07-06 18:06:54 +02:00
|
|
|
|
2021-07-11 00:58:28 +02:00
|
|
|
@patch('spoc.podman.prune')
|
|
|
|
def test_prune(prune):
|
|
|
|
spoc.prune.__wrapped__()
|
2021-07-06 18:06:54 +02:00
|
|
|
|
|
|
|
prune.assert_called_once()
|