def get_default_metaschema(): """This needs to be a method so it gets called after the test database is set up""" try: return MetaSchema.find()[0] except IndexError: ensure_schemas() return MetaSchema.find()[0]
def get_metaschemas(*args, **kwargs): """ List metaschemas with which a draft registration may be created. Only fetch the newest version for each schema. :return: serialized metaschemas :rtype: dict """ count = request.args.get('count', 100) include = request.args.get('include', 'latest') meta_schema_collection = database['metaschema'] meta_schemas = [] if include == 'latest': schema_names = meta_schema_collection.distinct('name') for name in schema_names: meta_schema_set = MetaSchema.find( Q('name', 'eq', name) & Q('schema_version', 'eq', 2) ) meta_schemas = meta_schemas + [s for s in meta_schema_set] else: meta_schemas = MetaSchema.find() meta_schemas = [ schema for schema in meta_schemas if schema.name in ACTIVE_META_SCHEMAS ] meta_schemas.sort(key=lambda a: ACTIVE_META_SCHEMAS.index(a.name)) return { 'meta_schemas': [ serialize_meta_schema(ms) for ms in meta_schemas[:count] ] }, http.OK
def get_metaschemas(*args, **kwargs): """ List metaschemas with which a draft registration may be created. Only fetch the newest version for each schema. :return: serialized metaschemas :rtype: dict """ count = request.args.get('count', 100) include = request.args.get('include', 'latest') meta_schema_collection = database['metaschema'] meta_schemas = [] if include == 'latest': schema_names = meta_schema_collection.distinct('name') for name in schema_names: meta_schema_set = MetaSchema.find( Q('name', 'eq', name) & Q('schema_version', 'eq', 2)) meta_schemas = meta_schemas + [s for s in meta_schema_set] else: meta_schemas = MetaSchema.find() meta_schemas = [ schema for schema in meta_schemas if schema.name in ACTIVE_META_SCHEMAS ] meta_schemas.sort(key=lambda a: ACTIVE_META_SCHEMAS.index(a.name)) return { 'meta_schemas': [serialize_meta_schema(ms) for ms in meta_schemas[:count]] }, http.OK
def test_ensure_schemas(self): # Should be zero MetaSchema records to begin with assert_equal(MetaSchema.find().count(), 0) ensure_schemas() assert_equal(MetaSchema.find().count(), len(OSF_META_SCHEMAS))
def get_default_metaschema(): """This needs to be a method so it gets called after the test database is set up""" try: return MetaSchema.find()[0] except IndexError: ensure_schemas() return MetaSchema.find()[0]
def test_ensure_schemas(self): # Should be zero MetaSchema records to begin with assert_equal( MetaSchema.find().count(), 0 ) ensure_schemas() assert_equal( MetaSchema.find().count(), len(OSF_META_SCHEMAS) )
def _create(cls, *args, **kwargs): branched_from = kwargs.get("branched_from") initiator = kwargs.get("initiator") registration_schema = kwargs.get("registration_schema") registration_metadata = kwargs.get("registration_metadata") if not branched_from: project_params = {} if initiator: project_params["creator"] = initiator branched_from = ProjectFactory(**project_params) initiator = branched_from.creator try: registration_schema = registration_schema or MetaSchema.find()[0] except IndexError: ensure_schemas() registration_metadata = registration_metadata or {} draft = DraftRegistration.create_from_node( branched_from, user=initiator, schema=registration_schema, data=registration_metadata ) return draft
def _create(cls, *args, **kwargs): branched_from = kwargs.get('branched_from') initiator = kwargs.get('initiator') registration_schema = kwargs.get('registration_schema') registration_metadata = kwargs.get('registration_metadata') if not branched_from: project_params = {} if initiator: project_params['creator'] = initiator branched_from = ProjectFactory(**project_params) initiator = branched_from.creator try: registration_schema = registration_schema or MetaSchema.find()[0] except IndexError: ensure_schemas() registration_metadata = registration_metadata or {} draft = DraftRegistration.create_from_node( branched_from, user=initiator, schema=registration_schema, data=registration_metadata, ) return draft
def test_metaschema_is_fine_with_same_name_but_different_version(self): MetaSchema(name='foo', schema_version=1).save() MetaSchema(name='foo', schema_version=2).save() assert_equal(MetaSchema.find(name='foo').count(), 2)
def get_schema(): all_schemas = MetaSchema.find() serialized_schemas = { 'schemas': [utils.serialize_meta_schema(s) for s in all_schemas] } return serialized_schemas
def test_metaschema_is_fine_with_same_name_but_different_version(self): MetaSchema(name='foo', schema_version=1).save() MetaSchema(name='foo', schema_version=2).save() assert_equal(MetaSchema.find(name='foo').count(), 2)
def get_schema(): all_schemas = MetaSchema.find() serialized_schemas = { 'schemas': [utils.serialize_meta_schema(s) for s in all_schemas] } return serialized_schemas