ariatosca-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mxm...@apache.org
Subject incubator-ariatosca git commit: fixing [Forced Update!]
Date Tue, 31 Jan 2017 14:00:26 GMT
Repository: incubator-ariatosca
Updated Branches:
  refs/heads/ARIA-44-Merge-parser-and-storage-models a87b49f67 -> 01a821e45 (forced update)


fixing


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

Branch: refs/heads/ARIA-44-Merge-parser-and-storage-models
Commit: 01a821e457c109a880b93dbc6babf38aaddc9ed6
Parents: 5555679
Author: mxmrlv <mxmrlv@gmail.com>
Authored: Tue Jan 31 15:45:42 2017 +0200
Committer: mxmrlv <mxmrlv@gmail.com>
Committed: Tue Jan 31 16:00:16 2017 +0200

----------------------------------------------------------------------
 aria/storage/modeling/type.py         |  14 ++--
 tests/storage/__init__.py             |   8 +-
 tests/storage/test_instrumentation.py |   6 +-
 tests/storage/test_structures.py      | 123 +++++++++--------------------
 4 files changed, 50 insertions(+), 101 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/01a821e4/aria/storage/modeling/type.py
----------------------------------------------------------------------
diff --git a/aria/storage/modeling/type.py b/aria/storage/modeling/type.py
index 2e1070d..9e3de3d 100644
--- a/aria/storage/modeling/type.py
+++ b/aria/storage/modeling/type.py
@@ -192,12 +192,12 @@ class _StrictDict(object):
     def __call__(self, key_cls=None, value_cls=None):
         strict_dict_map_key = _StrictDictID(key_cls=key_cls, value_cls=value_cls)
         if strict_dict_map_key not in self._strict_map:
-            key_cls = getattr(key_cls, '__name__', str(key_cls))
-            value_cls = getattr(value_cls, '__name__', str(value_cls))
+            key_cls_name = getattr(key_cls, '__name__', str(key_cls))
+            value_cls_name = getattr(value_cls, '__name__', str(value_cls))
             # Creating the type class itself. this class would be returned (used by the sqlalchemy
             # Column).
             strict_dict_cls = type(
-                'StrictDict_{0}_{1}'.format(key_cls, value_cls),
+                'StrictDict_{0}_{1}'.format(key_cls_name, value_cls_name),
                 (Dict, ),
                 {}
             )
@@ -205,7 +205,7 @@ class _StrictDict(object):
             # The new class inherits from both the _MutableDict class and the _StrictDictMixin,
             # while setting the necessary _key_cls and _value_cls as class attributes.
             listener_cls = type(
-                'StrictMutableDict_{0}_{1}'.format(key_cls, value_cls),
+                'StrictMutableDict_{0}_{1}'.format(key_cls_name, value_cls_name),
                 (_StrictDictMixin, _MutableDict),
                 {'_key_cls': key_cls, '_value_cls': value_cls}
             )
@@ -228,11 +228,11 @@ class _StrictList(object):
     def __call__(self, item_cls=None):
 
         if item_cls not in self._strict_map:
-            item_cls = getattr(item_cls, '__name__', str(item_cls))
+            item_cls_name = getattr(item_cls, '__name__', str(item_cls))
             # Creating the type class itself. this class would be returned (used by the sqlalchemy
             # Column).
             strict_list_cls = type(
-                'StrictList_{0}'.format(item_cls),
+                'StrictList_{0}'.format(item_cls_name),
                 (List, ),
                 {}
             )
@@ -240,7 +240,7 @@ class _StrictList(object):
             # The new class inherits from both the _MutableList class and the _StrictListMixin,
             # while setting the necessary _item_cls as class attribute.
             listener_cls = type(
-                'StrictMutableList_{0}'.format(item_cls),
+                'StrictMutableList_{0}'.format(item_cls_name),
                 (_StrictListMixin, _MutableList),
                 {'_item_cls': item_cls}
             )

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/01a821e4/tests/storage/__init__.py
----------------------------------------------------------------------
diff --git a/tests/storage/__init__.py b/tests/storage/__init__.py
index 66060b8..a50b387 100644
--- a/tests/storage/__init__.py
+++ b/tests/storage/__init__.py
@@ -30,21 +30,19 @@ from sqlalchemy import (
 from aria.storage import (
     model,
     type as aria_type,
-    structure
+    structure,
+    modeling
 )
 
 
 class MockModel(model.DB, structure.ModelMixin): #pylint: disable=abstract-method
-    __tablename__ = 'mock_models'
+    __tablename__ = 'mock_model'
     model_dict = Column(aria_type.Dict)
     model_list = Column(aria_type.List)
     value = Column(Integer)
     name = Column(Text)
 
 
-from aria.storage import modeling
-
-
 class TestFileSystem(object):
 
     def setup_method(self):

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/01a821e4/tests/storage/test_instrumentation.py
----------------------------------------------------------------------
diff --git a/tests/storage/test_instrumentation.py b/tests/storage/test_instrumentation.py
index da74bb2..4b1fc5d 100644
--- a/tests/storage/test_instrumentation.py
+++ b/tests/storage/test_instrumentation.py
@@ -347,15 +347,15 @@ class _MockModel(structure.ModelMixin):
     string2 = Column(Text)
 
 
-class MockModel1(modeling.declarative_base, _MockModel):
+class MockModel1(_MockModel, model.DB):
     __tablename__ = 'mock_model_1'
 
 
-class MockModel2(modeling.declarative_base, _MockModel):
+class MockModel2(_MockModel, model.DB):
     __tablename__ = 'mock_model_2'
 
 
-class StrictMockModel(model.DB):
+class StrictMockModel(structure.ModelMixin, model.DB):
     __tablename__ = 'strict_mock_model'
 
     strict_dict = Column(aria_type.StrictDict(basestring, basestring))

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/01a821e4/tests/storage/test_structures.py
----------------------------------------------------------------------
diff --git a/tests/storage/test_structures.py b/tests/storage/test_structures.py
index 7908cb4..1820d15 100644
--- a/tests/storage/test_structures.py
+++ b/tests/storage/test_structures.py
@@ -87,142 +87,93 @@ def test_inner_list_update(storage):
 
 
 def test_model_to_dict(context):
-    deployment = context.deployment
-    deployment_dict = deployment.to_dict()
+    service_instance = context.service_instance
+    service_instance = service_instance.to_dict()
 
     expected_keys = [
-        'created_at',
         'description',
-        'inputs',
-        'groups',
+        '_metadata',
+        'created_at',
         'permalink',
         'policy_triggers',
         'policy_types',
-        'outputs',
         'scaling_groups',
         'updated_at',
         'workflows',
-        'blueprint_name',
     ]
 
     for expected_key in expected_keys:
-        assert expected_key in deployment_dict
-
-    assert 'blueprint_fk' not in deployment_dict
+        assert expected_key in service_instance
 
 
 def test_relationship_model_ordering(context):
-    deployment = context.model.deployment.get_by_name(models.DEPLOYMENT_NAME)
-    source_node = context.model.node.get_by_name(models.DEPENDENT_NODE_NAME)
-    source_node_instance = context.model.node_instance.get_by_name(
-        models.DEPENDENT_NODE_INSTANCE_NAME)
-    target_node = context.model.node.get_by_name(models.DEPENDENCY_NODE_NAME)
-    target_node_instance = context.model.node_instance.get_by_name(
-        models.DEPENDENCY_NODE_INSTANCE_NAME)
-    new_node = model.Node(
+    service_instance = context.model.service_instance.get_by_name(models.DEPLOYMENT_NAME)
+    source_node = context.model.node.get_by_name(models.DEPENDENT_NODE_INSTANCE_NAME)
+    target_node = context.model.node.get_by_name(models.DEPENDENCY_NODE_INSTANCE_NAME)
+    new_node_template = model.NodeTemplate(
         name='new_node',
-        type='test_node_type',
-        type_hierarchy=[],
-        number_of_instances=1,
-        planned_number_of_instances=1,
-        deploy_number_of_instances=1,
-        properties={},
-        operations=dict((key, {}) for key in operations.NODE_OPERATIONS),
-        min_number_of_instances=1,
-        max_number_of_instances=1,
-        deployment=deployment
-    )
-    source_to_new_relationship = model.Relationship(
-        source_node=source_node,
-        target_node=new_node,
-        source_interfaces={},
-        source_operations=dict((key, {}) for key in operations.RELATIONSHIP_OPERATIONS),
-        target_interfaces={},
-        target_operations=dict((key, {}) for key in operations.RELATIONSHIP_OPERATIONS),
-        type='rel_type',
+        type_name='test_node_type',
         type_hierarchy=[],
-        properties={},
+        default_instances=1,
+        min_instances=1,
+        max_instances=1,
+        service_template=service_instance.service_template
     )
-    new_node_instance = model.NodeInstance(
+    new_node = model.Node(
         name='new_node_instance',
         runtime_properties={},
+        service_instance=service_instance,
         version=None,
-        node=new_node,
+        node_template=new_node_template,
         state='',
         scaling_groups=[]
     )
-    source_to_new_relationship_instance = model.RelationshipInstance(
-        relationship=source_to_new_relationship,
-        source_node_instance=source_node_instance,
-        target_node_instance=new_node_instance,
+
+    source_to_new_relationship = model.Relationship(
+        target_node=new_node,
+        source_node=source_node,
     )
 
     new_to_target_relationship = model.Relationship(
         source_node=new_node,
         target_node=target_node,
-        source_interfaces={},
-        source_operations=dict((key, {}) for key in operations.RELATIONSHIP_OPERATIONS),
-        target_interfaces={},
-        target_operations=dict((key, {}) for key in operations.RELATIONSHIP_OPERATIONS),
-        type='rel_type',
-        type_hierarchy=[],
-        properties={},
     )
-    new_to_target_relationship_instance = model.RelationshipInstance(
-        relationship=new_to_target_relationship,
-        source_node_instance=new_node_instance,
-        target_node_instance=target_node_instance,
-    )
-
 
+    context.model.node_template.put(new_node_template)
     context.model.node.put(new_node)
-    context.model.node_instance.put(new_node_instance)
     context.model.relationship.put(source_to_new_relationship)
     context.model.relationship.put(new_to_target_relationship)
-    context.model.relationship_instance.put(source_to_new_relationship_instance)
-    context.model.relationship_instance.put(new_to_target_relationship_instance)
 
-    def flip_and_assert(node_instance, direction):
+    def flip_and_assert(node, direction):
         """
         Reversed the order of relationships and assert effects took place.
-        :param node_instance: the node instance to operatate on
+        :param node: the node instance to operatate on
         :param direction: the type of relationships to flip (inbound/outbount)
         :return:
         """
         assert direction in ('inbound', 'outbound')
 
-        relationships = getattr(node_instance.node, direction + '_relationships')
-        relationship_instances = getattr(node_instance, direction + '_relationship_instances')
+        relationships = getattr(node, direction + '_relationships')
         assert len(relationships) == 2
-        assert len(relationship_instances) == 2
 
-        first_rel, second_rel = relationships
-        first_rel_instance, second_rel_instance = relationship_instances
-        assert getattr(first_rel, relationships.ordering_attr) == 0
-        assert getattr(second_rel, relationships.ordering_attr) == 1
-        assert getattr(first_rel_instance, relationship_instances.ordering_attr) == 0
-        assert getattr(second_rel_instance, relationship_instances.ordering_attr) == 1
+        first_rel_instance, second_rel_instance = relationships
+        assert getattr(first_rel_instance, relationships.ordering_attr) == 0
+        assert getattr(second_rel_instance, relationships.ordering_attr) == 1
 
-        reversed_relationships = list(reversed(relationships))
-        reversed_relationship_instances = list(reversed(relationship_instances))
+        reversed_relationship_instances = list(reversed(relationships))
 
-        assert relationships != reversed_relationships
-        assert relationship_instances != reversed_relationship_instances
+        assert relationships != reversed_relationship_instances
 
-        relationships[:] = reversed_relationships
-        relationship_instances[:] = reversed_relationship_instances
-        context.model.node_instance.update(node_instance)
+        relationships[:] = reversed_relationship_instances
+        context.model.node.update(node)
 
-        assert relationships == reversed_relationships
-        assert relationship_instances == reversed_relationship_instances
+        assert relationships == reversed_relationship_instances
 
-        assert getattr(first_rel, relationships.ordering_attr) == 1
-        assert getattr(second_rel, relationships.ordering_attr) == 0
-        assert getattr(first_rel_instance, relationship_instances.ordering_attr) == 1
-        assert getattr(second_rel_instance, relationship_instances.ordering_attr) == 0
+        assert getattr(first_rel_instance, relationships.ordering_attr) == 1
+        assert getattr(second_rel_instance, relationships.ordering_attr) == 0
 
-    flip_and_assert(source_node_instance, 'outbound')
-    flip_and_assert(target_node_instance, 'inbound')
+    flip_and_assert(source_node, 'outbound')
+    flip_and_assert(target_node, 'inbound')
 
 
 class StrictClass(model.DB, structure.ModelMixin):


Mime
View raw message