Esempio n. 1
0
def test_deployment_view_name_generation():
    """Test various forms of name are generated correctly."""
    deployment_view = DeploymentView(key="deployment",
                                     description="Description")
    assert deployment_view.name == "Deployment"

    deployment_view = DeploymentView(key="deployment",
                                     description="Description",
                                     environment="Live")
    assert deployment_view.name == "Deployment - Live"

    software_system = SoftwareSystem(name="Software System")
    deployment_view = DeploymentView(key="deployment",
                                     description="Description",
                                     software_system=software_system)
    assert deployment_view.name == "Software System - Deployment"

    software_system = SoftwareSystem(name="Software System")
    deployment_view = DeploymentView(
        key="deployment",
        description="Description",
        software_system=software_system,
        environment="Live",
    )
    assert deployment_view.name == "Software System - Deployment - Live"
Esempio n. 2
0
def test_model_automatically_adds_child_elements(empty_model: Model):
    """Check that adding a parent element to the model also adds its children."""
    system = SoftwareSystem(name="System")
    container = system.add_container(name="Container")

    assert not container.has_model
    empty_model += system
    assert container.has_model
Esempio n. 3
0
def test_deployment_node_add_with_iadd(model_with_node: MockModel):
    """Test adding things to a node using += rather than add_container."""
    node = model_with_node.empty_node
    system = SoftwareSystem(name="system")
    model_with_node += system
    container = Container(name="container")
    system += container
    child_node = DeploymentNode(name="child", environment="Live")
    infra_node = InfrastructureNode(name="infra")

    node += child_node
    assert child_node in node.children
    assert child_node in node.child_elements

    node += system
    assert node.software_system_instances[0].software_system is system
    assert node.software_system_instances[0] in node.child_elements

    child_node += container
    assert child_node.container_instances[0].container is container
    assert child_node.container_instances[0] in child_node.child_elements

    child_node += infra_node
    assert infra_node in child_node.infrastructure_nodes
    assert child_node.infrastructure_nodes[0] in child_node.child_elements
Esempio n. 4
0
def test_model_add_element_with_existing_id_raises_error(empty_model: Model):
    """Test you can't add an element with the same ID as an existing one."""
    system1 = empty_model.add_software_system(name="System")
    system2 = SoftwareSystem(name="System2", id=system1.id)

    with pytest.raises(ValueError, match="The element .* has an existing ID"):
        empty_model += system2
Esempio n. 5
0
def test_model_can_add_elements_with_plusequals(empty_model: Model, ):
    """Ensure passing something other than a Person or SoftwareSystem to += works."""
    sys = SoftwareSystem(name="Sys")
    c = Container(name="C")
    c.parent = sys
    empty_model += c
    assert c in empty_model.get_elements()
Esempio n. 6
0
def test_add_software_system(attributes: dict, model: Model):
    """Expect that a software system can be added to the model."""
    software_system = SoftwareSystem(**attributes)
    model.add_software_system(software_system)
    assert software_system.id == "1"
    assert len(model.software_systems) == 1
    for attr, expected in attributes.items():
        assert getattr(software_system, attr) == expected
def test_tag_order_is_preserved_to_and_from_io(empty_model: Model):
    """Test that when serializing via IO classes or back, tag ordering is preserved."""
    element = empty_model.add_software_system(name="Name", description="Description")
    element.tags.update(["tag3", "tag2", "tag1"])  # Deliberately not ascending

    element_io = SoftwareSystemIO.from_orm(element)
    assert element_io.tags == ["Element", "Software System", "tag3", "tag2", "tag1"]
    assert element_io.dict()["tags"] == "Element,Software System,tag3,tag2,tag1"
    element2 = SoftwareSystem.hydrate(element_io, Model())
    assert list(element2.tags) == ["Element", "Software System", "tag3", "tag2", "tag1"]
def test_constructor_param_validation():
    """Test validation of constructor parameters."""
    system = SoftwareSystem(name="sys1")
    container = Container(name="con1", parent=system)

    view1 = DynamicView(description="Description")
    assert view1.element is None
    view2 = DynamicView(description="Description", element=system)
    assert view2.element is system
    view3 = DynamicView(description="Description", element=container)
    assert view3.element is container
Esempio n. 9
0
def test_model_add_software_system_with_plusequals(empty_model: Model):
    """Check that adding a SoftwareSystem to a Model with += works."""
    sys = SoftwareSystem(name="Sys")
    empty_model += sys
    assert sys in empty_model.software_systems
    assert sys.id != ""