aboutsummaryrefslogtreecommitdiffstats
path: root/tests/integration/test_wordpress_import.py
blob: 6d3bfb800e5ea2e449a9b64a4129cf5bc53139ff (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# -*- coding: utf-8 -*-
"""
Testing the wordpress import.

It will do create a new site with the import_wordpress command
and use that newly created site to make a build.
"""

import os.path
from glob import glob

import pytest

from nikola import __main__

from .helper import cd
from .test_empty_build import (  # NOQA
    test_archive_exists,
    test_avoid_double_slash_in_rss,
    test_check_files,
)


def test_import_created_files(build, target_dir):
    assert os.path.exists(target_dir)
    assert os.path.exists(os.path.join(target_dir, "conf.py"))


@pytest.mark.parametrize("dirname", ["pages", "posts"])
def test_filled_directories(build, target_dir, dirname):
    folder = os.path.join(target_dir, dirname)
    assert os.path.isdir(folder)
    content = glob(os.path.join(folder, "**"), recursive=True)
    assert any(os.path.isfile(element) for element in content)


@pytest.fixture(scope="module")
def build(target_dir, import_file):
    __main__.main(
        [
            "import_wordpress",
            "--no-downloads",
            "--output-folder",
            target_dir,
            import_file,
        ]
    )

    with cd(target_dir):
        result = __main__.main(["build"])
        assert not result


@pytest.fixture(scope="module")
def import_file(test_dir):
    """Path to the Wordpress export file."""
    return os.path.join(
        test_dir, "..", "data", "wordpress_import", "wordpress_export_example.xml"
    )