ariatosca-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mxm...@apache.org
Subject [1/4] incubator-ariatosca git commit: reorded storage
Date Sun, 18 Dec 2016 14:30:55 GMT
Repository: incubator-ariatosca
Updated Branches:
  refs/heads/ARIA-39-Genericize-storage-models 89dfdb61c -> 24b55dacc


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3ac35f63/tests/orchestrator/workflows/executor/test_executor.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/workflows/executor/test_executor.py b/tests/orchestrator/workflows/executor/test_executor.py
index a425799..291a48c 100644
--- a/tests/orchestrator/workflows/executor/test_executor.py
+++ b/tests/orchestrator/workflows/executor/test_executor.py
@@ -20,7 +20,7 @@ from contextlib import contextmanager
 import pytest
 import retrying
 
-from aria.storage import models
+from aria.storage import model
 from aria.orchestrator import events
 from aria.orchestrator.workflows.executor import (
     thread,
@@ -104,7 +104,7 @@ class MockException(Exception):
 
 class MockTask(object):
 
-    INFINITE_RETRIES = models.Task.INFINITE_RETRIES
+    INFINITE_RETRIES = model.Task.INFINITE_RETRIES
 
     def __init__(self, func, inputs=None, ctx=None):
         self.states = []
@@ -120,7 +120,7 @@ class MockTask(object):
         self.retry_count = 0
         self.max_attempts = 1
 
-        for state in models.Task.STATES:
+        for state in model.Task.STATES:
             setattr(self, state.upper(), state)
 
     @contextmanager

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3ac35f63/tests/storage/__init__.py
----------------------------------------------------------------------
diff --git a/tests/storage/__init__.py b/tests/storage/__init__.py
index c455bfa..9101fd0 100644
--- a/tests/storage/__init__.py
+++ b/tests/storage/__init__.py
@@ -17,7 +17,7 @@ import platform
 from tempfile import mkdtemp
 from shutil import rmtree
 
-from aria.storage import models
+from aria.storage import model
 from sqlalchemy import (
     create_engine,
     orm)
@@ -59,7 +59,7 @@ def get_sqlite_api_kwargs(base_dir=None, filename='db.sqlite'):
     session_factory = orm.sessionmaker(bind=engine)
     session = scoped_session(session_factory=session_factory) if base_dir else session_factory()
 
-    models.DeclarativeBase.metadata.create_all(bind=engine)
+    model.DeclarativeBase.metadata.create_all(bind=engine)
     return dict(engine=engine, session=session)
 
 
@@ -76,4 +76,4 @@ def release_sqlite_storage(storage):
             session.rollback()
             session.close()
         for engine in set(mapi._engine for mapi in mapis):
-            models.DeclarativeBase.metadata.drop_all(engine)
+            model.DeclarativeBase.metadata.drop_all(engine)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3ac35f63/tests/storage/test_model_storage.py
----------------------------------------------------------------------
diff --git a/tests/storage/test_model_storage.py b/tests/storage/test_model_storage.py
index e5aee5a..7441099 100644
--- a/tests/storage/test_model_storage.py
+++ b/tests/storage/test_model_storage.py
@@ -15,47 +15,75 @@
 
 import pytest
 
+from sqlalchemy import Column, Text, Integer
+
 from aria.storage import (
     ModelStorage,
-    models,
+    model,
     exceptions,
     sql_mapi,
+    structure,
+    type as aria_type,
 )
 from aria import application_model_storage
 from tests.storage import get_sqlite_api_kwargs, release_sqlite_storage
 
 
+class MockModel(model.DeclarativeBase, structure.ModelBase):
+    __tablename__ = 'mock_models'
+    some_dict = Column(aria_type.Dict)
+    value = Column(Integer)
+    name = Column(Text)
+
+
 @pytest.fixture
 def storage():
     base_storage = ModelStorage(sql_mapi.SQLAlchemyModelAPI, api_kwargs=get_sqlite_api_kwargs())
+    base_storage.register(MockModel)
     yield base_storage
     release_sqlite_storage(base_storage)
 
 
+@pytest.fixture(scope='module', autouse=True)
+def module_cleanup():
+    model.DeclarativeBase.metadata.remove(MockModel.__table__)
+
+
 def test_storage_base(storage):
     with pytest.raises(AttributeError):
         storage.non_existent_attribute()
 
 
 def test_model_storage(storage):
-    storage.register(models.ProviderContext)
+    mock_model = MockModel(value=0, name='model_name')
+    storage.mock_model.put(mock_model)
 
-    pc = models.ProviderContext(context={}, name='context_name')
-    storage.provider_context.put(pc)
+    assert storage.mock_model.get_by_name('model_name') == mock_model
 
-    assert storage.provider_context.get_by_name('context_name') == pc
+    assert [mm_from_storage for mm_from_storage in storage.mock_model.iter()] == [mock_model]
+    assert [mm_from_storage for mm_from_storage in storage.mock_model] == [mock_model]
 
-    assert [pc_from_storage for pc_from_storage in storage.provider_context.iter()] == [pc]
-    assert [pc_from_storage for pc_from_storage in storage.provider_context] == [pc]
+    storage.mock_model.delete(mock_model)
+    with pytest.raises(exceptions.StorageError):
+        storage.mock_model.get(mock_model.id)
 
-    new_context = {'update_key': 0}
-    pc.context = new_context
-    storage.provider_context.update(pc)
-    assert storage.provider_context.get(pc.id).context == new_context
 
-    storage.provider_context.delete(pc)
-    with pytest.raises(exceptions.StorageError):
-        storage.provider_context.get(pc.id)
+def test_inner_dict_update(storage):
+    inner_dict = {'inner_value': 1}
+
+    mock_model = MockModel(some_dict={'inner_dict': inner_dict, 'value': 0})
+    storage.mock_model.put(mock_model)
+
+    storage_mm = storage.mock_model.get(mock_model.id)
+    assert storage_mm == mock_model
+
+    storage_mm.some_dict['inner_dict']['inner_value'] = 2
+    storage_mm.some_dict['value'] = -1
+    storage.mock_model.update(storage_mm)
+    storage_mm = storage.mock_model.get(storage_mm.id)
+
+    assert storage_mm.some_dict['inner_dict']['inner_value'] == 2
+    assert storage_mm.some_dict['value'] == -1
 
 
 def test_application_storage_factory():
@@ -70,6 +98,5 @@ def test_application_storage_factory():
     assert storage.deployment_update_step
     assert storage.deployment_modification
     assert storage.execution
-    assert storage.provider_context
 
     release_sqlite_storage(storage)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3ac35f63/tests/storage/test_models.py
----------------------------------------------------------------------
diff --git a/tests/storage/test_models.py b/tests/storage/test_models.py
index 2985eca..80f9fd3 100644
--- a/tests/storage/test_models.py
+++ b/tests/storage/test_models.py
@@ -12,19 +12,21 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
-from contextlib import contextmanager
 from datetime import datetime
+from contextlib import contextmanager
+
 import pytest
 
 from aria import application_model_storage
-from aria.storage import exceptions
-from aria.storage import sql_mapi
-from aria.storage.models import (
+from aria.storage import (
+    exceptions,
+    sql_mapi,
+)
+from aria.storage.model import (
     DeploymentUpdateStep,
     Blueprint,
     Execution,
     Task,
-    ProviderContext,
     Plugin,
     Deployment,
     Node,
@@ -835,23 +837,3 @@ class TestTask(object):
             create_task(max_attempts=0)
         with pytest.raises(ValueError):
             create_task(max_attempts=-2)
-
-
-def test_inner_dict_update(empty_storage):
-    inner_dict = {'inner_value': 1}
-    pc = ProviderContext(name='name', context={
-        'inner_dict': inner_dict,
-        'value': 0
-    })
-    empty_storage.provider_context.put(pc)
-
-    storage_pc = empty_storage.provider_context.get(pc.id)
-    assert storage_pc == pc
-
-    storage_pc.context['inner_dict']['inner_value'] = 2
-    storage_pc.context['value'] = -1
-    empty_storage.provider_context.update(storage_pc)
-    storage_pc = empty_storage.provider_context.get(pc.id)
-
-    assert storage_pc.context['inner_dict']['inner_value'] == 2
-    assert storage_pc.context['value'] == -1


Mime
View raw message