mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-08-09 14:55:03 -06:00
Merge branch 'master' of github.com:Ultimaker/Cura into feature_intent
This commit is contained in:
commit
1d9d411732
52 changed files with 773 additions and 289 deletions
|
@ -5,11 +5,14 @@ from unittest.mock import MagicMock
|
|||
import pytest
|
||||
|
||||
from cura.PrinterOutput.Models.PrintJobOutputModel import PrintJobOutputModel
|
||||
from cura.PrinterOutput.Models.PrinterConfigurationModel import PrinterConfigurationModel
|
||||
from cura.PrinterOutput.Models.PrinterOutputModel import PrinterOutputModel
|
||||
from cura.PrinterOutput.Peripheral import Peripheral
|
||||
|
||||
test_validate_data_get_set = [
|
||||
{"attribute": "name", "value": "YAY"},
|
||||
{"attribute": "targetBedTemperature", "value": 192},
|
||||
{"attribute": "cameraUrl", "value": "YAY!"}
|
||||
]
|
||||
|
||||
test_validate_data_get_update = [
|
||||
|
@ -22,6 +25,7 @@ test_validate_data_get_update = [
|
|||
{"attribute": "targetBedTemperature", "value": 9001},
|
||||
{"attribute": "activePrintJob", "value": PrintJobOutputModel(MagicMock())},
|
||||
{"attribute": "state", "value": "BEEPBOOP"},
|
||||
|
||||
]
|
||||
|
||||
|
||||
|
@ -79,3 +83,67 @@ def test_getAndUpdate(data):
|
|||
getattr(model, "update" + attribute)(data["value"])
|
||||
# The signal should not fire again
|
||||
assert signal.emit.call_count == 1
|
||||
|
||||
|
||||
def test_peripherals():
|
||||
model = PrinterOutputModel(MagicMock())
|
||||
model.peripheralsChanged = MagicMock()
|
||||
|
||||
peripheral = MagicMock(spec=Peripheral)
|
||||
peripheral.name = "test"
|
||||
peripheral2 = MagicMock(spec=Peripheral)
|
||||
peripheral2.name = "test2"
|
||||
|
||||
model.addPeripheral(peripheral)
|
||||
assert model.peripheralsChanged.emit.call_count == 1
|
||||
model.addPeripheral(peripheral2)
|
||||
assert model.peripheralsChanged.emit.call_count == 2
|
||||
|
||||
assert model.peripherals == "test, test2"
|
||||
|
||||
model.removePeripheral(peripheral)
|
||||
assert model.peripheralsChanged.emit.call_count == 3
|
||||
assert model.peripherals == "test2"
|
||||
|
||||
|
||||
def test_availableConfigurations_addConfiguration():
|
||||
model = PrinterOutputModel(MagicMock())
|
||||
|
||||
configuration = MagicMock(spec = PrinterConfigurationModel)
|
||||
|
||||
model.addAvailableConfiguration(configuration)
|
||||
assert model.availableConfigurations == [configuration]
|
||||
|
||||
|
||||
def test_availableConfigurations_addConfigTwice():
|
||||
model = PrinterOutputModel(MagicMock())
|
||||
|
||||
configuration = MagicMock(spec=PrinterConfigurationModel)
|
||||
|
||||
model.setAvailableConfigurations([configuration])
|
||||
assert model.availableConfigurations == [configuration]
|
||||
|
||||
# Adding it again should not have any effect
|
||||
model.addAvailableConfiguration(configuration)
|
||||
assert model.availableConfigurations == [configuration]
|
||||
|
||||
|
||||
def test_availableConfigurations_removeConfig():
|
||||
model = PrinterOutputModel(MagicMock())
|
||||
|
||||
configuration = MagicMock(spec=PrinterConfigurationModel)
|
||||
|
||||
model.addAvailableConfiguration(configuration)
|
||||
model.removeAvailableConfiguration(configuration)
|
||||
assert model.availableConfigurations == []
|
||||
|
||||
|
||||
def test_removeAlreadyRemovedConfiguration():
|
||||
model = PrinterOutputModel(MagicMock())
|
||||
|
||||
configuration = MagicMock(spec=PrinterConfigurationModel)
|
||||
model.availableConfigurationsChanged = MagicMock()
|
||||
model.removeAvailableConfiguration(configuration)
|
||||
assert model.availableConfigurationsChanged.emit.call_count == 0
|
||||
assert model.availableConfigurations == []
|
||||
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
from unittest.mock import patch
|
||||
|
||||
from cura.PrinterOutput.Models.ExtruderConfigurationModel import ExtruderConfigurationModel
|
||||
from cura.PrinterOutput.Models.MaterialOutputModel import MaterialOutputModel
|
||||
from cura.PrinterOutput.Models.PrinterConfigurationModel import PrinterConfigurationModel
|
||||
from cura.PrinterOutput.Models.PrinterOutputModel import PrinterOutputModel
|
||||
from cura.PrinterOutput.PrinterOutputDevice import PrinterOutputDevice
|
||||
|
||||
test_validate_data_get_set = [
|
||||
|
@ -8,10 +14,15 @@ test_validate_data_get_set = [
|
|||
{"attribute": "connectionState", "value": 1},
|
||||
]
|
||||
|
||||
@pytest.fixture()
|
||||
def printer_output_device():
|
||||
with patch("UM.Application.Application.getInstance"):
|
||||
return PrinterOutputDevice("whatever")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("data", test_validate_data_get_set)
|
||||
def test_getAndSet(data):
|
||||
model = PrinterOutputDevice("whatever")
|
||||
def test_getAndSet(data, printer_output_device):
|
||||
model = printer_output_device
|
||||
|
||||
# Convert the first letter into a capital
|
||||
attribute = list(data["attribute"])
|
||||
|
@ -35,3 +46,43 @@ def test_getAndSet(data):
|
|||
getattr(model, "set" + attribute)(data["value"])
|
||||
# The signal should not fire again
|
||||
assert signal.emit.call_count == 1
|
||||
|
||||
|
||||
def test_uniqueConfigurations(printer_output_device):
|
||||
printer = PrinterOutputModel(MagicMock())
|
||||
# Add a printer and fire the signal that ensures they get hooked up correctly.
|
||||
printer_output_device._printers = [printer]
|
||||
printer_output_device._onPrintersChanged()
|
||||
|
||||
assert printer_output_device.uniqueConfigurations == []
|
||||
configuration = PrinterConfigurationModel()
|
||||
printer.addAvailableConfiguration(configuration)
|
||||
|
||||
assert printer_output_device.uniqueConfigurations == [configuration]
|
||||
|
||||
# Once the type of printer is set, it's active configuration counts as being set.
|
||||
# In that case, that should also be added to the list of available configurations
|
||||
printer.updateType("blarg!")
|
||||
loaded_material = MaterialOutputModel(guid = "", type = "PLA", color = "Blue", brand = "Generic", name = "Blue PLA")
|
||||
loaded_left_extruder = ExtruderConfigurationModel(0)
|
||||
loaded_left_extruder.setMaterial(loaded_material)
|
||||
loaded_right_extruder = ExtruderConfigurationModel(1)
|
||||
loaded_right_extruder.setMaterial(loaded_material)
|
||||
printer.printerConfiguration.setExtruderConfigurations([loaded_left_extruder, loaded_right_extruder])
|
||||
assert printer_output_device.uniqueConfigurations == [configuration, printer.printerConfiguration]
|
||||
|
||||
|
||||
def test_uniqueConfigurations_empty_is_filtered_out(printer_output_device):
|
||||
printer = PrinterOutputModel(MagicMock())
|
||||
# Add a printer and fire the signal that ensures they get hooked up correctly.
|
||||
printer_output_device._printers = [printer]
|
||||
printer_output_device._onPrintersChanged()
|
||||
|
||||
printer.updateType("blarg!")
|
||||
empty_material = MaterialOutputModel(guid = "", type = "empty", color = "empty", brand = "Generic", name = "Empty")
|
||||
empty_left_extruder = ExtruderConfigurationModel(0)
|
||||
empty_left_extruder.setMaterial(empty_material)
|
||||
empty_right_extruder = ExtruderConfigurationModel(1)
|
||||
empty_right_extruder.setMaterial(empty_material)
|
||||
printer.printerConfiguration.setExtruderConfigurations([empty_left_extruder, empty_right_extruder])
|
||||
assert printer_output_device.uniqueConfigurations == []
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
import webbrowser
|
||||
from datetime import datetime
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import requests
|
||||
|
||||
from PyQt5.QtGui import QDesktopServices
|
||||
|
||||
from UM.Preferences import Preferences
|
||||
from cura.OAuth2.AuthorizationHelpers import AuthorizationHelpers, TOKEN_TIMESTAMP_FORMAT
|
||||
from cura.OAuth2.AuthorizationService import AuthorizationService
|
||||
|
@ -172,12 +173,12 @@ def test_storeAuthData(get_user_profile) -> None:
|
|||
|
||||
@patch.object(LocalAuthorizationServer, "stop")
|
||||
@patch.object(LocalAuthorizationServer, "start")
|
||||
@patch.object(webbrowser, "open_new")
|
||||
def test_localAuthServer(webbrowser_open, start_auth_server, stop_auth_server) -> None:
|
||||
@patch.object(QDesktopServices, "openUrl")
|
||||
def test_localAuthServer(QDesktopServices_openUrl, start_auth_server, stop_auth_server) -> None:
|
||||
preferences = Preferences()
|
||||
authorization_service = AuthorizationService(OAUTH_SETTINGS, preferences)
|
||||
authorization_service.startAuthorizationFlow()
|
||||
assert webbrowser_open.call_count == 1
|
||||
assert QDesktopServices_openUrl.call_count == 1
|
||||
|
||||
# Ensure that the Authorization service tried to start the server.
|
||||
assert start_auth_server.call_count == 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue