|
| 1 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 2 | +# you may not use this file except in compliance with the License. |
| 3 | +# You may obtain a copy of the License at |
| 4 | +# |
| 5 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +# |
| 7 | +# Unless required by applicable law or agreed to in writing, software |
| 8 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | +# See the License for the specific language governing permissions and |
| 11 | +# limitations under the License. |
| 12 | + |
| 13 | +""" |
| 14 | +Ensure that relationships in Elements and in the Model are consistent. |
| 15 | +
|
| 16 | +See https://github.com/Midnighter/structurizr-python/issues/31. |
| 17 | +""" |
| 18 | + |
| 19 | +import pytest |
| 20 | + |
| 21 | +from structurizr.model import Model |
| 22 | + |
| 23 | + |
| 24 | +@pytest.mark.skip(reason="To be fixed - issue #31") |
| 25 | +def test_adding_relationship_to_element_adds_to_model(): |
| 26 | + """ |
| 27 | + Make sure that when a relationship is added via Element.add_relationship it also |
| 28 | + gets added to the model and to the other element. |
| 29 | + """ |
| 30 | + model = Model() |
| 31 | + sys1 = model.add_software_system(name="sys1") |
| 32 | + sys2 = model.add_software_system(name="sys2") |
| 33 | + |
| 34 | + sys1.add_relationship(source=sys1, destination=sys2, description="uses") |
| 35 | + assert len(sys1.relationships) == 1 |
| 36 | + assert len(list(sys1.get_relationships())) == 1 # Currently will fail |
| 37 | + assert len(model.get_relationships()) == 1 # Currently will fail |
| 38 | + assert len(sys2.relationships) == 1 # Currently will fail |
| 39 | + assert len(list(sys2.get_relationships())) == 1 # Currently will fail |
| 40 | + |
| 41 | + |
| 42 | +@pytest.mark.skip(reason="To be fixed - issue #31") |
| 43 | +def test_adding_relationship_via_uses_adds_to_elements(): |
| 44 | + """ |
| 45 | + Make sure that when a relationship is added via StaticStructureElement.uses |
| 46 | + then it is reflected in the Elements. |
| 47 | + """ |
| 48 | + model = Model() |
| 49 | + sys1 = model.add_software_system(name="sys1") |
| 50 | + sys2 = model.add_software_system(name="sys2") |
| 51 | + |
| 52 | + sys1.uses(sys2, "uses") |
| 53 | + assert len(sys1.relationships) == 1 |
| 54 | + assert len(list(sys1.get_relationships())) == 1 |
| 55 | + assert len(model.get_relationships()) == 1 |
| 56 | + assert len(sys2.relationships) == 1 # Currently will fail |
| 57 | + assert len(list(sys2.get_relationships())) == 1 |
0 commit comments