Exemplo n.º 1
0
def fixture(taxonomy, path):
    scheme, _, path = path.partition(':')
    append_index = scheme == 'base'
    if isinstance(taxonomy, ClassifyAuthors) and append_index:
        site = Nikola(TRANSLATIONS={"en": ""}, AUTHOR_PATH=path)
    elif isinstance(taxonomy, ClassifyAuthors) and not append_index:
        pytest.skip("There is no AUTHORS_INDEX_PATH setting")
    elif isinstance(taxonomy, ClassifyCategories) and append_index:
        site = Nikola(TRANSLATIONS={"en": ""}, CATEGORY_PATH=path)
    elif isinstance(taxonomy, ClassifyCategories) and not append_index:
        site = Nikola(TRANSLATIONS={"en": ""}, CATEGORIES_INDEX_PATH=path)
    elif isinstance(taxonomy, ClassifyTags) and append_index:
        site = Nikola(TRANSLATIONS={"en": ""}, TAG_PATH=path)
    elif isinstance(taxonomy, ClassifyTags) and not append_index:
        site = Nikola(TRANSLATIONS={"en": ""}, TAGS_INDEX_PATH=path)
    else:
        raise TypeError("Unknown taxonomy %r" % type(taxonomy))

    site._template_system = mock.MagicMock()
    site._template_system.template_deps.return_value = []
    site._template_system.name = "dummy"
    site.hierarchy_per_classification = {
        taxonomy.classification_name: {
            "en": []
        }
    }
    site.posts_per_classification = {taxonomy.classification_name: {"en": {}}}
    site.taxonomy_plugins = {taxonomy.classification_name: taxonomy}

    taxonomy.set_site(site)

    classifier = TaxonomiesClassifier()
    classifier.set_site(site)

    expected = path.strip("/")
    if append_index:
        expected += "/"
    if not expected.startswith("/"):
        expected = "/" + expected

    return site, classifier, taxonomy, append_index, expected