2021-10-12 16:24:43 +02:00
|
|
|
import sys
|
2020-07-20 13:56:18 +02:00
|
|
|
import pytest
|
2021-10-12 16:24:43 +02:00
|
|
|
from unittest.mock import Mock
|
2020-07-20 13:56:18 +02:00
|
|
|
|
2021-10-12 16:24:43 +02:00
|
|
|
import core.config
|
|
|
|
|
|
|
|
sys.modules['libvirt'] = Mock()
|
|
|
|
|
|
|
|
import modules.contrib.libvirtvms
|
|
|
|
|
|
|
|
def build_module():
|
|
|
|
return modules.contrib.libvirtvms.Module(
|
|
|
|
config=core.config.Config([]),
|
|
|
|
theme=None
|
|
|
|
)
|
2020-07-20 13:56:18 +02:00
|
|
|
|
|
|
|
def test_load_module():
|
|
|
|
__import__("modules.contrib.libvirtvms")
|
|
|
|
|
2021-10-12 16:24:43 +02:00
|
|
|
def test_input_registration(mocker):
|
|
|
|
input_register = mocker.patch('core.input.register')
|
|
|
|
|
|
|
|
module = build_module()
|
|
|
|
|
|
|
|
input_register.assert_called_with(
|
|
|
|
module,
|
|
|
|
button=core.input.LEFT_MOUSE,
|
|
|
|
cmd="virt-manager"
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_status_failed(mocker):
|
|
|
|
mocker.patch('libvirt.openReadOnly', return_value=None)
|
|
|
|
|
|
|
|
module = build_module()
|
|
|
|
status = module.status(None)
|
|
|
|
|
|
|
|
assert status == "Failed to open connection to the hypervisor"
|
|
|
|
|
|
|
|
def test_status(mocker):
|
|
|
|
virtMock = mocker.Mock()
|
|
|
|
virtMock.numOfDomains = mocker.Mock(return_value=10)
|
|
|
|
|
|
|
|
mocker.patch('libvirt.openReadOnly', return_value=virtMock)
|
|
|
|
|
|
|
|
module = build_module()
|
|
|
|
status = module.status(None)
|
|
|
|
|
|
|
|
assert status == "VMs 10"
|