Exemplo n.º 1
0
def test_convert_to_cbz_adds_all_files_to_cbz(cleanup_test_directories,
                                              three_webpages_uri):
    comic = Comic("test", three_webpages_uri, "//img/@src", "//a/@href")
    comic.download()
    comic.convert_to_cbz()
    with ZipFile("{}.cbz".format(comic.name), mode="r") as cbz_file:
        assert len(cbz_file.infolist()) == 2
Exemplo n.º 2
0
def test_download_does_not_add_crawlers_in_main_process(
        mocker, cleanup_test_directories, three_webpages_uri):
    mocker.patch("webcomix.scrapy.crawler_worker.CrawlerWorker.start")
    mock_add_to_crawl = mocker.patch("scrapy.crawler.Crawler.crawl")
    comic = Comic("test", three_webpages_uri, "//img/@src", "//a/@href")
    comic.download()
    assert mock_add_to_crawl.call_count == 0
Exemplo n.º 3
0
def test_download_will_not_run_splash_settings_if_not_javascript(mocker):
    mocker.patch("os.path.isdir")
    mock_crawler_worker = mocker.patch("webcomix.comic.CrawlerWorker")
    comic = Comic(mocker.ANY, mocker.ANY, mocker.ANY, mocker.ANY, mocker.ANY)
    comic.download()
    settings = mock_crawler_worker.call_args_list[0][0][0]
    assert all(setting not in settings.items()
               for setting in SPLASH_SETTINGS.items())
Exemplo n.º 4
0
def test_download_saves_the_files_with_correct_first_item(
        cleanup_test_directories, three_webpages_uri):
    comic = Comic("test",
                  three_webpages_uri,
                  "//img/@src",
                  "//a/@href",
                  start_page=10)
    comic.download()
    files = next(os.walk("test"))[2]
    assert sorted(files) == ["10", "11"]
Exemplo n.º 5
0
def test_download_runs_the_worker(mocker, cleanup_test_directories):
    mock_crawler_running = mocker.patch(
        "webcomix.scrapy.crawler_worker.CrawlerWorker.start")
    comic = Comic(
        "xkcd",
        "http://xkcd.com/1/",
        "//div[@id='comic']//img/@src",
        "//a[@rel='next']/@href",
        False,
    )
    comic.download()
    assert mock_crawler_running.call_count == 1
Exemplo n.º 6
0
def test_download_with_alt_text_saves_the_text(cleanup_test_directories,
                                               three_webpages_alt_text_uri):
    comic = Comic(
        "test",
        three_webpages_alt_text_uri,
        "//img/@src",
        "//a/@href",
        alt_text="//img/@title",
    )
    comic.download()
    path, dirs, files = next(os.walk("test"))
    assert len(files) == 4
Exemplo n.º 7
0
def test_download_saves_the_files(cleanup_test_directories,
                                  three_webpages_uri):
    comic = Comic("test", three_webpages_uri, "//img/@src", "//a/@href")
    comic.download()
    path, dirs, files = next(os.walk("test"))
    assert len(files) == 2