def test_driver_update_fails_with_invalid_id(): """ Tests updating a record fails if the record id is not found. """ with sqlite3.connect("index.sq3") as conn: driver = SQLAlchemyIndexDriver("sqlite:///index.sq3") did = str(uuid.uuid4()) baseid = str(uuid.uuid4()) rev = str(uuid.uuid4())[:8] form = "object" conn.execute( """ INSERT INTO index_record(did, baseid, rev, form, size) VALUES (?,?,?,?,?) """, (did, baseid, rev, form, None), ) conn.commit() with pytest.raises(NoRecordFound): driver.update("some_record_that_does_not_exist", "some_record_version", rev)
def _test_driver_update_record(): """ Tests updating of a record. """ with sqlite3.connect("index.sq3") as conn: driver = SQLAlchemyIndexDriver("sqlite:///index.sq3") did = str(uuid.uuid4()) baseid = str(uuid.uuid4()) rev = str(uuid.uuid4())[:8] form = "object" conn.execute( """ INSERT INTO index_record(did, baseid, rev, form, size) VALUES (?,?,?,?,?) """, (did, baseid, rev, form, None), ) conn.commit() # update_size = 256 update_urls = ["a", "b", "c"] # update_hashes = {"a": "1", "b": "2", "c": "3"} file_name = "test" version = "ver_123" changing_fields = { "urls": update_urls, "file_name": file_name, "version": version, } driver.update(did, rev, changing_fields) new_did, new_rev, new_file_name, new_version = conn.execute(""" SELECT did, rev, file_name, version FROM index_record """).fetchone() new_urls = sorted(url[0] for url in conn.execute(""" SELECT url FROM index_record_url """)) # new_hashes = { # h: v # for h, v in conn.execute( # """ # SELECT hash_type, hash_value FROM index_record_hash # """ # ) # } assert did == new_did, "record id does not match" assert rev != new_rev, "record revision matches prior" assert update_urls == new_urls, "record urls mismatch" assert file_name == new_file_name, "file_name does not match" assert version == new_version, "version does not match"
def test_driver_update_fails_with_no_records(): ''' Tests updating a record fails if there are no records. ''' driver = SQLAlchemyIndexDriver('sqlite:///index.sq3') with pytest.raises(NoRecordFound): driver.update('some_record_that_does_not_exist', 'some_revision')
def test_driver_update_fails_with_no_records(): ''' Tests updating a record fails if there are no records. ''' driver = SQLAlchemyIndexDriver('sqlite:///index.sq3') with pytest.raises(NoRecordFound): driver.update('some_record_that_does_not_exist', 'some_revision')
def test_driver_update_record(): ''' Tests updating of a record. ''' with sqlite3.connect('index.sq3') as conn: driver = SQLAlchemyIndexDriver('sqlite:///index.sq3') did = str(uuid.uuid4()) baseid = str(uuid.uuid4()) rev = str(uuid.uuid4())[:8] form = 'object' conn.execute( ''' INSERT INTO index_record(did, baseid, rev, form, size) VALUES (?,?,?,?,?) ''', (did, baseid, rev, form, None)) conn.commit() update_size = 256 update_urls = ['a', 'b', 'c'] update_hashes = { 'a': '1', 'b': '2', 'c': '3', } file_name = 'test' version = 'ver_123' driver.update(did, rev, urls=update_urls, file_name=file_name, version=version) new_did, new_rev, new_file_name, new_version = conn.execute(''' SELECT did, rev, file_name, version FROM index_record ''').fetchone() new_urls = sorted(url[0] for url in conn.execute(''' SELECT url FROM index_record_url ''')) new_hashes = { h: v for h, v in conn.execute(''' SELECT hash_type, hash_value FROM index_record_hash ''') } assert did == new_did, 'record id does not match' assert rev != new_rev, 'record revision matches prior' assert update_urls == new_urls, 'record urls mismatch' assert file_name == new_file_name, 'file_name does not match' assert version == new_version, 'version does not match'
def test_driver_update_fails_with_no_records(): """ Tests updating a record fails if there are no records. """ driver = SQLAlchemyIndexDriver("sqlite:///index.sq3") with pytest.raises(NoRecordFound): driver.update("some_record_that_does_not_exist", "some_base_version", "some_revision")
def test_driver_update_record(): ''' Tests updating of a record. ''' with sqlite3.connect('index.sq3') as conn: driver = SQLAlchemyIndexDriver('sqlite:///index.sq3') did = str(uuid.uuid4()) rev = str(uuid.uuid4())[:8] form = 'object' conn.execute(''' INSERT INTO index_record VALUES (?,?,?,?) ''', (did, rev, form, None)) conn.commit() update_size = 256 update_urls = ['a', 'b', 'c'] update_hashes = { 'a': '1', 'b': '2', 'c': '3', } driver.update(did, rev, size=update_size, urls=update_urls, hashes=update_hashes, ) new_did, new_rev, new_form, new_size = conn.execute(''' SELECT did, rev, form, size FROM index_record ''').fetchone() new_urls = sorted(url[0] for url in conn.execute(''' SELECT url FROM index_record_url ''')) new_hashes = {h:v for h,v in conn.execute(''' SELECT hash_type, hash_value FROM index_record_hash ''')} assert did == new_did, 'record id does not match' assert rev != new_rev, 'record revision matches prior' assert form == new_form, 'record form does not match' assert update_size == new_size, 'record size mismatch' assert update_urls == new_urls, 'record urls mismatch' assert update_hashes == new_hashes, 'record hashes mismatch'
def test_driver_update_fails_with_invalid_rev(): ''' Tests updating a record fails if the record rev is not invalid. ''' with sqlite3.connect('index.sq3') as conn: driver = SQLAlchemyIndexDriver('sqlite:///index.sq3') did = str(uuid.uuid4()) rev = str(uuid.uuid4())[:8] form = 'object' conn.execute(''' INSERT INTO index_record VALUES (?,?,?,?) ''', (did, rev, form, None)) conn.commit() with pytest.raises(RevisionMismatch): driver.update(did, 'some_revision')
def test_driver_update_fails_with_invalid_id(): ''' Tests updating a record fails if the record id is not found. ''' with sqlite3.connect('index.sq3') as conn: driver = SQLAlchemyIndexDriver('sqlite:///index.sq3') did = str(uuid.uuid4()) rev = str(uuid.uuid4())[:8] form = 'object' conn.execute(''' INSERT INTO index_record VALUES (?,?,?,?) ''', (did, rev, form, None)) conn.commit() with pytest.raises(NoRecordFound): driver.update('some_record_that_does_not_exist', rev)
def test_driver_update_fails_with_invalid_rev(): ''' Tests updating a record fails if the record rev is not invalid. ''' with sqlite3.connect('index.sq3') as conn: driver = SQLAlchemyIndexDriver('sqlite:///index.sq3') did = str(uuid.uuid4()) rev = str(uuid.uuid4())[:8] form = 'object' conn.execute( ''' INSERT INTO index_record VALUES (?,?,?,?) ''', (did, rev, form, None)) conn.commit() with pytest.raises(RevisionMismatch): driver.update(did, 'some_revision')
def test_driver_update_fails_with_invalid_id(): ''' Tests updating a record fails if the record id is not found. ''' with sqlite3.connect('index.sq3') as conn: driver = SQLAlchemyIndexDriver('sqlite:///index.sq3') did = str(uuid.uuid4()) rev = str(uuid.uuid4())[:8] form = 'object' conn.execute( ''' INSERT INTO index_record VALUES (?,?,?,?) ''', (did, rev, form, None)) conn.commit() with pytest.raises(NoRecordFound): driver.update('some_record_that_does_not_exist', rev)
def test_driver_update_fails_with_invalid_rev(): """ Tests updating a record fails if the record rev is not invalid. """ with sqlite3.connect("index.sq3") as conn: driver = SQLAlchemyIndexDriver("sqlite:///index.sq3") did = str(uuid.uuid4()) baseid = str(uuid.uuid4()) rev = str(uuid.uuid4())[:8] form = "object" conn.execute( """ INSERT INTO index_record(did, baseid, rev, form, size) VALUES (?,?,?,?,?) """, (did, baseid, rev, form, None), ) conn.commit() with pytest.raises(RevisionMismatch): driver.update(did, baseid, "some_revision")