-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #335 from iriusrisk/feature/OPT-1032
[feature/OPT-1032] to dev
- Loading branch information
Showing
8 changed files
with
165 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,27 @@ | ||
from typing import List | ||
|
||
from slp_drawio.slp_drawio.load.drawio_dict_utils import get_mx_cell_dataflows, get_dataflow_tags | ||
from slp_drawio.slp_drawio.objects.diagram_objects import DiagramDataflow | ||
|
||
|
||
class DiagramDataflowLoader: | ||
|
||
def __init__(self, source: dict): | ||
self.source: dict = source | ||
self._source: dict = source | ||
|
||
def load(self) -> [DiagramDataflow]: | ||
return [] | ||
|
||
result: List[DiagramDataflow] = [] | ||
|
||
mx_cell_dataflows = get_mx_cell_dataflows(self._source) | ||
for mx_cell in mx_cell_dataflows: | ||
if all(key in mx_cell for key in ['source', 'target']): | ||
result.append(DiagramDataflow( | ||
dataflow_id=mx_cell.get('id'), | ||
name=f'{mx_cell.get("id")}-dataflow', | ||
source_node=mx_cell.get('source'), | ||
destination_node=mx_cell.get('target'), | ||
tags=get_dataflow_tags(mx_cell.get('id'), self._source) | ||
)) | ||
|
||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
slp_drawio/tests/unit/load/test_diagram_dataflow_loader.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import json | ||
from unittest.mock import patch | ||
|
||
from sl_util.sl_util.file_utils import get_byte_data | ||
from slp_drawio.slp_drawio.load.diagram_dataflow_loader import DiagramDataflowLoader | ||
from slp_drawio.slp_drawio.load.drawio_dict_utils import get_dataflow_tags | ||
from slp_drawio.tests.resources import test_resource_paths | ||
|
||
|
||
class TestDiagramDataflowLoader: | ||
|
||
@patch('slp_drawio.slp_drawio.load.diagram_dataflow_loader.get_dataflow_tags', wraps=get_dataflow_tags) | ||
def test_load(self, get_dataflow_tags_wrapper): | ||
# GIVEN a DrawIO | ||
source = json.loads(get_byte_data(test_resource_paths.aws_two_component_multiple_dataflows_as_json)) | ||
|
||
# WHEN DiagramDataflowLoader::load | ||
diagram_dataflows = DiagramDataflowLoader(source).load() | ||
|
||
# THEN diagram dataflows has length of 2 | ||
assert len(diagram_dataflows) == 2 | ||
# AND elements has the following information | ||
assert diagram_dataflows[0].otm.id == 'pt2kyrPXSm7H56EBWWGj-6' | ||
assert diagram_dataflows[0].otm.name == 'pt2kyrPXSm7H56EBWWGj-6-dataflow' | ||
assert diagram_dataflows[0].otm.source_node == 'pt2kyrPXSm7H56EBWWGj-1' | ||
assert diagram_dataflows[0].otm.destination_node == 'pt2kyrPXSm7H56EBWWGj-7' | ||
assert len(diagram_dataflows[0].otm.tags) == 1 | ||
assert diagram_dataflows[0].otm.tags[0] == 'Dataflow Info' | ||
|
||
# AND self reference dataflow is also mapped | ||
assert diagram_dataflows[1].otm.id == 'pt2kyrPXSm7H56EBWWGj-8' | ||
assert diagram_dataflows[1].otm.name == 'pt2kyrPXSm7H56EBWWGj-8-dataflow' | ||
assert diagram_dataflows[1].otm.source_node == 'pt2kyrPXSm7H56EBWWGj-7' | ||
assert diagram_dataflows[1].otm.destination_node == 'pt2kyrPXSm7H56EBWWGj-7' | ||
assert len(diagram_dataflows[1].otm.tags) == 0 | ||
|
||
# AND the method get_dataflow_tags has been called once for each dataflow | ||
assert get_dataflow_tags_wrapper.call_count == len(diagram_dataflows) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters