Skip to content

Commit d300b75

Browse files
[BLAZ-1964] Component name fixed if the length is less than 2 in Visio and Lucidchart
1 parent abc8173 commit d300b75

2 files changed

Lines changed: 25 additions & 22 deletions

File tree

slp_visio/slp_visio/parse/mappers/diagram_component_mapper.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import Dict
2-
31
from otm.otm.entity.component import Component
42
from otm.otm.entity.trustzone import Trustzone
53
from slp_base import MappingFileNotValidError
@@ -8,25 +6,29 @@
86
from slp_visio.slp_visio.parse.representation.representation_calculator import RepresentationCalculator
97

108

9+
def _normalize_component_name(name: str) -> str:
10+
return f'_{name}' if len(name) == 1 else name
11+
12+
1113
class DiagramComponentMapper(DiagramMapper):
1214

1315
def __init__(self,
14-
components: [DiagramComponent],
15-
component_mappings: Dict[str, dict],
16-
trustzone_mappings: Dict[str, dict],
16+
components: list[DiagramComponent],
17+
component_mappings: dict[str, dict],
18+
trustzone_mappings: dict[str, dict],
1719
default_trustzone: Trustzone,
1820
representation_calculator: RepresentationCalculator):
19-
self.components: [DiagramComponent] = components
21+
self.components: list[DiagramComponent] = components
2022
self.component_mappings = component_mappings
2123
self.trustzone_mappings = trustzone_mappings
2224
self.default_trustzone = default_trustzone
2325

2426
self.representation_calculator = representation_calculator
2527

26-
def to_otm(self) -> [Component]:
28+
def to_otm(self) -> list[Component]:
2729
return self.__map_to_otm(self.components)
2830

29-
def __map_to_otm(self, components: [DiagramComponent]) -> [Component]:
31+
def __map_to_otm(self, components: list[DiagramComponent]) -> list[Component]:
3032
otm_components = []
3133

3234
for diag_component in components:
@@ -43,7 +45,7 @@ def __build_otm_component(self, diagram_component: DiagramComponent, otm_type: s
4345

4446
return Component(
4547
component_id=diagram_component.id,
46-
name=diagram_component.name,
48+
name=_normalize_component_name(diagram_component.name),
4749
component_type=otm_type,
4850
parent=self.__calculate_parent_id(diagram_component),
4951
parent_type=self._calculate_parent_type(diagram_component),

slp_visio/tests/unit/parse/mappers/test_diagram_component_mapper.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22

33
import pytest
44

5+
from slp_visio.slp_visio.load.objects.diagram_objects import DiagramComponent
6+
57
from slp_base import MappingFileNotValidError
68
from slp_visio.slp_visio.parse.mappers.diagram_component_mapper import DiagramComponentMapper
79

8-
tz1 = MagicMock(id='tz1')
9-
c1 = MagicMock(id='c1')
10+
tz1 = DiagramComponent(id='tz1')
11+
c1 = DiagramComponent(id='c1', name='Component 1')
1012
c1.parent = tz1
11-
c2 = MagicMock(id='c2')
13+
c2 = DiagramComponent(id='c2', name='Component 2')
1214
c2.parent = c1
13-
c3 = MagicMock(id='c3')
15+
c3 = DiagramComponent(id='c3', name='3')
1416
c3.parent = None
15-
c4 = MagicMock(id='c4')
17+
c4 = DiagramComponent(id='c4', name='Component 4')
1618

1719

1820
diagram_components = [tz1, c1, c2, c3, c4]
@@ -53,17 +55,20 @@ def test_to_otm(self):
5355
assert components[0].id == 'c1'
5456
assert components[0].type == 'type-1'
5557
assert components[0].parent == 'tz1'
58+
assert components[0].name == c1.name
5659

5760
assert components[1].id == 'c2'
5861
assert components[1].type == 'type-2'
5962
assert components[1].parent == 'c1'
63+
assert components[1].name == c2.name
6064

6165
assert components[2].id == 'c3'
6266
assert components[2].type == 'type-3'
6367
assert components[2].parent == default_trustzone.id
68+
assert components[2].name == f"_{c3.name}"
6469

6570
def test_not_default_trustzone(self):
66-
# GIVEN the diagram component mapper without default trustzone
71+
# GIVEN the diagram component mapper without a default trustzone
6772
diagram_component_mapper = DiagramComponentMapper(
6873
diagram_components,
6974
component_mappings,
@@ -72,15 +77,11 @@ def test_not_default_trustzone(self):
7277
representation_calculator
7378
)
7479

75-
# WHEN to_otm is called an exception is raised
80+
# WHEN to_otm is called, expect an exception
7681
with pytest.raises(MappingFileNotValidError) as error:
7782
diagram_component_mapper.to_otm()
7883

79-
# THEN the exception is raised
84+
# THEN an exception is raised
8085
assert error.value.title == 'Mapping files are not valid'
8186
assert error.value.detail == 'No default trust zone has been defined in the mapping file'
82-
assert error.value.message == 'Please, add a default trust zone'
83-
84-
85-
86-
87+
assert error.value.message == 'Please, add a default trust zone'

0 commit comments

Comments
 (0)