mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-04-22 13:49:39 +08:00

The PrintInformation test wasn't cleaning up after itself correclty. This left some stuff behind that the other tests were using. Since this is bad (as at that point tests can influence other tests), i've fixed that
65 lines
2.5 KiB
Python
65 lines
2.5 KiB
Python
from unittest.mock import MagicMock, PropertyMock
|
|
|
|
import pytest
|
|
|
|
from cura.Machines.Models.DiscoveredPrintersModel import DiscoveredPrintersModel, DiscoveredPrinter
|
|
|
|
|
|
@pytest.fixture()
|
|
def discovered_printer_model(application) -> DiscoveredPrintersModel:
|
|
return DiscoveredPrintersModel(application)
|
|
|
|
@pytest.fixture()
|
|
def discovered_printer() -> DiscoveredPrinter:
|
|
return DiscoveredPrinter("127.0.0.1", "zomg", "yay", None, "bleep", MagicMock())
|
|
|
|
|
|
@pytest.mark.skip # TODO: This has some unknown dependency on the applicaiton / registry, which is hard to patch out. (which doesn't mean we shouldn't fix it!)
|
|
def test_discoveredPrinters(discovered_printer_model):
|
|
mocked_device = MagicMock()
|
|
cluster_size = PropertyMock(return_value = 1)
|
|
type(mocked_device).clusterSize = cluster_size
|
|
|
|
mocked_callback = MagicMock()
|
|
discovered_printer_model.addDiscoveredPrinter("ip", "key", "name", mocked_callback, "machine_type", mocked_device)
|
|
device = discovered_printer_model.discoveredPrinters[0]
|
|
discovered_printer_model.createMachineFromDiscoveredPrinter(device)
|
|
mocked_callback.assert_called_with("key")
|
|
|
|
assert len(discovered_printer_model.discoveredPrinters) == 1
|
|
|
|
discovered_printer_model.discoveredPrintersChanged = MagicMock()
|
|
# Test if removing it works
|
|
discovered_printer_model.removeDiscoveredPrinter("ip")
|
|
assert len(discovered_printer_model.discoveredPrinters) == 0
|
|
assert discovered_printer_model.discoveredPrintersChanged.emit.call_count == 1
|
|
# Removing it again shouldn't cause another signal emit
|
|
discovered_printer_model.removeDiscoveredPrinter("ip")
|
|
assert discovered_printer_model.discoveredPrintersChanged.emit.call_count == 1
|
|
|
|
|
|
test_validate_data_get_set = [
|
|
{"attribute": "name", "value": "zomg"},
|
|
{"attribute": "machineType", "value": "BHDHAHHADAD"},
|
|
]
|
|
|
|
@pytest.mark.parametrize("data", test_validate_data_get_set)
|
|
def test_getAndSet(data, discovered_printer):
|
|
# Attempt to set the value
|
|
# Convert the first letter into a capital
|
|
attribute = list(data["attribute"])
|
|
attribute[0] = attribute[0].capitalize()
|
|
attribute = "".join(attribute)
|
|
|
|
# Attempt to set the value
|
|
getattr(discovered_printer, "set" + attribute)(data["value"])
|
|
|
|
# Ensure that the value got set
|
|
assert getattr(discovered_printer, data["attribute"]) == data["value"]
|
|
|
|
|
|
def test_isHostofGroup(discovered_printer):
|
|
discovered_printer.device.clusterSize = 0
|
|
assert not discovered_printer.isHostOfGroup
|
|
discovered_printer.device.clusterSize = 2
|
|
assert discovered_printer.isHostOfGroup |