def testcases_arrays_inside_yaml(): db_schema = Schema() user = Schema() user._add_child('name', SchemaString()) user._add_child('groups', SchemaList(SchemaString())) db_schema.hash('users', user) db0 = { 'users': { 'andrea': { 'name': 'Andrea', 'groups': ['one', 'two'], } } } db_schema.validate(db0) dm = DiskMap() dm.hint_file_yaml(user) disk_maps = {} disk_maps['vanilla'] = DiskMap() disk_maps['yaml'] = dm prefix = 'array_inside_yaml' res = get_combinations(db_schema, db0, prefix, operation_sequences, disk_maps) return res
def testcases_TranslateNone(): schema = Schema() user = Schema() user.string('name') schema.hash('users', user) db0 = {'users': {'andrea': {'name': 'Andrea'}, 'john': {'name': 'John'}}} disk_map_with_hint = DiskMap() disk_map_with_hint.hint_directory(schema, translations={'users': None}) disk_maps = {'vanilla': DiskMap(), 'hint': disk_map_with_hint} # disk_map_with_hint.hint_directory(schema['users'], pattern='%.user') prefix = 'tranlatenone' operation_sequences = [seq1] res = get_combinations(schema, db0, prefix, operation_sequences, disk_maps) return res
def testcases_arrays(): db_schema = Schema() db_schema.list('alist', SchemaString()) db0 = {'alist': ['one', 'two']} db_schema.validate(db0) disk_maps = {} disk_maps['vanilla'] = DiskMap() prefix = 'array1' res = get_combinations(db_schema, db0, prefix, operation_sequences, disk_maps) return res
def testcases_arrayplus(): db_schema = Schema() # - first: ciao # last: ciao # - first: # last: entry = Schema() entry.string('first') entry.string('last') db_schema.list('thelist', entry) db0 = { 'thelist': [ { 'first': 'John', 'last': 'Lennon' }, { 'first': 'Max', 'last': 'Power' }, ] } db_schema.validate(db0) disk_maps = {} disk_maps['vanilla'] = DiskMap() prefix = 'arrayplus' res = get_combinations(db_schema, db0, prefix, operation_sequences, disk_maps) return res
def testcases_minilibrary(): schema = Schema() things = Schema() models = SchemaHash(SchemaString()) posets = SchemaHash(SchemaString()) things._add_child('models', models) things._add_child('posets', posets) schema._add_child('things', things) dm = DiskMap() dm.hint_directory(schema, translations={'things': None}) dm.hint_directory(things, translations={'models': None, 'posets': None}) dm.hint_directory(posets, pattern='%.poset') dm.hint_directory(models, pattern='%.mcdp') db0 = { 'things': { 'models': { 'model1': 'mcdp {}', }, 'posets': { 'poset1': 'poset {}', }, }, } disk_maps = {'vanilla': DiskMap()} prefix = 'minilibrary' res = get_combinations(schema, db0, prefix, operation_sequences, disk_maps) return res
class DB(object): acl = SchemaList(SchemaList(SchemaString())) db = Schema() library = Schema() image = Schema() image_extensions = sorted(set(_.lower() for _ in MCDPConstants.exts_images)) for ext in image_extensions: image.bytes(ext, can_be_none=True) # and can be none library.hash('images', image) library.hash('documents', SchemaString()) with library.context_e('things') as things: for spec_name, spec in specs.items(): # @UnusedVariable thing = SchemaString() things.hash(spec_name, thing) shelf = Schema() shelf._add_child('acl', acl) with shelf.context_e('info') as shelf_info: shelf_info.string('desc_short', can_be_none=True) shelf_info.string('desc_long', can_be_none=True) shelf_info.list("authors", SchemaString()) shelf_info.list("dependencies", SchemaString()) shelf.hash('libraries', library) shelves = SchemaHash(shelf) repo = Schema() with repo.context_e('info') as repo_info: repo_info.string('desc_short', can_be_none=True) repo_info.string('desc_long', can_be_none=True) repo._add_child('shelves', shelves) user = Schema() with user.context_e('info') as user_info: user_info.string('name') user_info.string('username', can_be_none=True) user_info.date('account_created', can_be_none=True) user_info.date('account_last_active', can_be_none=True) user_info.string('website', can_be_none=True) user_info.string('affiliation', can_be_none=True) user_info.list('subscriptions', SchemaString()) user_info.string('email', can_be_none=True) with user_info.list_e('authentication_ids') as auth_id: auth_id.string('provider') auth_id.string('id', can_be_none=True) auth_id.string('password', can_be_none=True) user_info.list('groups', SchemaString()) user.hash('images', image) users = SchemaHash(user) user_db = Schema() user_db._add_child('users', users) db._add_child('user_db', user_db) db._add_child('repos', SchemaHash(repo)) dm = DiskMap() dm.hint_directory(shelves, pattern='%.mcdpshelf') dm.hint_directory(repo, translations={'info': 'mcdprepo.yaml'}) dm.hint_file_yaml(repo['info']) dm.hint_directory(shelf, translations={ 'info': 'mcdpshelf.yaml', 'libraries': None, 'acl': 'acl.yaml' }) dm.hint_file_yaml(shelf['info']) dm.hint_file_yaml(shelf['acl']) dm.hint_directory(shelf['libraries'], pattern='%.mcdplib') dm.hint_directory(users, pattern='%.mcdp_user') dm.hint_directory(user, translations={'info': 'user.yaml', 'images': None}) dm.hint_file_yaml(user['info']) dm.hint_directory(user_db, translations={'users': None}) dm.hint_directory(library, translations={ 'images': None, 'documents': None, 'things': None }) dm.hint_extensions(library['images'], image_extensions) dm.hint_extensions(user['images'], image_extensions) dm.hint_directory(library['documents'], pattern='%.md') spec_translations = dict((k, None) for k in list(specs)) dm.hint_directory(things, translations=spec_translations) for spec_name, spec in specs.items(): # @UnusedVariable dm.hint_directory(things[spec_name], pattern='%.' + spec.extension) view_manager = ViewManager(db) view_manager.set_view_class(user, User) view_manager.set_view_class(repo, RepoView) view_manager.set_view_class(shelf, Shelf) view_manager.set_view_class(user_info, UserInfo) view_manager.set_view_class(user_db, UserDB) view_manager.set_view_class(library, LibraryView)
def testcases_SimpleUserDB(): db_schema = Schema() schema_user = Schema() schema_user.string('name') schema_user.string('email', can_be_none=True) schema_user.list('groups', SchemaString()) db_schema.hash('users', schema_user) db0 = { 'users': { U1: { 'name': U1, 'email': '*****@*****.**', 'groups': ['group:admin', 'group:FDM'], }, U2: { 'name': 'Pinco Pallo', 'email': None, 'groups': ['group:FDM'], }, } } db_schema.validate(db0) disk_map_with_hint = DiskMap() disk_map_with_hint.hint_directory(db_schema['users'], pattern='%.user') disk_map_files_are_yaml= DiskMap() disk_map_files_are_yaml.hint_directory(db_schema['users'], pattern='%.yaml') disk_map_files_are_yaml.hint_file_yaml(db_schema['users'].prototype) disk_maps= {} disk_maps['vanilla'] = DiskMap() disk_maps['with_hint'] = disk_map_with_hint disk_maps['files_are_yaml'] = disk_map_files_are_yaml prefix='simpleuserdb' seqs = [ seq1, seq_set_list, seq_set_hash, seq_set_struct, ] res = get_combinations(db_schema, db0, prefix, seqs, disk_maps) return res