def test_software_system_adding_container_with_existing_parent_fails(
    model_with_system: MockModel,
):
    """Check that adding a container with a (different) parent fails."""
    empty_system = model_with_system.empty_system
    system2 = SoftwareSystem(name="System 2", description="Description")
    system2.set_model(empty_system.model)

    container = empty_system.add_container(name="Container", description="Description")
    with pytest.raises(ValueError, match="Container with name .* already has parent"):
        system2 += container
class MockModel:
    """Implement a mock model for testing."""
    def __init__(self):
        """Set up an empty system for testing."""
        self.empty_system = SoftwareSystem(name="Sys")
        self.empty_system.set_model(self)

    def __iadd__(self, container):
        """Simulate the model assigning IDs to new elements."""
        if not container.id:
            container.id = "id"
        container.set_model(self)
        return self
예제 #3
0
 def add_software_system(self,
                         name,
                         description,
                         location=Location.UNSPECIFIED):
     if self.get_software_system_with_name(name) is not None:
         raise ValueError(
             "A software system named {} already exists".format(name))
     software_system = SoftwareSystem()
     software_system.set_location(location)
     software_system.set_name(name)
     software_system.set_description(description)
     self._software_systems.add(software_system)
     software_system.set_id(self._id_generator.generate_id(software_system))
     self._add_element_to_internal_structures(software_system)
     return software_system
def test_software_system_serialisation(model_with_system: MockModel):
    """Test systems are deserialised correctly."""
    empty_system = model_with_system.empty_system
    empty_system.add_container(name="Test", description="Description")

    system_io = SoftwareSystemIO.from_orm(empty_system)

    new_system = SoftwareSystem.hydrate(system_io, model_with_system)
    assert new_system.name == "Sys"
    assert len(new_system.containers) == 1
    container = next(iter(new_system.containers))
    assert container.name == "Test"
    assert container.parent is new_system
def test_software_system_init(attributes):
    """Expect proper initialization from arguments."""
    system = SoftwareSystem(**attributes)
    for attr, expected in attributes.items():
        assert getattr(system, attr) == expected
 def __init__(self):
     """Set up an empty system for testing."""
     self.empty_system = SoftwareSystem(name="Sys")
     self.empty_system.set_model(self)