Exemple #1
0
def test_args_pretty(testapp, pretty, lines):
    """Sitemap processor has to respect pretty argument."""

    timepoint = datetime.datetime.fromtimestamp(0, tz=datetime.timezone.utc)
    stream = sitemap.process(
        testapp,
        [
            holocron.WebSiteItem({
                "destination": pathlib.Path("1.html"),
                "updated": timepoint,
                "baseurl": testapp.metadata["url"],
            })
        ],
        pretty=pretty,
    )

    assert isinstance(stream, collections.abc.Iterable)

    items = list(stream)
    assert items == [
        holocron.WebSiteItem({
            "destination": pathlib.Path("1.html"),
            "updated": timepoint,
            "baseurl": testapp.metadata["url"],
        }),
        holocron.WebSiteItem({
            "source": pathlib.Path("sitemap://sitemap.xml"),
            "destination": pathlib.Path("sitemap.xml"),
            "content": unittest.mock.ANY,
            "baseurl": testapp.metadata["url"],
        }),
    ]
    assert len(items[-1]["content"].splitlines()) == lines
Exemple #2
0
def test_args_save_as_unsupported(testapp, document_path, sitemap_path):
    """Sitemap process has to check enlisted URLs for compatibility."""

    timepoint = datetime.datetime.fromtimestamp(0, tz=datetime.timezone.utc)
    stream = sitemap.process(
        testapp,
        [
            holocron.WebSiteItem({
                "destination": document_path,
                "updated": timepoint,
                "baseurl": testapp.metadata["url"],
            })
        ],
        save_as=str(sitemap_path),
    )

    assert isinstance(stream, collections.abc.Iterable)

    with pytest.raises(ValueError) as excinfo:
        next(stream)

    excinfo.match(
        "The location of a Sitemap file determines the set of URLs "
        "that can be included in that Sitemap. A Sitemap file located "
        "at .* can include any URLs starting with .* but can not "
        "include .*.")
Exemple #3
0
def test_args_save_as(testapp, save_as):
    """Sitemap processor has to respect save_as argument."""

    timepoint = datetime.datetime.fromtimestamp(0, tz=datetime.timezone.utc)
    stream = sitemap.process(
        testapp,
        [
            holocron.WebSiteItem({
                "destination": pathlib.Path("posts", "1.html"),
                "updated": timepoint,
                "baseurl": testapp.metadata["url"],
            })
        ],
        save_as=str(save_as),
    )

    assert isinstance(stream, collections.abc.Iterable)
    assert list(stream) == [
        holocron.WebSiteItem({
            "destination": pathlib.Path("posts", "1.html"),
            "updated": timepoint,
            "baseurl": testapp.metadata["url"],
        }),
        holocron.WebSiteItem({
            "source": pathlib.Path("sitemap://", save_as),
            "destination": pathlib.Path(save_as),
            "content": unittest.mock.ANY,
            "baseurl": testapp.metadata["url"],
        }),
    ]
Exemple #4
0
def test_item_many(testapp, amount):
    """Sitemap processor has to work with stream."""

    timepoint = datetime.datetime.fromtimestamp(0, tz=datetime.timezone.utc)
    stream = sitemap.process(
        testapp,
        [
            holocron.WebSiteItem({
                "destination": pathlib.Path(str(i)),
                "updated": timepoint,
                "baseurl": testapp.metadata["url"],
            }) for i in range(amount)
        ],
    )

    assert isinstance(stream, collections.abc.Iterable)
    assert list(stream) == list(
        itertools.chain(
            [
                holocron.WebSiteItem({
                    "destination": pathlib.Path(str(i)),
                    "updated": timepoint,
                    "baseurl": testapp.metadata["url"],
                }) for i in range(amount)
            ],
            [
                holocron.WebSiteItem({
                    "source":
                    pathlib.Path("sitemap://sitemap.xml"),
                    "destination":
                    pathlib.Path("sitemap.xml"),
                    "content":
                    _pytest_xmlasdict(
                        {
                            "urlset": {
                                "@xmlns":
                                "http://www.sitemaps.org/schemas/sitemap/0.9",
                                "url": [{
                                    "loc": "https://yoda.ua/%d" % i,
                                    "lastmod": "1970-01-01T00:00:00+00:00",
                                } for i in range(amount)],
                            }
                        },
                        force_list=["url"],
                    ),
                    "baseurl":
                    testapp.metadata["url"],
                })
            ],
        ))
Exemple #5
0
def test_args_gzip(testapp):
    """Sitemap processor has to respect gzip argument."""

    timepoint = datetime.datetime.fromtimestamp(0, tz=datetime.timezone.utc)
    stream = sitemap.process(
        testapp,
        [
            holocron.WebSiteItem({
                "destination": pathlib.Path("1.html"),
                "updated": timepoint,
                "baseurl": testapp.metadata["url"],
            })
        ],
        gzip=True,
    )

    assert isinstance(stream, collections.abc.Iterable)
    assert list(stream) == [
        holocron.WebSiteItem({
            "destination": pathlib.Path("1.html"),
            "updated": timepoint,
            "baseurl": testapp.metadata["url"],
        }),
        holocron.WebSiteItem({
            "source":
            pathlib.Path("sitemap://sitemap.xml.gz"),
            "destination":
            pathlib.Path("sitemap.xml.gz"),
            "content":
            _pytest_xmlasdict(
                {
                    "urlset": {
                        "@xmlns":
                        "http://www.sitemaps.org/schemas/sitemap/0.9",
                        "url": {
                            "loc": "https://yoda.ua/1.html",
                            "lastmod": "1970-01-01T00:00:00+00:00",
                        },
                    }
                },
                ungzip=True,
            ),
            "baseurl":
            testapp.metadata["url"],
        }),
    ]
Exemple #6
0
def test_item(testapp, filename, escaped):
    """Sitemap processor has to work!"""

    timepoint = datetime.datetime.fromtimestamp(0, tz=datetime.timezone.utc)
    stream = sitemap.process(
        testapp,
        [
            holocron.WebSiteItem({
                "destination": pathlib.Path(filename),
                "updated": timepoint,
                "baseurl": testapp.metadata["url"],
            })
        ],
    )

    assert isinstance(stream, collections.abc.Iterable)
    assert list(stream) == [
        holocron.WebSiteItem({
            "destination": pathlib.Path(filename),
            "updated": timepoint,
            "baseurl": testapp.metadata["url"],
        }),
        holocron.WebSiteItem({
            "source":
            pathlib.Path("sitemap://sitemap.xml"),
            "destination":
            pathlib.Path("sitemap.xml"),
            "content":
            _pytest_xmlasdict({
                "urlset": {
                    "@xmlns": "http://www.sitemaps.org/schemas/sitemap/0.9",
                    "url": {
                        "loc": "https://yoda.ua/" + escaped,
                        "lastmod": "1970-01-01T00:00:00+00:00",
                    },
                }
            }),
            "baseurl":
            testapp.metadata["url"],
        }),
    ]
Exemple #7
0
def test_item_many_zero(testapp):
    """Sitemap processor has to work with stream of zero items."""

    stream = sitemap.process(testapp, [])

    assert isinstance(stream, collections.abc.Iterable)
    assert list(stream) == [
        holocron.WebSiteItem({
            "source":
            pathlib.Path("sitemap://sitemap.xml"),
            "destination":
            pathlib.Path("sitemap.xml"),
            "content":
            _pytest_xmlasdict({
                "urlset": {
                    "@xmlns": "http://www.sitemaps.org/schemas/sitemap/0.9"
                }
            }),
            "baseurl":
            testapp.metadata["url"],
        })
    ]
Exemple #8
0
def test_args_bad_value(testapp, args, error):
    """Sitemap processor has to validate input arguments."""

    with pytest.raises(ValueError) as excinfo:
        next(sitemap.process(testapp, [], **args))
    assert str(excinfo.value) == error