def test_add_to_index(): arch = mock.Mock() arch.index_prefix = 'test' indexer = Indexer(archivist=arch) entries = [] indexer.indexes[indexer.index_key] = {"entries": entries} asset = arch.new_resource(key='test.key', data=asset_data) indexer.add_to_index(indexer.index_key, asset) assert len(entries) == 1
def test_on_delete(): arch = S3archivist(testbucket, s3=mock.Mock(), siteconfig={}) testkey = arch.archetype_prefix + 'test.key' asset = arch.new_resource(key=testkey, data=asset_data, resourcetype='archetype') asset2 = arch.new_resource(key='non-matching.key', data=asset_data, resourcetype='archetype') entries = [] indexer = Indexer(archivist=arch) indexer.indexes[indexer.index_key] = {"entries": entries} indexer.add_to_index(indexer.index_key, asset) indexer.add_to_index(indexer.index_key, asset2) assert len(entries) == 2 # just to be sure our setup worked indexer.on_delete(testkey) assert len(entries) == 1