Пример #1
0
def assert_db_state(clients):
    """Verify that the DB client table contains the given client batch."""
    Session.expire_all()
    result = Session.execute(
        select(Client).where(Client.id != 'odp.test')).scalars().all()
    assert set((row.id, scope_ids(row), row.collection_id) for row in result) \
           == set((client.id, scope_ids(client), client.collection_id) for client in clients)
Пример #2
0
def assert_db_state(collections):
    """Verify that the DB collection table contains the given collection batch."""
    Session.expire_all()
    result = Session.execute(select(Collection)).scalars().all()
    result.sort(key=lambda c: c.id)
    collections.sort(key=lambda c: c.id)
    assert len(result) == len(collections)
    for n, row in enumerate(result):
        assert row.id == collections[n].id
        assert row.name == collections[n].name
        assert row.doi_key == collections[n].doi_key
        assert row.provider_id == collections[n].provider_id
        assert_new_timestamp(row.timestamp)
        assert project_ids(row) == project_ids(collections[n])
        assert client_ids(row) == client_ids(collections[n])
        assert role_ids(row) == role_ids(collections[n])
Пример #3
0
def assert_db_state(records):
    """Verify that the DB record table contains the given record batch."""
    Session.expire_all()
    result = Session.execute(select(Record)).scalars().all()
    result.sort(key=lambda r: r.id)
    records.sort(key=lambda r: r.id)
    assert len(result) == len(records)
    for n, row in enumerate(result):
        assert row.id == records[n].id
        assert row.doi == records[n].doi
        assert row.sid == records[n].sid
        assert row.metadata_ == records[n].metadata_
        assert_new_timestamp(row.timestamp)
        assert row.collection_id == records[n].collection_id
        assert row.schema_id == records[n].schema_id
        assert row.schema_type == records[n].schema_type
Пример #4
0
def assert_db_tag_state(collection_id, *collection_tags):
    """Verify that the collection_tag table contains the given collection tags."""
    Session.expire_all()
    result = Session.execute(select(CollectionTag)).scalars().all()
    result.sort(key=lambda r: r.timestamp)

    assert len(result) == len(collection_tags)
    for n, row in enumerate(result):
        assert row.collection_id == collection_id
        assert_new_timestamp(row.timestamp)
        if isinstance(collection_tag := collection_tags[n], CollectionTag):
            assert row.tag_id == collection_tag.tag_id
            assert row.user_id == collection_tag.user_id
            assert row.data == collection_tag.data
        else:
            assert row.tag_id == collection_tag['tag_id']
            assert row.user_id is None
            assert row.data == collection_tag['data']
Пример #5
0
def assert_db_state(scopes):
    """Verify that the DB scope table contains the given scope batch."""
    Session.expire_all()
    result = Session.execute(select(Scope)).scalars().all()
    assert set((row.id, row.type) for row in result) \
           == set((scope.id, scope.type) for scope in scopes)
Пример #6
0
def assert_db_state(catalogs):
    """Verify that the DB catalog table contains the given catalog batch."""
    Session.expire_all()
    result = Session.execute(select(Catalog)).scalars().all()
    assert set((row.id, row.schema_id, row.schema_type) for row in result) \
           == set((catalog.id, catalog.schema_id, catalog.schema_type) for catalog in catalogs)
Пример #7
0
def assert_db_state(schemas):
    """Verify that the DB schema table contains the given schema batch."""
    Session.expire_all()
    result = Session.execute(select(Schema)).scalars().all()
    assert set((row.id, row.type, row.uri) for row in result) \
           == set((schema.id, schema.type, schema.uri) for schema in schemas)
Пример #8
0
def assert_db_state(users):
    """Verify that the DB user table contains the given user batch."""
    Session.expire_all()
    result = Session.execute(select(User)).scalars().all()
    assert set((row.id, row.name, row.email, row.active, row.verified, role_ids(row)) for row in result) \
           == set((user.id, user.name, user.email, user.active, user.verified, role_ids(user)) for user in users)
Пример #9
0
def assert_db_state(tags):
    """Verify that the DB tag table contains the given tag batch."""
    Session.expire_all()
    result = Session.execute(select(Tag)).scalars().all()
    assert set((row.id, row.cardinality, row.public, row.scope_id, row.scope_type, row.schema_id, row.schema_type) for row in result) \
           == set((tag.id, tag.cardinality, tag.public, tag.scope_id, tag.scope_type, tag.schema_id, tag.schema_type) for tag in tags)
Пример #10
0
def assert_db_state(roles):
    """Verify that the DB role table contains the given role batch."""
    Session.expire_all()
    result = Session.execute(select(Role)).scalars().all()
    assert set((row.id, scope_ids(row), row.collection_id) for row in result) \
           == set((role.id, scope_ids(role), role.collection_id) for role in roles)
Пример #11
0
def assert_db_state(providers):
    """Verify that the DB provider table contains the given provider batch."""
    Session.expire_all()
    result = Session.execute(select(Provider)).scalars().all()
    assert set((row.id, row.name, collection_ids(row)) for row in result) \
           == set((provider.id, provider.name, collection_ids(provider)) for provider in providers)