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: moved class creation into the driver
Date Mon, 21 Nov 2016 17:15:23 GMT
Repository: incubator-ariatosca
Updated Branches:
  refs/heads/wip-storage 01aebc283 -> c931d4516


moved class creation into the driver


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

Branch: refs/heads/wip-storage
Commit: c931d451608782a38588c0a661d2d5a5fd745445
Parents: 01aebc2
Author: mxmrlv <mxmrlv@gmail.com>
Authored: Mon Nov 21 19:14:44 2016 +0200
Committer: mxmrlv <mxmrlv@gmail.com>
Committed: Mon Nov 21 19:14:44 2016 +0200

----------------------------------------------------------------------
 aria/storage/__init__.py            | 8 ++++----
 tests/storage/__init__.py           | 6 ++++--
 tests/storage/test_drivers.py       | 6 +++---
 tests/storage/test_model_storage.py | 5 +++--
 4 files changed, 14 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c931d451/aria/storage/__init__.py
----------------------------------------------------------------------
diff --git a/aria/storage/__init__.py b/aria/storage/__init__.py
index 6353308..e659d38 100644
--- a/aria/storage/__init__.py
+++ b/aria/storage/__init__.py
@@ -155,11 +155,11 @@ class _ModelApi(object):
         :rtype: Model
         """
         with self._driver as connection:
-            data = connection.get(
+            return connection.get(
                 name=self._name,
                 entry_id=entry_id,
+                model_cls=self._model_cls,
                 **kwargs)
-        return self._model_cls(**data)
 
     def store(self, entry, **kwargs):
         """
@@ -192,8 +192,8 @@ class _ModelApi(object):
         Generator over the entries of model in storage.
         """
         with self._driver as connection:
-            for data in connection.iter(name=self._name, **kwargs):
-                yield self._model_cls(**data)
+            for data in connection.iter(name=self._name, model_cls=self._model_cls, **kwargs):
+                yield data
 
     def update(self, entry_id, **kwargs):
         """

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c931d451/tests/storage/__init__.py
----------------------------------------------------------------------
diff --git a/tests/storage/__init__.py b/tests/storage/__init__.py
index 9380707..d229578 100644
--- a/tests/storage/__init__.py
+++ b/tests/storage/__init__.py
@@ -27,16 +27,18 @@ class InMemoryModelDriver(ModelDriver):
         super(InMemoryModelDriver, self).__init__(**kwargs)
         self.storage = {}
         self.pointers = {}
+        self.model_cls = {}
 
     def create(self, name, model_cls, *args, **kwargs):
         self.storage[name] = {}
         self.pointers[name] = {}
+        self.model_cls[name] = model_cls
         self._create_pointer_mapping(name=name, model_cls=model_cls)
 
     def get(self, name, entry_id, **kwargs):
         base_entry = self.storage[name][entry_id].copy()
         base_entry.update(self._get_pointers(name, base_entry))
-        return base_entry.copy()
+        return self.model_cls[name](**base_entry.copy())
 
     def _get_pointers(self, name, base_entry, **kwargs):
         pointers = {}
@@ -90,7 +92,7 @@ class InMemoryModelDriver(ModelDriver):
         for base_entry in self.storage[name].values():
             base_entry = base_entry.copy()
             base_entry.update(self._get_pointers(name, base_entry, **kwargs))
-            yield base_entry.copy()
+            yield self.model_cls[name](**base_entry.copy())
 
     def update(self, name, entry_id, **kwargs):
         self.storage[name][entry_id].update(**kwargs)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c931d451/tests/storage/test_drivers.py
----------------------------------------------------------------------
diff --git a/tests/storage/test_drivers.py b/tests/storage/test_drivers.py
index 5bb091c..a310afa 100644
--- a/tests/storage/test_drivers.py
+++ b/tests/storage/test_drivers.py
@@ -80,12 +80,12 @@ def test_custom_driver():
         entry = Entry(**entry_dict)
 
         driver.store(name='entry', entry=entry, entry_id=entry.id)
-        assert driver.get(name='entry', entry_id='entry_id') == entry_dict
+        assert driver.get(name='entry', entry_id='entry_id') == entry
 
-        assert list(node for node in driver.iter('entry')) == [entry_dict]
+        assert list(node for node in driver.iter('entry')) == [entry]
 
         driver.update(name='entry', entry_id=entry.id, entry_value='new_value')
-        assert driver.get(name='entry', entry_id='entry_id')['entry_value'] == 'new_value'
+        assert driver.get(name='entry', entry_id='entry_id').entry_value == 'new_value'
 
         driver.delete(name='entry', entry_id='entry_id')
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c931d451/tests/storage/test_model_storage.py
----------------------------------------------------------------------
diff --git a/tests/storage/test_model_storage.py b/tests/storage/test_model_storage.py
index e6a83b1..9d51336 100644
--- a/tests/storage/test_model_storage.py
+++ b/tests/storage/test_model_storage.py
@@ -69,9 +69,10 @@ def test_storage_driver():
     assert storage._driver.get(
         name='provider_context',
         entry_id='id2',
-        model_cls=models.ProviderContext) == pc.fields_dict
+        model_cls=models.ProviderContext) == pc
 
-    assert [i for i in storage._driver.iter(name='provider_context')] == [pc.fields_dict]
+    assert [i for i in storage._driver.iter(name='provider_context',
+                                            model_cls=models.ProviderContext)] == [pc]
     assert [i for i in storage.provider_context] == [pc]
 
     storage.provider_context.delete('id2')


Mime
View raw message