summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2017-10-12 15:41:09 +0300
committerLars Wirzenius <liw@liw.fi>2017-10-12 15:41:09 +0300
commitac7bacfce90b38a65bbb017c6283ba1482c74278 (patch)
tree34dd519b23fc4f7aa8cdfa07f0ff77912a4b5cf9
parent894afeab0e4cab70c6629a611664cdb922aa0aa3 (diff)
downloadqvisqve-ac7bacfce90b38a65bbb017c6283ba1482c74278.tar.gz
Refactor: move some "builtin" resource types into yaml files
-rw-r--r--qvarn/api.py74
-rw-r--r--qvarn/api_tests.py8
-rw-r--r--resource_type/listeners.yaml11
-rw-r--r--resource_type/notifications.yaml13
4 files changed, 32 insertions, 74 deletions
diff --git a/qvarn/api.py b/qvarn/api.py
index 6211f14..6b3c8fd 100644
--- a/qvarn/api.py
+++ b/qvarn/api.py
@@ -14,68 +14,9 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-import io
-
-import yaml
-
import qvarn
-resource_type_spec_yaml = '''
-type: resource_type
-path: /resource_types
-versions:
-
-- version: v0
- prototype:
- type: ""
- id: ""
- revision: ""
- name: ""
- yaml: ""
-'''
-
-listener_spec = {
- 'type': 'listener',
- 'path': '/listeners',
- 'versions': [
- {
- 'version': 'v0',
- 'prototype': {
- 'id': '',
- 'type': '',
- 'revision': '',
- 'notify_of_new': False,
- 'listen_on_all': False,
- 'listen_on': [''],
- },
- 'subpaths': {},
- },
- ],
-}
-
-notification_spec = {
- 'type': 'notification',
- 'path': '/notifications',
- 'versions': [
- {
- 'version': 'v0',
- 'prototype': {
- 'id': '',
- 'type': '',
- 'revision': '',
- 'listener_id': '',
- 'resource_id': '',
- 'resource_revision': '',
- 'resource_change': '',
- 'timestamp': '',
- },
- 'subpaths': {},
- },
- ],
-}
-
-
class QvarnAPI:
def __init__(self):
@@ -90,21 +31,6 @@ class QvarnAPI:
def set_object_store(self, store):
self._store = store
self._store.create_store(obj_id=str, subpath=str)
- self.set_up_resource_types()
-
- def set_up_resource_types(self):
- f = io.StringIO(resource_type_spec_yaml)
- spec = yaml.safe_load(f)
- rt = qvarn.ResourceType()
- rt.from_spec(spec)
- self._rt_coll = qvarn.CollectionAPI()
- self._rt_coll.set_object_store(self._store)
- self._rt_coll.set_resource_type(rt)
-
- for spec in [listener_spec, notification_spec]:
- rt2 = qvarn.ResourceType()
- rt2.from_spec(spec)
- self.add_resource_type(rt2)
def add_resource_type(self, rt):
path = rt.get_path()
diff --git a/qvarn/api_tests.py b/qvarn/api_tests.py
index 0669b4c..23e6143 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 os
import unittest
@@ -62,6 +63,13 @@ class QvarnAPITests(unittest.TestCase):
api = qvarn.QvarnAPI()
api.set_object_store(store)
api.add_resource_type(rt)
+
+ dirname = os.path.dirname(qvarn.__file__)
+ dirname = os.path.join(dirname, '../resource_type')
+ resource_types = qvarn.load_resource_types(dirname)
+ for rt in resource_types:
+ api.add_resource_type(rt)
+
self.assertNotEqual(api.find_missing_route('/subjects'), [])
def test_get_resource_type_raises_error_for_unknown_path(self):
diff --git a/resource_type/listeners.yaml b/resource_type/listeners.yaml
new file mode 100644
index 0000000..07c2e53
--- /dev/null
+++ b/resource_type/listeners.yaml
@@ -0,0 +1,11 @@
+type: listener
+path: /listeners
+versions:
+ - version: v0
+ prototype:
+ id: ""
+ type: ""
+ revision: ""
+ notify_of_new: false
+ listen_on_all: false
+ listen_on: [""]
diff --git a/resource_type/notifications.yaml b/resource_type/notifications.yaml
new file mode 100644
index 0000000..9660282
--- /dev/null
+++ b/resource_type/notifications.yaml
@@ -0,0 +1,13 @@
+type: notification
+path: /notifications
+versions:
+ - version: v0
+ prototype:
+ id: ""
+ type: ""
+ revision: ""
+ listener_id: ""
+ resource_id: ""
+ resource_revision: ""
+ resource_change: ""
+ timestamp: ""