def test_driver_get_all_versions_with_no_record():
    """
    Tests retrieval of the lattest record version
    """
    with sqlite3.connect("index.sq3") as conn:
        driver = SQLAlchemyIndexDriver("sqlite:///index.sq3")
        baseid = str(uuid.uuid4())

        for _ in range(3):

            did = str(uuid.uuid4())
            rev = str(uuid.uuid4())[:8]
            size = 512
            form = "object"

            conn.execute(
                """
                INSERT INTO index_record(did, baseid, rev, form, size) VALUES (?,?,?,?,?)
            """,
                (did, baseid, rev, form, size),
            )

        conn.commit()

        with pytest.raises(NoRecordFound):
            driver.get_all_versions("some baseid")
def test_driver_get_all_versions():
    """
    Tests retrieval of the lattest record version
    """
    with sqlite3.connect("index.sq3") as conn:
        driver = SQLAlchemyIndexDriver("sqlite:///index.sq3")
        baseid = str(uuid.uuid4())

        NUMBER_OF_RECORD = 3

        dids = []
        revs = []
        created_dates = []
        updated_dates = []

        for _ in range(NUMBER_OF_RECORD):

            did = str(uuid.uuid4())
            rev = str(uuid.uuid4())[:8]
            size = 512
            form = "object"
            created_date = datetime.now()
            updated_date = created_date

            dids.append(did)
            revs.append(rev)
            created_dates.append(created_date)
            updated_dates.append(updated_date)

            conn.execute(
                """
                INSERT INTO index_record(did, baseid, rev, form, size, created_date, updated_date) \
                    VALUES (?,?,?,?,?,?,?)
            """,
                (did, baseid, rev, form, size, created_date, updated_date),
            )

        conn.commit()

        records = driver.get_all_versions(did)
        assert len(records) == NUMBER_OF_RECORD, "the number of records does not match"

        # make sure records are returned in creation date order
        for i, record in records.items():
            assert record["did"] == dids[i], "record id does not match"
            assert record["rev"] == revs[i], "record revision does not match"
            assert record["size"] == size, "record size does not match"
            assert record["form"] == form, "record form does not match"
            assert (
                record["created_date"] == created_dates[i].isoformat()
            ), "created date does not match"
            assert (
                record["updated_date"] == updated_dates[i].isoformat()
            ), "updated date does not match"
Exemple #3
0
def test_driver_get_all_version():
    '''
    Tests retrieval of the lattest record version
    '''
    with sqlite3.connect('index.sq3') as conn:
        driver = SQLAlchemyIndexDriver('sqlite:///index.sq3')
        baseid = str(uuid.uuid4())

        NUMBER_OF_RECORD = 3

        dids = []
        revs = []
        created_dates = []
        updated_dates = []

        for _ in range(NUMBER_OF_RECORD):

            did = str(uuid.uuid4())
            rev = str(uuid.uuid4())[:8]
            size = 512
            form = 'object'
            created_date = datetime.now()
            updated_date = created_date

            dids.append(did)
            revs.append(rev)
            created_dates.append(created_date)
            updated_dates.append(updated_date)

            conn.execute(
                '''
                INSERT INTO index_record(did, baseid, rev, form, size, created_date, updated_date) \
                    VALUES (?,?,?,?,?,?,?)
            ''', (did, baseid, rev, form, size, created_date, updated_date))

        conn.commit()

        records = driver.get_all_versions(did)
        assert len(
            records
        ) == NUMBER_OF_RECORD, 'the number of records does not match'

        for i in range(NUMBER_OF_RECORD):
            record = records[i]
            assert record['did'] == dids[i], 'record id does not match'
            assert record['rev'] == revs[i], 'record revision does not match'
            assert record['size'] == size, 'record size does not match'
            assert record['form'] == form, 'record form does not match'
            assert record['created_date'] == created_dates[i].isoformat(
            ), 'created date does not match'
            assert record['updated_date'] == updated_dates[i].isoformat(
            ), 'updated date does not match'
def test_driver_get_all_version_with_no_record():
    '''
    Tests retrieval of the lattest record version
    '''
    with sqlite3.connect('index.sq3') as conn:
        driver = SQLAlchemyIndexDriver('sqlite:///index.sq3')
        baseid = str(uuid.uuid4())

        for _ in range(3):

            did = str(uuid.uuid4())
            rev = str(uuid.uuid4())[:8]
            size = 512
            form = 'object'

            conn.execute('''
                INSERT INTO index_record(did, baseid, rev, form, size) VALUES (?,?,?,?,?)
            ''', (did, baseid, rev, form, size))

        conn.commit()

        with pytest.raises(NoRecordFound):
            driver.get_all_versions('some baseid')