summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2017-11-02 18:32:50 +0200
committerLars Wirzenius <liw@liw.fi>2017-11-02 18:50:23 +0200
commit607f62ae6bc8f684095e447569cff27ba7c8a5dd (patch)
treeb85035ae09af9e21fe9ae537b463aa8c161e0498
parentba16a904e153fc71f1537b588793659800c78b4c (diff)
downloadqvisqve-607f62ae6bc8f684095e447569cff27ba7c8a5dd.tar.gz
Add: allow resource type specs to be updated
-rw-r--r--NEWS4
-rw-r--r--qvarn/api.py23
-rw-r--r--qvarn/api_tests.py43
3 files changed, 60 insertions, 10 deletions
diff --git a/NEWS b/NEWS
index 9b7d8fe..79147a1 100644
--- a/NEWS
+++ b/NEWS
@@ -18,6 +18,10 @@ Bug fixes:
such as a string and an integer, Qvarn would crash. This is now
fixed.
+* Saulius Žemaitaitis reported that updating a resource type
+ specification YAML file and restarting Qvarn wouldn't make the new
+ version of the resource type availables. Fixed now.
+
Version 0.86, released 2017-10-10
----------------------------------
diff --git a/qvarn/api.py b/qvarn/api.py
index 0ff402a..aea0887 100644
--- a/qvarn/api.py
+++ b/qvarn/api.py
@@ -34,16 +34,19 @@ class QvarnAPI:
def add_resource_type(self, rt):
path = rt.get_path()
- objs = self._get_resource_type_given_path(path)
- if not objs:
- obj = {
- 'id': rt.get_type(),
- 'type': 'resource_type',
- 'path': path,
- 'spec': rt.as_dict(),
- }
- self._store.create_object(
- obj, obj_id=obj['id'], subpath='', auxtable=True)
+ keys = {
+ 'obj_id': rt.get_type(),
+ 'subpath': '',
+ }
+ self._store.remove_objects(**keys)
+
+ obj = {
+ 'id': rt.get_type(),
+ 'type': 'resource_type',
+ 'path': path,
+ 'spec': rt.as_dict(),
+ }
+ self._store.create_object(obj, **keys, auxtable=True)
def get_resource_type(self, path):
objs = self._get_resource_type_given_path(path)
diff --git a/qvarn/api_tests.py b/qvarn/api_tests.py
index 4567333..b6f8929 100644
--- a/qvarn/api_tests.py
+++ b/qvarn/api_tests.py
@@ -14,6 +14,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+import copy
import os
import unittest
@@ -131,3 +132,45 @@ class QvarnAPITests(unittest.TestCase):
api.set_object_store(store)
api.add_resource_type(rt)
self.assertEqual(api.add_resource_type(rt), None)
+
+ def test_updating_resource_type_with_new_version_works(self):
+ spec1 = {
+ 'type': 'subject',
+ 'path': '/subjects',
+ 'versions': [
+ {
+ 'version': 'v0',
+ 'prototype': {
+ 'id': '',
+ 'revision': '',
+ 'name': '',
+ },
+ },
+ ],
+ }
+
+ spec2 = copy.deepcopy(spec1)
+ spec2['versions'].append({
+ 'version': 'v1',
+ 'prototype': {
+ 'id': '',
+ 'revision': '',
+ 'name': '',
+ 'newfield': '',
+ },
+ })
+
+ store = qvarn.MemoryObjectStore()
+ api = qvarn.QvarnAPI()
+ api.set_object_store(store)
+
+ rt1 = qvarn.ResourceType()
+ rt1.from_spec(spec1)
+ api.add_resource_type(rt1)
+
+ rt2 = qvarn.ResourceType()
+ rt2.from_spec(spec2)
+ api.add_resource_type(rt2)
+
+ rt = api.get_resource_type(spec1['path'])
+ self.assertEqual(rt.as_dict(), spec2)