Пример #1
0
 def _store_resource_types(self, specs_and_texts):
     qvarn.log.log('debug', msg_text='Storing specs in database')
     rst = qvarn.ResourceTypeStorage()
     with self._dbconn.transaction() as t:
         rst.prepare_tables(t)
         for spec, text in specs_and_texts:
             qvarn.log.log('debug', msg_text='Storing spec', spec=spec)
             rst.add_or_update_spec(t, spec, text)
Пример #2
0
    def setUp(self):
        self.app = qvarn.BackendApplication()
        self.app._dbconn = qvarn.DatabaseConnection()
        self.app._dbconn.set_sql(qvarn.SqliteAdapter())
        self.spec = yaml.safe_load(self.spec_text)

        with self.app._dbconn.transaction() as t:
            rts = qvarn.ResourceTypeStorage()
            rts.prepare_tables(t)
            rts.add_or_update_spec(t, self.spec, self.spec_text)
Пример #3
0
 def _load_specs_from_db(self):
     qvarn.log.log('debug', msg_text='Loading specs from database')
     specs = []
     rst = qvarn.ResourceTypeStorage()
     with self._dbconn.transaction() as t:
         type_names = rst.get_types(t)
         for type_name in type_names:
             qvarn.log.log('debug',
                           msg_text='Loading {!r}'.format(type_name))
             spec = rst.get_spec(t, type_name)
             specs.append(spec)
     return specs
Пример #4
0
    def test_delete_type(self):
        spec = {
            'type': 'person',
            'blah': 'BLAH',
        }
        spec_text = yaml.safe_dump(spec)

        with self.transaction() as t:
            rts = qvarn.ResourceTypeStorage()
            rts.prepare_tables(t)
            rts.add_or_update_spec(t, spec, spec_text)
            rts.delete_spec(t, spec[u'type'])
            self.assertEqual(rts.get_types(t), [])
Пример #5
0
    def test_spec_with_blob(self):
        text = '''\
path: /files
type: file
versions:
- prototype: {id: '', revision: '', type: '', foo: blob}
  version: v0
'''
        spec = yaml.safe_load(text)

        with self.transaction() as t:
            rts = qvarn.ResourceTypeStorage()
            rts.prepare_tables(t)
            rts.add_or_update_spec(t, spec, text)
            self.assertEqual(rts.get_types(t), ['file'])
Пример #6
0
 def _get_spec_for_resource_type(self, path):
     qvarn.log.log('debug',
                   msg_text='Loading spec from database',
                   path=path)
     rst = qvarn.ResourceTypeStorage()
     with self._dbconn.transaction() as t:
         type_names = rst.get_types(t)
         for type_name in type_names:
             spec = rst.get_spec(t, type_name)
             if spec[u'path'] == path or path.startswith(spec[u'path'] +
                                                         u'/'):
                 qvarn.log.log('debug',
                               msg_text='Found spec',
                               path=path,
                               spec=spec)
                 return spec
     qvarn.log.log('debug', msg_text='No spec found for path', path=path)
     return None
Пример #7
0
    def test_updates_existing_type(self):
        spec_v1 = {
            'type': 'person',
            'blah': 'BLAH',
        }
        spec_v1_text = yaml.safe_dump(spec_v1)

        spec_v2 = spec_v1.copy()
        spec_v2['bling'] = 'blong'
        spec_v2_text = yaml.safe_dump(spec_v2)

        with self.transaction() as t:
            rts = qvarn.ResourceTypeStorage()
            rts.prepare_tables(t)
            rts.add_or_update_spec(t, spec_v1, spec_v1_text)
            rts.add_or_update_spec(t, spec_v2, spec_v2_text)
            self.assertEqual(rts.get_types(t), [spec_v2['type']])
            self.assertEqual(rts.get_spec(t, spec_v2['type']), spec_v2)
Пример #8
0
 def test_has_no_types_initally(self):
     with self.transaction() as t:
         rts = qvarn.ResourceTypeStorage()
         rts.prepare_tables(t)
         self.assertEqual(rts.get_types(t), [])