Only test whether setProperty calls setProperty on proper container

It sets up a mock container and records whether setProperty is called on that container. Whether that actually sets the property correctly is up to the instance container.

Contributes to issue CURA-3497.
This commit is contained in:
Ghostkeeper 2017-04-12 09:31:56 +02:00
parent 2161cf9f52
commit 09ab895feb
No known key found for this signature in database
GPG key ID: C5F96EE2BC0F7E75

View file

@ -548,36 +548,32 @@ def test_setPropertyUser(key, property, value, global_stack):
user_changes.getMetaDataEntry = unittest.mock.MagicMock(return_value = "user") user_changes.getMetaDataEntry = unittest.mock.MagicMock(return_value = "user")
global_stack.userChanges = user_changes global_stack.userChanges = user_changes
global_stack.setProperty(key, property, value) global_stack.setProperty(key, property, value) #The actual test.
global_stack.userChanges.setProperty.assert_called_once_with(key, property, value)
global_stack.userChanges.setProperty.assert_called_once_with(key, property, value) #Make sure that the user container gets a setProperty call.
## Tests setting properties on specific containers on the global stack. ## Tests setting properties on specific containers on the global stack.
@pytest.mark.parametrize("target_container", [ @pytest.mark.parametrize("target_container, stack_variable", [
"user", ("user", "userChanges"),
"quality_changes", ("quality_changes", "qualityChanges"),
"quality", ("quality", "quality"),
"material", ("material", "material"),
"variant", ("variant", "variant"),
"definition_changes", ("definition_changes", "definitionChanges")
]) ])
def test_setPropertyOtherContainers(target_container, writable_global_stack): def test_setPropertyOtherContainers(target_container, stack_variable, global_stack):
#Other parameters that don't need to be varied. #Other parameters that don't need to be varied.
key = "layer_height" key = "layer_height"
property = "value" property = "value"
value = 0.1337 value = 0.1337
output_value = 0.1337 #A mock container in the right spot.
container = unittest.mock.MagicMock()
container.getMetaDataEntry = unittest.mock.MagicMock(return_value = target_container)
setattr(global_stack, stack_variable, container) #For instance, set global_stack.qualityChanges = container.
writable_global_stack.setProperty(key, property, value, target_container = target_container) global_stack.setProperty(key, property, value, target_container = target_container) #The actual test.
containers = {
"user": writable_global_stack.userChanges, getattr(global_stack, stack_variable).setProperty.assert_called_once_with(key, property, value) #Make sure that the proper container gets a setProperty call.
"quality_changes": writable_global_stack.qualityChanges,
"quality": writable_global_stack.quality,
"material": writable_global_stack.material,
"variant": writable_global_stack.variant,
"definition_changes": writable_global_stack.definitionChanges,
"definition": writable_global_stack.definition
}
assert containers[target_container].getProperty(key, property) == output_value
## Tests setting qualities by specifying an ID of a quality that exists. ## Tests setting qualities by specifying an ID of a quality that exists.
def test_setQualityByIdExists(global_stack, container_registry): def test_setQualityByIdExists(global_stack, container_registry):