Commit 7f011348 authored by Łukasz Nowak's avatar Łukasz Nowak

Rename to checkConnected

Even more -- return True in case if all was ok.
parent 771aa3d7
...@@ -66,7 +66,7 @@ class SoftwareInstance(Item): ...@@ -66,7 +66,7 @@ class SoftwareInstance(Item):
return result_dict return result_dict
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'checkDisconnected') 'checkConnected')
def checkDisconnected(self, graph, root): def checkDisconnected(self, graph, root):
size = len(graph) size = len(graph)
visited = set() visited = set()
...@@ -83,3 +83,4 @@ class SoftwareInstance(Item): ...@@ -83,3 +83,4 @@ class SoftwareInstance(Item):
# anyway wrong in Software Instance trees # anyway wrong in Software Instance trees
if size != len(visited) + 1: if size != len(visited) + 1:
raise DisconnectedSoftwareTree raise DisconnectedSoftwareTree
return True
...@@ -153,7 +153,7 @@ graph[software_instance.getUid()] = software_instance.getPredecessorUidList() + ...@@ -153,7 +153,7 @@ graph[software_instance.getUid()] = software_instance.getPredecessorUidList() +
\n \n
# check if all elements are still connected\n # check if all elements are still connected\n
script.log(graph, root_software_instance.getUid())\n script.log(graph, root_software_instance.getUid())\n
software_instance.checkDisconnected(graph, root_software_instance.getUid())\n software_instance.checkConnected(graph, root_software_instance.getUid())\n
\n \n
software_instance.edit(\n software_instance.edit(\n
predecessor_list=predecessor_list,\n predecessor_list=predecessor_list,\n
......
247 248
\ No newline at end of file \ No newline at end of file
...@@ -8206,31 +8206,31 @@ class TestVifibSlapWebService(testVifibMixin): ...@@ -8206,31 +8206,31 @@ class TestVifibSlapWebService(testVifibMixin):
def _test_si_tree(self): def _test_si_tree(self):
software_instance = self.portal.software_instance_module.newContent( software_instance = self.portal.software_instance_module.newContent(
portal_type='Software Instance') portal_type='Software Instance')
self.checkDisconnected = software_instance.checkDisconnected self.checkConnected = software_instance.checkConnected
def test_si_tree_simple_connected(self): def test_si_tree_simple_connected(self):
"""Graph of one element is connected """Graph of one element is connected
A A
""" """
self._test_si_tree() self._test_si_tree()
graph = {'A': []} graph = {'A': []}
root = 'A' root = 'A'
self.assertEqual(None, self.checkDisconnected(graph, root)) self.assertEqual(True, self.checkConnected(graph, root))
def test_si_tree_simple_list_connected(self): def test_si_tree_simple_list_connected(self):
"""Graph of list is connected """Graph of list is connected
B->C->A B->C->A
""" """
self._test_si_tree() self._test_si_tree()
graph = {'A': [], 'B': ['C'], 'C': ['A']} graph = {'A': [], 'B': ['C'], 'C': ['A']}
root = 'B' root = 'B'
self.assertEqual(None, self.checkDisconnected(graph, root)) self.assertEqual(True, self.checkConnected(graph, root))
def test_si_tree_complex_connected(self): def test_si_tree_complex_connected(self):
"""Tree is connected """Tree is connected
B --> A B --> A
\-> C --> D \-> C --> D
\-> E --> F \-> E --> F
...@@ -8245,11 +8245,11 @@ class TestVifibSlapWebService(testVifibMixin): ...@@ -8245,11 +8245,11 @@ class TestVifibSlapWebService(testVifibMixin):
'F': [], 'F': [],
} }
root = 'B' root = 'B'
self.assertEqual(None, self.checkDisconnected(graph, root)) self.assertEqual(True, self.checkConnected(graph, root))
def test_si_tree_simple_list_disconnected(self): def test_si_tree_simple_list_disconnected(self):
"""Two lists are disconnected """Two lists are disconnected
A->B A->B
C C
""" """
...@@ -8257,23 +8257,24 @@ class TestVifibSlapWebService(testVifibMixin): ...@@ -8257,23 +8257,24 @@ class TestVifibSlapWebService(testVifibMixin):
graph = {'A': ['B'], 'B': [], 'C': []} graph = {'A': ['B'], 'B': [], 'C': []}
root = 'A' root = 'A'
from erp5.document.SoftwareInstance import DisconnectedSoftwareTree from erp5.document.SoftwareInstance import DisconnectedSoftwareTree
self.assertRaises(DisconnectedSoftwareTree, self.checkDisconnected, graph, self.assertRaises(DisconnectedSoftwareTree, self.checkConnected, graph,
root) root)
# For now limitation of implementation gives false positive # For now limitation of implementation gives false positive
@expectedFailure @expectedFailure
def test_si_tree_cyclic_connected(self): def test_si_tree_cyclic_connected(self):
"""Cyclic is connected """Cyclic is connected
A<->B A<->B
""" """
self._test_si_tree() self._test_si_tree()
graph = {'A': ['B'], 'B': ['A']} graph = {'A': ['B'], 'B': ['A']}
root = 'B' root = 'B'
self.assertEqual(None, self.checkDisconnected(graph, root)) self.assertEqual(True, self.checkConnected(graph, root))
def test_si_tree_cyclic_disconnected(self): def test_si_tree_cyclic_disconnected(self):
"""Two trees, where one is cyclic are disconnected """Two trees, where one is cyclic are disconnected
B --> A B --> A
\-> H \-> H
C --> D --> G C --> D --> G
...@@ -8292,7 +8293,7 @@ class TestVifibSlapWebService(testVifibMixin): ...@@ -8292,7 +8293,7 @@ class TestVifibSlapWebService(testVifibMixin):
} }
root = 'B' root = 'B'
from erp5.document.SoftwareInstance import DisconnectedSoftwareTree from erp5.document.SoftwareInstance import DisconnectedSoftwareTree
self.assertRaises(DisconnectedSoftwareTree, self.checkDisconnected, graph, self.assertRaises(DisconnectedSoftwareTree, self.checkConnected, graph,
root) root)
######################################## ########################################
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment