瀏覽代碼

Wrote test for read_outgoing and patched exceptional case

Yentl Van Tendeloo 7 年之前
父節點
當前提交
73e4c1a249
共有 2 個文件被更改,包括 76 次插入11 次删除
  1. 16 10
      bootstrap/mini_modify.alc
  2. 60 1
      unit/test_all.py

+ 16 - 10
bootstrap/mini_modify.alc

@@ -285,11 +285,14 @@ String function cmd_read_outgoing(model : Element, element_name : String, type :
 	Element elems
 
 	if (dict_in(model["model"], element_name)):
-		result = "Success: "
-		elems = allOutgoingAssociationInstances(model, element_name, type)
-		while (set_len(elems) > 0):
-			result = string_join(result, set_pop(elems)) + "\n"
-		return result!
+		if (bool_or(dict_in(model["metamodel"]["model"], type), type == "")):
+			result = "Success: "
+			elems = allOutgoingAssociationInstances(model, element_name, type)
+			while (set_len(elems) > 0):
+				result = string_join(result, set_pop(elems)) + "\n"
+			return result!
+		else:
+			return "Element not found: " + type!
 	else:
 		return "Element not found: " + element_name!
 
@@ -298,11 +301,14 @@ String function cmd_read_incoming(model : Element, element_name : String, type :
 	Element elems
 
 	if (dict_in(model["model"], element_name)):
-		result = "Success: "
-		elems = allIncomingAssociationInstances(model, element_name, type)
-		while (set_len(elems) > 0):
-			result = string_join(result, set_pop(elems)) + "\n"
-		return result!
+		if (bool_or(dict_in(model["metamodel"]["model"], type), type == "")):
+			result = "Success: "
+			elems = allIncomingAssociationInstances(model, element_name, type)
+			while (set_len(elems) > 0):
+				result = string_join(result, set_pop(elems)) + "\n"
+			return result!
+		else:
+			return "Element not found: " + type!
 	else:
 		return "Element not found: " + element_name!
 

+ 60 - 1
unit/test_all.py

@@ -1563,6 +1563,66 @@ class TestModelverse(unittest.TestCase):
         except UnknownLocation:
             pass
 
+        # No permissions on locations directly, so there are no checks that have to be done
+
+    def test_op_read_outgoing(self):
+        model_add("users/user/test/a", "formalisms/SimpleClassDiagrams", """
+            SimpleAttribute String {}
+            Class A {
+                name : String
+            }
+            Class B {}
+            Association C (A, B) {}
+            Association D (C, B) {}
+            """)
+
+        # Test normal operation
+        assert read_outgoing("users/user/test/a", "A", "Association") == set(["C"])
+        assert read_outgoing("users/user/test/a", "A", "AttributeLink") == set(["A_name"])
+
+        # Test wildcard
+        assert read_outgoing("users/user/test/a", "A", "") == set(["A_name", "C"])
+
+        # Test association on association
+        assert read_outgoing("users/user/test/a", "C", "") == set(["D"])
+
+        # Test empty result
+        assert read_outgoing("users/user/test/a", "B", "") == set([])
+
+        # Test simpleattribute
+        assert read_outgoing("users/user/test/a", "String", "") == set([])
+
+        # Non-existing model
+        try:
+            read_outgoing("users/afa", "Association", "")
+            self.fail()
+        except UnknownModel:
+            pass
+
+        # Non-existing element
+        before = element_list("users/user/test/a")
+        try:
+            read_outgoing("users/user/test/a", "AAAAAAA", "")
+            self.fail()
+        except UnknownElement:
+            assert element_list("users/user/test/a") == before
+
+        # Non-existing type
+        before = element_list("users/user/test/a")
+        try:
+            read_outgoing("users/user/test/a", "A", "AAAAAAA")
+            self.fail()
+        except UnknownElement:
+            assert element_list("users/user/test/a") == before
+
+
+        # No read permissions
+        try:
+            read_outgoing("administration/core", "formalisms", "")
+            self.fail()
+        except ReadPermissionDenied:
+            pass
+
     """
     def test_op_model_render(self):
     def test_op_transformation_between(self):
@@ -1585,7 +1645,6 @@ class TestModelverse(unittest.TestCase):
     def test_op_group_list(self):
     def test_op_conformance_delete(self):
     def test_op_conformance_add(self):
-    def test_op_read_outgoing(self):
     def test_op_read_incoming(self):
     def test_op_read_association_source(self):
     def test_op_read_association_destination(self):