2013-03-04 18:10:27 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2016-10-28 22:21:41 +00:00
|
|
|
# Copyright (C) 2004-2008 Tristan Seligmann and Jonathan Jacobs
|
2016-05-05 21:33:48 +00:00
|
|
|
# Copyright (C) 2012-2014 Bastian Kleineidam
|
2017-10-12 21:56:39 +00:00
|
|
|
# Copyright (C) 2015-2017 Tobias Gruetzmacher
|
2016-05-05 21:33:48 +00:00
|
|
|
|
|
|
|
from __future__ import absolute_import, division, print_function
|
2016-03-07 00:08:57 +00:00
|
|
|
|
|
|
|
import pytest
|
2017-10-12 22:34:37 +00:00
|
|
|
import responses
|
2016-05-05 21:33:48 +00:00
|
|
|
|
2017-10-12 21:56:39 +00:00
|
|
|
import dosagelib.cmd
|
2017-10-12 22:34:37 +00:00
|
|
|
import httpmocks
|
|
|
|
|
2013-03-04 18:10:27 +00:00
|
|
|
|
2017-10-12 21:56:39 +00:00
|
|
|
def cmd(*options):
|
|
|
|
"""'Fake' run dosage with given options."""
|
|
|
|
return dosagelib.cmd.main(('--allow-multiple',) + options)
|
2013-03-04 18:10:27 +00:00
|
|
|
|
2017-10-12 22:34:37 +00:00
|
|
|
|
2017-10-12 21:56:39 +00:00
|
|
|
def cmd_ok(*options):
|
|
|
|
assert cmd(*options) == 0
|
2013-03-04 18:10:27 +00:00
|
|
|
|
2017-10-12 22:34:37 +00:00
|
|
|
|
2017-10-12 21:56:39 +00:00
|
|
|
def cmd_err(*options):
|
|
|
|
assert cmd(*options) == 1
|
2013-03-04 18:10:27 +00:00
|
|
|
|
2017-10-12 22:34:37 +00:00
|
|
|
|
2016-03-07 00:08:57 +00:00
|
|
|
class TestDosage(object):
|
2013-03-04 18:10:27 +00:00
|
|
|
"""Test the dosage commandline client."""
|
|
|
|
|
2016-03-07 00:08:57 +00:00
|
|
|
def test_list_comics(self):
|
2013-03-04 18:10:27 +00:00
|
|
|
for option in ("-l", "--list", "--singlelist"):
|
2017-10-12 21:56:39 +00:00
|
|
|
cmd_ok(option)
|
2016-03-07 00:08:57 +00:00
|
|
|
|
|
|
|
def test_display_version(self):
|
2017-10-12 21:56:39 +00:00
|
|
|
cmd_ok("--version")
|
2016-03-07 00:08:57 +00:00
|
|
|
|
|
|
|
def test_display_help(self):
|
2013-03-04 18:10:27 +00:00
|
|
|
for option in ("-h", "--help"):
|
2017-10-12 21:56:39 +00:00
|
|
|
with pytest.raises(SystemExit):
|
|
|
|
cmd(option)
|
2016-03-07 00:08:57 +00:00
|
|
|
|
|
|
|
def test_module_help(self):
|
2017-10-12 21:56:39 +00:00
|
|
|
cmd_ok("-m", "xkcd")
|
2016-03-07 00:08:57 +00:00
|
|
|
|
|
|
|
def test_no_comics_specified(self):
|
2017-10-12 21:56:39 +00:00
|
|
|
cmd_err()
|
2016-03-07 00:08:57 +00:00
|
|
|
|
|
|
|
def test_unknown_option(self):
|
2017-10-12 21:56:39 +00:00
|
|
|
with pytest.raises(SystemExit):
|
|
|
|
cmd('--imadoofus')
|
2016-03-07 00:08:57 +00:00
|
|
|
|
|
|
|
def test_multiple_comics_match(self):
|
2017-10-12 21:56:39 +00:00
|
|
|
cmd_err('Garfield')
|
2016-03-07 00:08:57 +00:00
|
|
|
|
2017-10-12 22:34:37 +00:00
|
|
|
@responses.activate
|
2016-05-05 21:33:48 +00:00
|
|
|
def test_fetch_html_and_rss_json(self, tmpdir):
|
2017-10-12 22:34:37 +00:00
|
|
|
httpmocks.xkcd()
|
2017-10-12 21:56:39 +00:00
|
|
|
cmd_ok("-n", "2", "-v", "-b", str(tmpdir), "-o", "html", "-o", "rss",
|
2017-10-12 22:34:37 +00:00
|
|
|
"-o", "json", "xkcd")
|
2016-03-07 00:08:57 +00:00
|
|
|
|
2017-10-12 22:34:37 +00:00
|
|
|
@responses.activate
|
2016-03-28 14:29:57 +00:00
|
|
|
def test_fetch_html_and_rss_2(self, tmpdir):
|
2017-10-12 22:34:37 +00:00
|
|
|
httpmocks.bloomingfaeries()
|
2017-10-12 21:56:39 +00:00
|
|
|
cmd_ok("--numstrips", "2", "--baseurl", "bla", "--basepath",
|
2017-10-12 22:34:37 +00:00
|
|
|
str(tmpdir), "--output", "rss", "--output", "html", "--adult",
|
|
|
|
"BloomingFaeries")
|
2016-03-07 00:08:57 +00:00
|
|
|
|
2017-10-12 22:34:37 +00:00
|
|
|
@responses.activate
|
2016-03-28 14:29:57 +00:00
|
|
|
def test_fetch_indexed(self, tmpdir):
|
2017-10-12 22:34:37 +00:00
|
|
|
httpmocks.xkcd()
|
2017-10-12 21:56:39 +00:00
|
|
|
cmd_ok("-n", "2", "-v", "-b", str(tmpdir), "xkcd:303")
|