def test_add_resource_type_is_ok_adding_type_again(self): spec = { 'type': 'subject', 'path': '/subjects', 'versions': [ { 'version': 'v0', 'prototype': { 'id': '', 'revision': '', 'name': '', }, }, ], } rt = qvarn.ResourceType() rt.from_spec(spec) store = qvarn.MemoryObjectStore() api = qvarn.QvarnAPI() api.set_object_store(store) api.add_resource_type(rt) self.assertEqual(api.add_resource_type(rt), None)
def test_get_resource_type_returns_it_when_it_is_known(self): spec = { 'type': 'subject', 'path': '/subjects', 'versions': [ { 'version': 'v0', 'prototype': { 'id': '', 'revision': '', 'name': '', }, }, ], } rt = qvarn.ResourceType() rt.from_spec(spec) store = qvarn.MemoryObjectStore() api = qvarn.QvarnAPI() api.set_object_store(store) api.add_resource_type(rt) rt2 = api.get_resource_type(spec['path']) self.assertTrue(isinstance(rt2, qvarn.ResourceType)) self.assertEqual(rt2.as_dict(), spec)
def setUp(self): self.store = qvarn.MemoryObjectStore() spec = { 'type': 'subject', 'path': '/subjects', 'versions': [ { 'version': 'v0', 'prototype': { 'type': '', 'id': '', 'full_name': '', }, 'subpaths': { 'moar': { 'prototype': { 'nickname': '', }, }, }, }, ], } self.rt = qvarn.ResourceType() self.rt.from_spec(spec) self.coll = qvarn.CollectionAPI() self.coll.set_object_store(self.store) self.coll.set_resource_type(self.rt) self.next_id = 1 self.claims = { 'aud': 'test-client', 'sub': 'test-user', } self.client_id = 'test-client' self.user_id = 'test-user' rule = { 'method': 'GET', 'client_id': self.client_id, 'user_id': self.user_id, 'subpath': '', 'resource_id': '*', 'resource_type': 'subject', 'resource_field': None, 'resource_value': None, } self.store.add_allow_rule(rule)
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)
def setUp(self): self.store = qvarn.MemoryObjectStore() spec = { 'type': 'subject', 'path': '/subjects', 'versions': [ { 'version': 'v0', 'prototype': { 'type': '', 'id': '', 'revision': '', 'full_name': '', 'names': [ { 'sort_key': '', }, ], 'things': [ { 'things': '', 'other': '', }, ], }, 'subpaths': { 'sub': { 'prototype': { 'subfield': '', }, }, }, }, ], } self.rt = qvarn.ResourceType() self.rt.from_spec(spec) self.coll = qvarn.CollectionAPI() self.coll.set_object_store(self.store) self.coll.set_resource_type(self.rt)
def test_returns_routes_for_known_resource_type(self): spec = { 'type': 'subject', 'path': '/subjects', 'versions': [ { 'version': 'v0', 'prototype': { 'id': '', 'revision': '', 'name': '', }, 'subpaths': { 'sub': { 'prototype': { 'subfoo': '', }, }, }, }, ], } rt = qvarn.ResourceType() rt.from_spec(spec) store = qvarn.MemoryObjectStore() api = qvarn.QvarnAPI() api.set_object_store(store) api.add_resource_type(rt) api.set_base_url('https://qvarn.example.com') 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'), [])
'body': 'blob', 'content-type': '', }, }, }, 'files': [ 'blob', ], }, ], }) resource_types = qvarn.load_resource_types(config['resource-type-dir']) if config['memory-database']: store = qvarn.MemoryObjectStore() else: sql = qvarn.PostgresAdapter() sql.connect(**config['database']) store = qvarn.PostgresObjectStore(sql) if config.get('enable-fine-grained-access-control'): store.enable_fine_grained_access_control() qvarn.log.log('info', msg_text='Fine grained access control?', enabled=store.have_fine_grained_access_control()) api = qvarn.QvarnAPI() api.set_base_url(config['baseurl']) api.set_object_store(store) api.add_resource_type(subject) for rt in resource_types:
def test_get_resource_type_raises_error_for_unknown_path(self): store = qvarn.MemoryObjectStore() api = qvarn.QvarnAPI() api.set_object_store(store) with self.assertRaises(qvarn.NoSuchResourceType): api.get_resource_type('/subjects')
def test_returns_no_routes_for_unknown_resource_type(self): store = qvarn.MemoryObjectStore() api = qvarn.QvarnAPI() api.set_object_store(store) self.assertEqual(api.find_missing_route('/subjects'), [])
def create_store(self, **keys): store = qvarn.MemoryObjectStore() store.create_store(**keys) return store