Repository: incubator-ariatosca
Updated Branches:
  refs/heads/ARIA-1-parser-test-suite 40a93457f -> 3a1b059a8


Function tests


Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/3a1b059a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/3a1b059a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/3a1b059a

Branch: refs/heads/ARIA-1-parser-test-suite
Commit: 3a1b059a826f82250fff490118fd24071415a806
Parents: 40a9345
Author: Tal Liron <tal.li...@gmail.com>
Authored: Fri Oct 20 13:37:59 2017 -0500
Committer: Tal Liron <tal.li...@gmail.com>
Committed: Fri Oct 20 13:37:59 2017 -0500

----------------------------------------------------------------------
 .../simple_v1_0/modeling/functions.py           |  38 +++--
 .../functions/test_function_get_artifact.py     | 139 +++++++++++++++++++
 .../functions/test_function_get_input.py        |   2 +-
 .../test_function_get_nodes_of_type.py          |  55 +++++++-
 .../test_function_get_operation_output.py       |  69 ++++++++-
 .../test_functions_modelable_entity.py          |   6 +-
 6 files changed, 296 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3a1b059a/extensions/aria_extension_tosca/simple_v1_0/modeling/functions.py
----------------------------------------------------------------------
diff --git a/extensions/aria_extension_tosca/simple_v1_0/modeling/functions.py 
b/extensions/aria_extension_tosca/simple_v1_0/modeling/functions.py
index e1609cb..d28410b 100644
--- a/extensions/aria_extension_tosca/simple_v1_0/modeling/functions.py
+++ b/extensions/aria_extension_tosca/simple_v1_0/modeling/functions.py
@@ -329,6 +329,9 @@ class GetOperationOutput(Function):
         return {'get_operation_output': [self.modelable_entity_name, 
interface_name, operation_name,
                                          output_variable_name]}
 
+    def __evaluate__(self, container):
+        return Evaluation(None)
+
 
 #
 # Navigation
@@ -363,7 +366,7 @@ class GetNodesOfType(Function):
         return {'get_nodes_of_type': node_type_name}
 
     def __evaluate__(self, container):
-        pass
+        return Evaluation(None)
 
 
 #
@@ -391,10 +394,16 @@ class GetArtifact(Function):
                                                              argument[0])
         self.artifact_name = parse_string_expression(context, presentation, 
'get_artifact', 1,
                                                      'the artifact name', 
argument[1])
-        self.location = parse_string_expression(context, presentation, 
'get_artifact', 2,
-                                                'the location or 
"LOCAL_FILE"', argument[2])
-        self.remove = parse_bool(context, presentation, 'get_artifact', 3, 
'the removal flag',
-                                 argument[3])
+        if len(argument) > 2:
+            self.location = parse_string_expression(context, presentation, 
'get_artifact', 2,
+                                                    'the location or 
"LOCAL_FILE"', argument[2])
+        else:
+            self.location = None
+        if len(argument) > 3:
+            self.remove = parse_bool(context, presentation, 'get_artifact', 3, 
'the removal flag',
+                                     argument[3])
+        else:
+            self.remove = None
 
     @property
     def as_raw(self):
@@ -402,9 +411,22 @@ class GetArtifact(Function):
         if hasattr(artifact_name, 'as_raw'):
             artifact_name = as_raw(artifact_name)
         location = self.location
-        if hasattr(location, 'as_raw'):
-            location = as_raw(location)
-        return {'get_artifacts': [self.modelable_entity_name, artifact_name, 
location, self.remove]}
+        if location is not None:
+            if hasattr(location, 'as_raw'):
+                location = as_raw(location)
+            remove = self.remove
+            if hasattr(remove, 'as_raw'):
+                remove = as_raw(remove)
+            if remove is not None:
+                return {'get_artifact': [self.modelable_entity_name, 
artifact_name, location,
+                                         remove]}
+            else:
+                return {'get_artifact': [self.modelable_entity_name, 
artifact_name, location]}
+        else:
+            return {'get_artifact': [self.modelable_entity_name, 
artifact_name]}
+
+    def __evaluate__(self, container):
+        return Evaluation(None)
 
 
 #

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3a1b059a/tests/extensions/aria_extension_tosca/simple_v1_0/functions/test_function_get_artifact.py
----------------------------------------------------------------------
diff --git 
a/tests/extensions/aria_extension_tosca/simple_v1_0/functions/test_function_get_artifact.py
 
b/tests/extensions/aria_extension_tosca/simple_v1_0/functions/test_function_get_artifact.py
index a590ed4..11be88a 100644
--- 
a/tests/extensions/aria_extension_tosca/simple_v1_0/functions/test_function_get_artifact.py
+++ 
b/tests/extensions/aria_extension_tosca/simple_v1_0/functions/test_function_get_artifact.py
@@ -15,3 +15,142 @@
 # limitations under the License.
 
 import pytest
+
+
+# Syntax
+
+def test_functions_get_artifact_syntax_empty(parser):
+    parser.parse_literal("""
+tosca_definitions_version: tosca_simple_yaml_1_0
+node_types:
+  MyType:
+    properties:
+      my_parameter:
+        type: string
+topology_template:
+  node_templates:
+    my_node:
+      type: MyType
+      properties:
+        my_parameter: { get_artifact: [] } # needs at least two args
+""").assert_failure()
+
+
+# Arguments
+
+def test_functions_get_artifact_2_arguments(parser):
+    parser.parse_literal("""
+tosca_definitions_version: tosca_simple_yaml_1_0
+artifact_types:
+  MyType: {}
+node_types:
+  MyType:
+    properties:
+      my_parameter:
+        type: string
+    artifacts:
+      my_artifact:
+        type: MyType
+        file: filename
+topology_template:
+  node_templates:
+    my_node:
+      type: MyType
+      properties:
+        my_parameter: { get_artifact: [ my_node, my_artifact ] }
+""").assert_success()
+
+
+@pytest.mark.skip(reason='not implemented')
+def test_functions_get_artifact_unknown(parser):
+    parser.parse_literal("""
+tosca_definitions_version: tosca_simple_yaml_1_0
+artifact_types:
+  MyType: {}
+node_types:
+  MyType:
+    properties:
+      my_parameter:
+        type: string
+    artifacts:
+      my_artifact:
+        type: MyType
+        file: filename
+topology_template:
+  node_templates:
+    my_node:
+      type: MyType
+      properties:
+        my_parameter: { get_artifact: [ unknown, my_artifact ] }
+""").assert_failure()
+
+
+def test_functions_get_artifact_3_arguments(parser):
+    parser.parse_literal("""
+tosca_definitions_version: tosca_simple_yaml_1_0
+artifact_types:
+  MyType: {}
+node_types:
+  MyType:
+    properties:
+      my_parameter:
+        type: string
+    artifacts:
+      my_artifact:
+        type: MyType
+        file: filename
+topology_template:
+  node_templates:
+    my_node:
+      type: MyType
+      properties:
+        my_parameter: { get_artifact: [ my_node, my_artifact, path ] }
+""").assert_success()
+
+
+def test_functions_get_artifact_4_arguments(parser):
+    parser.parse_literal("""
+tosca_definitions_version: tosca_simple_yaml_1_0
+artifact_types:
+  MyType: {}
+node_types:
+  MyType:
+    properties:
+      my_parameter:
+        type: string
+    artifacts:
+      my_artifact:
+        type: MyType
+        file: filename
+topology_template:
+  node_templates:
+    my_node:
+      type: MyType
+      properties:
+        my_parameter: { get_artifact: [ my_node, my_artifact, path, true ] }
+""").assert_success()
+
+
+# Unicode
+
+def test_functions_get_artifact_unicode(parser):
+    parser.parse_literal("""
+tosca_definitions_version: tosca_simple_yaml_1_0
+artifact_types:
+  類型: {}
+node_types:
+  類型:
+    properties:
+      參數:
+        type: string
+    artifacts:
+      神器:
+        type: 類型
+        file: 文件名
+topology_template:
+  node_templates:
+    模板:
+      type: 類型
+      properties:
+        參數: { get_artifact: [ 模板, 神器, 路徑, true ] }
+""").assert_success()

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3a1b059a/tests/extensions/aria_extension_tosca/simple_v1_0/functions/test_function_get_input.py
----------------------------------------------------------------------
diff --git 
a/tests/extensions/aria_extension_tosca/simple_v1_0/functions/test_function_get_input.py
 
b/tests/extensions/aria_extension_tosca/simple_v1_0/functions/test_function_get_input.py
index daaea5f..a4c97a4 100644
--- 
a/tests/extensions/aria_extension_tosca/simple_v1_0/functions/test_function_get_input.py
+++ 
b/tests/extensions/aria_extension_tosca/simple_v1_0/functions/test_function_get_input.py
@@ -28,7 +28,7 @@ topology_template:
     my_node:
       type: MyType
       properties:
-        my_parameter: { get_input: [ unknown ] }
+        my_parameter: { get_input: unknown }
 """).assert_failure()
 
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3a1b059a/tests/extensions/aria_extension_tosca/simple_v1_0/functions/test_function_get_nodes_of_type.py
----------------------------------------------------------------------
diff --git 
a/tests/extensions/aria_extension_tosca/simple_v1_0/functions/test_function_get_nodes_of_type.py
 
b/tests/extensions/aria_extension_tosca/simple_v1_0/functions/test_function_get_nodes_of_type.py
index a590ed4..ffa2f9c 100644
--- 
a/tests/extensions/aria_extension_tosca/simple_v1_0/functions/test_function_get_nodes_of_type.py
+++ 
b/tests/extensions/aria_extension_tosca/simple_v1_0/functions/test_function_get_nodes_of_type.py
@@ -14,4 +14,57 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import pytest
+
+def test_functions_get_nodes_of_type_unknown(parser):
+    parser.parse_literal("""
+tosca_definitions_version: tosca_simple_yaml_1_0
+node_types:
+  MyType:
+    properties:
+      my_parameter:
+        type: string
+topology_template:
+  node_templates:
+    my_node:
+      type: MyType
+      properties:
+        my_parameter: { get_nodes_of_type: unknown }
+""", import_profile=True).assert_failure()
+
+
+def test_functions_get_nodes_of_type(parser):
+    parser.parse_literal("""
+tosca_definitions_version: tosca_simple_yaml_1_0
+node_types:
+  MyType:
+    properties:
+      my_parameter:
+        type: list
+        entry_schema: string
+topology_template:
+  node_templates:
+    my_node:
+      type: MyType
+      properties:
+        my_parameter: { get_nodes_of_type: MyType }
+""", import_profile=True).assert_success()
+
+
+# Unicode
+
+def test_functions_get_nodes_of_type_unicode(parser):
+    parser.parse_literal("""
+tosca_definitions_version: tosca_simple_yaml_1_0
+node_types:
+  類型:
+    properties:
+      參數:
+        type: list
+        entry_schema: string
+topology_template:
+  node_templates:
+    模板:
+      type: 類型
+      properties:
+        參數: { get_nodes_of_type: 類型 }
+""", import_profile=True).assert_success()

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3a1b059a/tests/extensions/aria_extension_tosca/simple_v1_0/functions/test_function_get_operation_output.py
----------------------------------------------------------------------
diff --git 
a/tests/extensions/aria_extension_tosca/simple_v1_0/functions/test_function_get_operation_output.py
 
b/tests/extensions/aria_extension_tosca/simple_v1_0/functions/test_function_get_operation_output.py
index a590ed4..c115d0d 100644
--- 
a/tests/extensions/aria_extension_tosca/simple_v1_0/functions/test_function_get_operation_output.py
+++ 
b/tests/extensions/aria_extension_tosca/simple_v1_0/functions/test_function_get_operation_output.py
@@ -14,4 +14,71 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import pytest
+
+# Syntax
+
+def test_functions_get_operation_output_syntax_empty(parser):
+    parser.parse_literal("""
+tosca_definitions_version: tosca_simple_yaml_1_0
+node_types:
+  MyType:
+    properties:
+      my_parameter:
+        type: string
+topology_template:
+  node_templates:
+    my_node:
+      type: MyType
+      properties:
+        my_parameter: { get_operation_output: [] } # needs at least two args
+""").assert_failure()
+
+
+# Arguments
+
+def test_functions_get_operation_output(parser):
+    parser.parse_literal("""
+tosca_definitions_version: tosca_simple_yaml_1_0
+interface_types:
+  MyType:
+    my_operation: {}
+node_types:
+  MyType:
+    properties:
+      my_parameter:
+        type: string
+    interfaces:
+      MyInterface:
+        type: MyType
+topology_template:
+  node_templates:
+    my_node:
+      type: MyType
+      properties:
+        my_parameter: { get_operation_output: [ my_node, MyInterface, 
my_operation, my_variable ] }
+""").assert_success()
+
+
+# Unicode
+
+def test_functions_get_operation_output_unicode(parser):
+    parser.parse_literal("""
+tosca_definitions_version: tosca_simple_yaml_1_0
+interface_types:
+  類型:
+    手術: {}
+node_types:
+  類型:
+    properties:
+      參數:
+        type: string
+    interfaces:
+      接口:
+        type: 類型
+topology_template:
+  node_templates:
+    模板:
+      type: 類型
+      properties:
+        參數: { get_operation_output: [ 模板, 接口, 手術, 變量 ] }
+""").assert_success()

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3a1b059a/tests/extensions/aria_extension_tosca/simple_v1_0/functions/test_functions_modelable_entity.py
----------------------------------------------------------------------
diff --git 
a/tests/extensions/aria_extension_tosca/simple_v1_0/functions/test_functions_modelable_entity.py
 
b/tests/extensions/aria_extension_tosca/simple_v1_0/functions/test_functions_modelable_entity.py
index 3d0c522..365971a 100644
--- 
a/tests/extensions/aria_extension_tosca/simple_v1_0/functions/test_functions_modelable_entity.py
+++ 
b/tests/extensions/aria_extension_tosca/simple_v1_0/functions/test_functions_modelable_entity.py
@@ -17,8 +17,10 @@
 import pytest
 
 
-# TODO other keywords (HOST, SOURCE, TARGET)
-# reqs and caps
+# TODO:
+#  other keywords (HOST, SOURCE, TARGET)
+#  requirements
+#  capabilities
 
 
 PERMUTATIONS = (

Reply via email to