-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: added aws dynamodb vertex verification
* chore: tests utils added * tests: extracted verification to test utils * tests: added dynamodb vertex verification * fix: fix pipeline
- Loading branch information
Showing
3 changed files
with
109 additions
and
41 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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from multicloud_diagrams import MultiCloudDiagrams | ||
import xml.etree.ElementTree as et | ||
|
||
from tests.test_utils import TestUtilities | ||
|
||
|
||
class TestMultiCloudDiagramsAWSVertecies(TestUtilities): | ||
|
||
def test_dynamo(self): | ||
# given | ||
mcd = MultiCloudDiagrams() | ||
|
||
# when | ||
table_arn = 'arn:aws:dynamodb:eu-west-1:123456789012:table/prod-dynamo-table' | ||
table_name = 'prod-dynamo-table' | ||
metadata = { | ||
'DeletionProtectionEnabled': True, | ||
'ItemCount': 900, | ||
'TableSizeBytes': 123 | ||
} | ||
mcd.add_vertex(id=table_arn, node_name=table_name, arn=table_arn, node_type='dynamo', metadata=metadata) | ||
|
||
|
||
# then | ||
tree = et.ElementTree(mcd.mxfile) | ||
self.verify_mxfile_default(et.ElementTree(tree)) | ||
|
||
mx_cells = tree.findall("./*/*/*/") | ||
self.assertEqual(3, len(mx_cells)) | ||
self.verify_mx_cell(mx_cells[0], expected={'id': '0'}) | ||
self.verify_mx_cell(mx_cells[1], expected={'id': '1', 'parent': '0'}) | ||
|
||
expected = { | ||
'id': 'vertex:dynamo:arn:aws:dynamodb:eu-west-1:123456789012:table/prod-dynamo-table', | ||
'value': '<b>Name</b>: prod-dynamo-table<BR><b>ARN</b>: arn:aws:dynamodb:eu-west-1:123456789012:table/prod-dynamo-table <BR>-----------<BR><b>DeletionProtectionEnabled</b>: True<BR><b>ItemCount</b>: 900<BR><b>TableSizeBytes</b>: 123', | ||
'style': 'verticalLabelPosition=bottom;html=1;verticalAlign=top;aspect=fixed;align=left;pointerEvents=1;outlineConnect=0;dashed=0;verticalLabelPosition=bottom;verticalAlign=top;align=left;html=1;shape=mxgraph.aws3.dynamo_db;fillColor=#2E73B8;gradientColor=none;', | ||
'parent': '1', | ||
'vertex': '1' | ||
} | ||
self.verify_mx_cell(mx_cells[2], expected) |
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,90 +1,64 @@ | ||
from unittest import TestCase | ||
|
||
from multicloud_diagrams import MultiCloudDiagrams | ||
import xml.etree.ElementTree as et | ||
|
||
from tests.test_utils import TestUtilities | ||
|
||
|
||
class TestMultiCloudDiagramsDefaultDrawIO(TestCase): | ||
class TestMultiCloudDiagramsDefaultDrawIO(TestUtilities): | ||
|
||
def test_drawio_preambula(self): | ||
# given | ||
mcd = MultiCloudDiagrams() | ||
|
||
# when | ||
tree = et.ElementTree(mcd.mxfile) | ||
roots = tree.findall(".") | ||
root = roots[0] | ||
|
||
# then | ||
self.assertEqual(1, len(roots)) | ||
self.assertEqual('mxfile', root.tag) | ||
self.assertEqual('multicloud-diagrams', root.attrib['host']) | ||
self.assertEqual('PIP package multicloud-diagrams. Generate resources in draw.io compatible format for Cloud infrastructure. Copyrights @ Roman Tsypuk 2023. MIT license.', | ||
root.attrib['agent']) | ||
self.assertEqual('MultiCloud', root.attrib['type']) | ||
self.verify_mxfile(tree.findall(".")) | ||
|
||
def test_diagram(self): | ||
# given | ||
mcd = MultiCloudDiagrams() | ||
|
||
# when | ||
tree = et.ElementTree(mcd.mxfile) | ||
diagrams = tree.findall("./") | ||
diagram = diagrams[0] | ||
|
||
# then | ||
self.assertEqual(1, len(diagrams)) | ||
self.assertEqual('diagram', diagram.tag) | ||
self.assertEqual('diagram_1', diagram.attrib['id']) | ||
self.assertEqual('AWS components', diagram.attrib['name']) | ||
# ./diagram/ | ||
self.verify_diagrams(tree.findall("./")) | ||
|
||
def test_mx_graph_model(self): | ||
# given | ||
mcd = MultiCloudDiagrams() | ||
|
||
# when | ||
tree = et.ElementTree(mcd.mxfile) | ||
# ./diagram/ | ||
mx_graph_models = tree.findall("/*/") | ||
mx_graph_model = mx_graph_models[0] | ||
|
||
# then | ||
self.assertEqual(1, len(mx_graph_models)) | ||
self.assertEqual('mxGraphModel', mx_graph_model.tag) | ||
expected = {'dx': '1015', 'dy': '661', 'grid': '1', 'gridSize': '10', 'guides': '1', 'tooltips': '1', 'connect': '1', 'arrows': '1', 'fold': '1', 'page': '1', 'pageScale': '1', | ||
'pageWidth': '850', 'pageHeight': '1100', 'math': '0', 'shadow': '0'} | ||
self.assertEqual(expected, mx_graph_model.attrib) | ||
# ./diagram/mxGraphModel/ | ||
self.verify_mx_graph_models(tree.findall("/*/")) | ||
|
||
def test_root(self): | ||
# given | ||
mcd = MultiCloudDiagrams() | ||
|
||
# when | ||
tree = et.ElementTree(mcd.mxfile) | ||
# ./diagram/mxGraphModel/root | ||
roots = tree.findall("./*/*/*") | ||
root = roots[0] | ||
|
||
# then | ||
self.assertEqual(1, len(roots)) | ||
self.assertEqual('root', root.tag) | ||
expected = {} | ||
self.assertEqual(expected, root.attrib) | ||
# ./diagram/mxGraphModel/root | ||
self.verify_roots(tree.findall("./*/*/")) | ||
|
||
def test_mx_cell(self): | ||
# given | ||
mcd = MultiCloudDiagrams() | ||
|
||
# when | ||
tree = et.ElementTree(mcd.mxfile) | ||
# ./diagram/mxGraphModel/root/mxCell | ||
mxcells = tree.findall("./*/*/*/*") | ||
|
||
# then | ||
self.assertEqual(2, len(mxcells)) | ||
self.verify_mx_cell(mxcells[0], expected={'id': '0'}) | ||
self.verify_mx_cell(mxcells[1], expected={'id': '1', 'parent': '0'}) | ||
|
||
def verify_mx_cell(self, mx_cell, expected): | ||
self.assertEqual('mxCell', mx_cell.tag) | ||
self.assertEqual(expected, mx_cell.attrib) | ||
# ./diagram/mxGraphModel/root/mxCell | ||
mx_cells = tree.findall("./*/*/*/") | ||
self.assertEqual(2, len(mx_cells)) | ||
self.verify_mx_cell(mx_cells[0], expected={'id': '0'}) | ||
self.verify_mx_cell(mx_cells[1], expected={'id': '1', 'parent': '0'}) |
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,54 @@ | ||
from unittest import TestCase | ||
|
||
|
||
class TestUtilities(TestCase): | ||
|
||
def verify_mx_cell(self, mx_cell, expected): | ||
# then | ||
self.assertEqual('mxCell', mx_cell.tag) | ||
self.assertEqual(expected, mx_cell.attrib) | ||
|
||
def verify_mxfile(self, roots): | ||
root = roots[0] | ||
|
||
# then | ||
self.assertEqual(1, len(roots)) | ||
self.assertEqual('mxfile', root.tag) | ||
self.assertEqual('multicloud-diagrams', root.attrib['host']) | ||
self.assertEqual('PIP package multicloud-diagrams. Generate resources in draw.io compatible format for Cloud infrastructure. Copyrights @ Roman Tsypuk 2023. MIT license.', | ||
root.attrib['agent']) | ||
self.assertEqual('MultiCloud', root.attrib['type']) | ||
|
||
def verify_diagrams(self, diagrams): | ||
diagram = diagrams[0] | ||
|
||
# then | ||
self.assertEqual(1, len(diagrams)) | ||
self.assertEqual('diagram', diagram.tag) | ||
self.assertEqual('diagram_1', diagram.attrib['id']) | ||
self.assertEqual('AWS components', diagram.attrib['name']) | ||
|
||
def verify_mx_graph_models(self, mx_graph_models): | ||
mx_graph_model = mx_graph_models[0] | ||
|
||
# then | ||
self.assertEqual(1, len(mx_graph_models)) | ||
self.assertEqual('mxGraphModel', mx_graph_model.tag) | ||
expected = {'dx': '1015', 'dy': '661', 'grid': '1', 'gridSize': '10', 'guides': '1', 'tooltips': '1', 'connect': '1', 'arrows': '1', 'fold': '1', 'page': '1', 'pageScale': '1', | ||
'pageWidth': '850', 'pageHeight': '1100', 'math': '0', 'shadow': '0'} | ||
self.assertEqual(expected, mx_graph_model.attrib) | ||
|
||
def verify_roots(self, roots): | ||
root = roots[0] | ||
|
||
# then | ||
self.assertEqual(1, len(roots)) | ||
self.assertEqual('root', root.tag) | ||
expected = {} | ||
self.assertEqual(expected, root.attrib) | ||
|
||
def verify_mxfile_default(self, tree): | ||
self.verify_mxfile(tree.findall(".")) | ||
self.verify_diagrams(tree.findall("./")) | ||
self.verify_mx_graph_models(tree.findall("/*/")) | ||
self.verify_roots(tree.findall("./*/*/")) |