Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
    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'), [])
Ejemplo n.º 5
0
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:
    api.add_resource_type(rt)

app = apifw.create_bottle_application(api, counter, dict_logger, config,
                                      resource_types)

# If we are running this program directly with Python, and not via
# gunicorn, we can use the Bottle built-in debug server, which can
# make some things easier to debug.

if __name__ == '__main__':
    print('running in debug mode')
Ejemplo n.º 6
0
 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')
Ejemplo n.º 7
0
 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'), [])
Ejemplo n.º 8
0
 def test_returns_routes_for_allow_path(self):
     api = qvarn.QvarnAPI()
     self.assertNotEqual(api.find_missing_route('/allow'), [])
Ejemplo n.º 9
0
 def test_returns_routes_for_version_path(self):
     api = qvarn.QvarnAPI()
     self.assertNotEqual(api.find_missing_route('/version'), [])
Ejemplo n.º 10
0
 def test_does_allow_ids_with_right_scope(self):
     api = qvarn.QvarnAPI()
     claims = {'scope': 'uapi_set_meta_fields'}
     self.assertTrue(api.is_id_allowed(claims))
Ejemplo n.º 11
0
 def test_does_not_allow_ids_normally(self):
     api = qvarn.QvarnAPI()
     claims = {'scope': 'uapi_version_get'}
     self.assertFalse(api.is_id_allowed(claims))