Пример #1
0
def provider_batch():
    """Create and commit a batch of Provider instances,
    with associated collections."""
    providers = [ProviderFactory() for _ in range(randint(3, 5))]
    for provider in providers:
        CollectionFactory.create_batch(randint(0, 3), provider=provider)
    return providers
Пример #2
0
def project_build(**id):
    """Build and return an uncommitted Project instance.
    Referenced collections are however committed."""
    return ProjectFactory.build(
        **id,
        collections=CollectionFactory.create_batch(randint(0, 3)),
    )
Пример #3
0
def project_batch():
    """Create and commit a batch of Project instances."""
    return [
        ProjectFactory(
            collections=CollectionFactory.create_batch(randint(0, 3)))
        for _ in range(randint(3, 5))
    ]
Пример #4
0
def collection_build(**id):
    """Build and return an uncommitted Collection instance.
    Referenced provider is however committed."""
    return CollectionFactory.build(
        **id,
        provider=(provider := ProviderFactory()),
        provider_id=provider.id,
    )
Пример #5
0
def role_build(collection=None, **id):
    """Build and return an uncommitted Role instance.
    Referenced scopes and/or collection are however committed."""
    return RoleFactory.build(
        **id,
        scopes=ScopeFactory.create_batch(randint(0, 3), type=choice(('odp', 'client'))),
        collection=collection or (collection := CollectionFactory() if randint(0, 1) else None),
        collection_id=collection.id if collection else None,
    )
Пример #6
0
def collection_batch_no_projects():
    """Create and commit a batch of Collection instances
    without projects, for testing the update API - we cannot
    assign projects to collections, only the other way around."""
    collections = [CollectionFactory() for _ in range(randint(3, 5))]
    for collection in collections:
        ClientFactory.create_batch(randint(0, 3), collection=collection)
        RoleFactory.create_batch(randint(0, 3), collection=collection)
    return collections
Пример #7
0
def collection_batch():
    """Create and commit a batch of Collection instances,
    with associated projects, clients and roles."""
    collections = [CollectionFactory() for _ in range(randint(3, 5))]
    ProjectFactory.create_batch(randint(0, 3), collections=collections)
    for collection in collections:
        ClientFactory.create_batch(randint(0, 3), collection=collection)
        RoleFactory.create_batch(randint(0, 3), collection=collection)
    return collections
Пример #8
0
def client_build(collection=None, **id):
    """Build and return an uncommitted Client instance.
    Referenced scopes and/or collection are however committed."""
    return ClientFactory.build(
        **id,
        scopes=ScopeFactory.create_batch(randint(1, 3)),
        collection=collection
        or (collection := CollectionFactory() if randint(0, 1) else None),
        collection_id=collection.id if collection else None,
    )
Пример #9
0
def record_build(collection=None, collection_tags=None, **id):
    """Build and return an uncommitted Record instance.
    Referenced collection and schema are however committed."""
    record = RecordFactory.build(
        **id,
        collection=collection or (collection := CollectionFactory()),
        collection_id=collection.id,
        schema=(schema := SchemaFactory(type='metadata')),
        schema_id=schema.id,
        schema_type=schema.type,
    )
    if collection_tags:
        for ct in collection_tags:
            CollectionTagFactory(
                collection=record.collection,
                tag=TagFactory(id=ct, type='collection'),
            )
    return record
Пример #10
0
def test_list_roles(api, role_batch, scopes, collection_auth):
    authorized = ODPScope.ROLE_READ in scopes

    if collection_auth == CollectionAuth.MATCH:
        api_client_collection = role_batch[2].collection
        expected_result_batch = [role_batch[2]]
    elif collection_auth == CollectionAuth.MISMATCH:
        api_client_collection = CollectionFactory()
        expected_result_batch = []
    else:
        api_client_collection = None
        expected_result_batch = role_batch

    r = api(scopes, api_client_collection).get('/role/')

    if authorized:
        assert_json_results(r, r.json(), expected_result_batch)
    else:
        assert_forbidden(r)

    assert_db_state(role_batch)
Пример #11
0
def test_list_collections(api, collection_batch, scopes, collection_auth):
    authorized = ODPScope.COLLECTION_READ in scopes

    if collection_auth == CollectionAuth.MATCH:
        api_client_collection = collection_batch[2]
        expected_result_batch = [collection_batch[2]]
    elif collection_auth == CollectionAuth.MISMATCH:
        api_client_collection = CollectionFactory()
        expected_result_batch = [api_client_collection]
        collection_batch += [api_client_collection]
    else:
        api_client_collection = None
        expected_result_batch = collection_batch

    r = api(scopes, api_client_collection).get('/collection/')

    if authorized:
        assert_json_collection_results(r, r.json(), expected_result_batch)
    else:
        assert_forbidden(r)

    assert_db_state(collection_batch)
    assert_no_audit_log()
Пример #12
0
def test_create_project_with_collections():
    collections = CollectionFactory.create_batch(5)
    project = ProjectFactory(collections=collections)
    result = Session.execute(select(ProjectCollection)).scalars()
    assert [(row.project_id, row.collection_id) for row in result] \
           == [(project.id, collection.id) for collection in collections]
Пример #13
0
def test_create_collection():
    collection = CollectionFactory()
    result = Session.execute(select(Collection, Provider).join(Provider)).one()
    assert (result.Collection.id, result.Collection.name, result.Collection.doi_key, result.Collection.provider_id, result.Provider.name) \
           == (collection.id, collection.name, collection.doi_key, collection.provider.id, collection.provider.name)