Ejemplo n.º 1
0
def test_container_instance_tags(model_with_container):
    """Check default tags."""
    instance = ContainerInstance(
        container=model_with_container.mock_container, instance_id="11"
    )
    assert Tags.ELEMENT in instance.tags
    assert Tags.CONTAINER_INSTANCE in instance.tags
Ejemplo n.º 2
0
def test_container_instance_name_is_container_name(model_with_container):
    """Ensure container instance takes its name from its container."""
    io = ContainerInstanceIO(container_id="19",
                             instance_id=3,
                             environment="Live")

    instance = ContainerInstance.hydrate(io, model_with_container, parent=None)

    assert instance.name == "Mock Container"
Ejemplo n.º 3
0
def test_container_instance_hydration_retrieves_container_from_id(
        model_with_container):
    """Check that the container instance is retrieved from the model on hydration."""
    io = ContainerInstanceIO(container_id="19",
                             instance_id=3,
                             environment="Live")

    instance = ContainerInstance.hydrate(io, model_with_container, parent=None)

    assert instance.instance_id == 3
    assert instance.environment == "Live"
    assert instance.container is model_with_container.mock_container
    assert instance.container_id == "19"
Ejemplo n.º 4
0
def test_container_instance_hyrdates_http_health_checks(model_with_container):
    """Check that health checks are hydrated into the ContainerInstance."""
    health_check_io = HTTPHealthCheckIO(name="name", url="http://a.b.com")
    io = ContainerInstanceIO(
        container_id="19",
        instance_id=3,
        environment="Live",
        health_checks=[health_check_io],
    )

    instance = ContainerInstance.hydrate(io, model_with_container, parent=None)

    assert len(instance.health_checks) == 1
    assert list(instance.health_checks)[0].name == "name"
Ejemplo n.º 5
0
def test_container_instance_serialization(model_with_container):
    """Test that container instances serialise properly."""
    health_check = HTTPHealthCheck(name="health", url="http://a.b.com")
    instance = ContainerInstance(
        container=model_with_container.mock_container,
        instance_id=7,
        health_checks=[health_check],
    )

    io = ContainerInstanceIO.from_orm(instance)

    assert io.container_id == "19"
    assert io.instance_id == 7
    assert len(io.health_checks) == 1
    assert io.health_checks[0].name == "health"
Ejemplo n.º 6
0
def test_deployment_view_find_deployment_node(empty_workspace: Workspace):
    """Test _find_deployment_node."""
    model = empty_workspace.model
    software_system = model.add_software_system("Software System")
    container1 = software_system.add_container("Container 1")
    node1 = model.add_deployment_node("Deployment Node 1")
    container_instance1 = node1.add_container(container1)
    container2 = software_system.add_container("Container 2")
    container_instance2 = ContainerInstance(container=container2,
                                            instance_id=1)
    # Explicitly we don't add container_instance2 to a deployment node

    deployment_view = empty_workspace.views.create_deployment_view(
        software_system=software_system,
        key="deployment",
        description="Description")
    deployment_view += node1

    assert deployment_view._find_deployment_node(container_instance1) is node1
    assert deployment_view._find_deployment_node(container_instance2) is None
Ejemplo n.º 7
0
def test_container_instance_init(attributes):
    """Expect proper initialization from arguments."""
    instance = ContainerInstance(**attributes)
    for attr, expected in attributes.items():
        assert getattr(instance, attr) == expected
Ejemplo n.º 8
0
 def __iadd__(self, instance: ContainerInstance):
     """Simulate the model assigning IDs to new elements."""
     if not instance.id:
         instance.id = "id"
     instance.set_model(self)
     return self