Midnighter / structurizr-python

A Python 3 port of Simon Brown's Structurizr diagrams-as-code architecture description tool.
https://structurizr.com/
Apache License 2.0
65 stars 16 forks source link

Constrain elements that can be added to each view type #79

Open yt-ms opened 3 years ago

yt-ms commented 3 years ago

Checklist

Is your feature related to a problem? Please describe it.

In the Java implementation, each view class overrides checkElementCanBeAdded which is defined abstractly in View. Without having this, it is possible to add elements to a view that then would not be supported in Structurizr itself.

Describe the solution you would like.

Mirror the Java implementation with an abstract check_element_can_be_added method in View which each subtype overrides.

Additional context

from structurizr import Workspace
workspace = Workspace(name="Test", description="Test")
system = workspace.model.add_software_system(name="System 1")
container = system.add_container(name="Container 1")
view = workspace.views.create_container_view(key="con1", description="test", software_system=system)

# This should fail but doesn't
view.add(system)
yt-ms commented 3 years ago

I've added an xfail test in test_container_view to demonstrate this issue in PR #78.