from webcomix.comic_spider import ComicSpider


def test_parse_yields_good_page(mocker):
    mock_response = mocker.patch('scrapy.http.Response')
    mock_response.urljoin.return_value = "http://xkcd.com/3/"
    mock_response.url = "http://xkcd.com/2/"
    mock_selector = mocker.patch('scrapy.selector.SelectorList')
    mock_response.xpath.return_value = mock_selector
    mock_selector.extract_first.side_effect = [
        '//imgs.xkcd.com/comics/tree_cropped_(1).jpg', 'xkcd.com/3/'
    ]

    spider = ComicSpider()
    result = spider.parse(mock_response)
    results = list(result)
    assert len(results) == 2
    assert results[0].get(
        'url') == "http://imgs.xkcd.com/comics/tree_cropped_(1).jpg"
    assert results[1].url == "http://xkcd.com/3/"


def test_parse_yields_bad_page(mocker):
    mock_response = mocker.patch('scrapy.http.Response')
    mock_response.urljoin.return_value = "http://xkcd.com/3/"
    mock_response.url = "http://xkcd.com/2/"
    mock_selector = mocker.patch('scrapy.selector.SelectorList')
    mock_response.xpath.return_value = mock_selector
    mock_selector.extract_first.side_effect = [None, 'xkcd.com/3/']

    spider = ComicSpider()
    result = spider.parse(mock_response)
    results = list(result)
    assert len(results) == 1
    assert results[0].url == "http://xkcd.com/3/"

Add tests for the parse method of the spider
Add tests for the parse method of the spider
