provide (almost) automatic creation of type records in database
This commit is contained in:
		
							parent
							
								
									1e165a711c
								
							
						
					
					
						commit
						1bf5e82afc
					
				
					 2 changed files with 21 additions and 8 deletions
				
			
		|  | @ -17,6 +17,7 @@ class Concept(Track): | ||||||
| class Concepts(Container): | class Concepts(Container): | ||||||
| 
 | 
 | ||||||
|     insertOnChange = False |     insertOnChange = False | ||||||
|  |     indexes = None | ||||||
|   |   | ||||||
| 
 | 
 | ||||||
| class Predicate(Concept): | class Predicate(Concept): | ||||||
|  | @ -69,3 +70,15 @@ class Types(Concepts): | ||||||
|     itemFactory = Type |     itemFactory = Type | ||||||
|     indexes = [('name',), ('tprefix',)] |     indexes = [('name',), ('tprefix',)] | ||||||
|     tableName = 'types' |     tableName = 'types' | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | def storeType(storage, cls, name): | ||||||
|  |     types = storage.create(Types) | ||||||
|  |     types.save(Type(name, cls.prefix)) | ||||||
|  |     storage.commit() | ||||||
|  | 
 | ||||||
|  | def setupCoreTypes(storage): | ||||||
|  |     for c in registry.values(): | ||||||
|  |         cls = c.itemFactory | ||||||
|  |         storeType(storage, cls, cls.__name__.lower()) | ||||||
|  | 
 | ||||||
|  |  | ||||||
|  | @ -77,16 +77,16 @@ def test_folder(self, config): | ||||||
| def test_type(self, config): | def test_type(self, config): | ||||||
|         storage = config.storageFactory(config.dbschema) |         storage = config.storageFactory(config.dbschema) | ||||||
|         storage.dropTable('types') |         storage.dropTable('types') | ||||||
|         types = storage.create(concept.Types) |         concept.setupCoreTypes(storage) | ||||||
|         ttype = concept.Type('type', concept.Type.prefix) |  | ||||||
|         ttid = types.save(ttype) |  | ||||||
|         self.assertEqual(ttid, 1) |  | ||||||
|         tps = list(ttype.values()) |  | ||||||
|         self.assertEqual(len(tps), 1) |  | ||||||
| 
 | 
 | ||||||
|         tfolder = concept.Type('folder', folder.Folder.prefix) |         types = storage.getContainer(concept.Type.prefix) | ||||||
|         tfid = types.save(tfolder) |         tps = list(types.query()) | ||||||
|  |         self.assertEqual(len(tps), 5) | ||||||
|  |         self.assertEqual(tps[0].name, 'track') | ||||||
|  | 
 | ||||||
|  |         tfolder = types.queryLast(name='folder') | ||||||
|         fldrs = list(tfolder.values()) |         fldrs = list(tfolder.values()) | ||||||
|         self.assertEqual(len(fldrs), 2) |         self.assertEqual(len(fldrs), 2) | ||||||
|  |         self.assertEqual(fldrs[0].name, 'top') | ||||||
| 
 | 
 | ||||||
|         storage.commit() |         storage.commit() | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue