Exemplo n.º 1
0
def test_load_index():
    arch = mock.Mock()
    arch.index_prefix = 'test'
    indexer = Indexer(archivist=arch)
    indexer.load_index(indexer.index_key)
    assert arch.get.called_once_with(indexer.index_key)
    assert indexer.index_key in indexer.indexes
Exemplo n.º 2
0
def test_on_save_with_non_archetype():
    arch = mock.Mock()
    arch.index_prefix = 'test'
    arch.siteconfig = {"site": asset_data}
    arch.all_archetypes.return_value = []
    asset = arch.new_resource(key='test.key', data=asset_data,
                              resourcetype='asset')
    indexer = Indexer(archivist=arch)

    indexer.on_save(asset)
    arch.assert_not_called()
Exemplo n.º 3
0
def test_full_reindex():
    arch = mock.Mock()
    arch.index_prefix = 'test'
    arch.siteconfig = {"site": asset_data}
    arch.all_archetypes.return_value = []
    indexer = Indexer(archivist=arch)
    indexer.full_reindex(indexer.index_key)

    ix = indexer.indexes[indexer.index_key]
    assert ix['title'] == asset_data['title']
    arch.all_archetypes.assert_called_with()
Exemplo n.º 4
0
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
Exemplo n.º 5
0
def test_record_from_asset():
    arch = S3archivist(testbucket, s3=mock.Mock(), siteconfig={})
    asset = arch.new_resource(key='test.key', data=asset_data)
    indexer = Indexer(archivist=arch)
    ix = indexer.record_for_asset(asset)
    assert ix['title'] == asset_data['title']
    assert ix['published'] == asset_data['published']
    assert ix['updated'] == asset_data['updated']
    assert ix['category'] == asset_data['category']
    assert ix['author'] == asset_data['author']
    assert ix['description'] == asset_data['description']
    assert ix['image'] == asset_data['image']
    assert ix['monograph'] == asset_data['monograph']
    assert ix['archetype'] == 'test.key'
    assert 'itemtype' in ix
Exemplo n.º 6
0
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