def test_model_cannot_add_relationship_with_same_id_as_element(empty_model: Model): """Ensure you can't add a relationship with the same ID as an element.""" sys1 = empty_model.add_software_system(name="sys1") sys2 = empty_model.add_software_system(name="sys2") with pytest.raises( ValueError, match="Relationship.* has the same ID as SoftwareSystem.*" ): empty_model.add_relationship(source=sys1, destination=sys2, id=sys1.id)
def test_model_add_relationship_twice_ignored(empty_model: Model): """Ensure that adding an existing relationship to the Model makes no difference.""" sys1 = empty_model.add_software_system(name="sys1") sys2 = empty_model.add_software_system(name="sys2") relationship = empty_model.add_relationship(source=sys1, destination=sys2) assert set(empty_model.get_relationships()) == {relationship} empty_model.add_relationship(relationship) assert set(empty_model.get_relationships()) == {relationship}
def test_model_cannot_add_relationship_with_same_id_as_existing(empty_model: Model): """Ensure you can't add two relationships with the same ID.""" sys1 = empty_model.add_software_system(name="sys1") sys2 = empty_model.add_software_system(name="sys2") empty_model.add_relationship(source=sys1, destination=sys2, id="r1") with pytest.raises( ValueError, match="Relationship.* has the same ID as Relationship.*" ): empty_model.add_relationship(source=sys1, destination=sys2, id="r1")
def test_model_get_relationship_by_id(empty_model: Model): """Test retrieving relationships by their IDs.""" sys1 = empty_model.add_software_system(name="sys1") sys2 = empty_model.add_software_system(name="sys2") relationship = empty_model.add_relationship(source=sys1, destination=sys2, id="r1") assert empty_model.get_relationship("r1") is relationship
def test_adding_relationship_to_model_adds_to_element(): """Ensure relationships are added to elements. Make sure that when a relationship is added via Model.add_relationship it also gets added to the elements. """ model = Model() sys1 = model.add_software_system(name="sys1") sys2 = model.add_software_system(name="sys2") relationship = model.add_relationship(source=sys1, destination=sys2, description="uses") assert sys1.relationships == {relationship} assert set(sys1.get_relationships()) == {relationship} assert set(model.get_relationships()) == {relationship} assert sys2.relationships == set() # relationships only contains outbound assert set(sys2.get_relationships()) == {relationship}