Пример #1
0
def test_wikipedia_get_page_happy_path(fakewiki, fakepage):
    fakewiki.page.return_value = fakepage
    wiki = Wikipedia(fakewiki)

    assert wiki.get_page('Python') == {'title': 'Python',
                                       'url': 'https://www.wikipedia.org/wiki/Python',
                                       'summary': 'Python'}
Пример #2
0
def test_wikipedia_get_page_receives_disambiguation(fakewiki):
    fakewiki.page.side_effect = wikipedia.DisambiguationError('...', '...')
    wiki = Wikipedia(fakewiki)

    with pytest.raises(WikipediaError) as excinfo:
        wiki.get_page('Whooops...')

    assert excinfo.value.msg == 'This is a disambiguation page'
    assert excinfo.value.code == 301
Пример #3
0
def test_wikipedia_get_page_blows_up(fakewiki):
    fakewiki.page.side_effect = wikipedia.WikipediaException('...')
    wiki = Wikipedia(fakewiki)

    with pytest.raises(WikipediaError):
        wiki.get_page('')
Пример #4
0
def test_transform_page(fakepage):
    wiki = Wikipedia(None)

    assert wiki._transform_page(fakepage) == {'title': 'Python',
                                              'url': 'https://www.wikipedia.org/wiki/Python',
                                              'summary': 'Python'}
Пример #5
0
def test_wikipedia_search_blows_up(fakewiki):
    fakewiki.search.side_effect = wikipedia.WikipediaException('Whoops..')
    wiki = Wikipedia(fakewiki)

    with pytest.raises(WikipediaError):
        wiki.search('')
Пример #6
0
def test_wikipedia_search_happy_path(fakewiki, fakepage):
    fakewiki.search.return_value = ['Python (Programming Language)']
    wiki = Wikipedia(fakewiki)

    assert wiki.search('python') == [{'title': 'Python (Programming Language)',
                                      'url': 'https://www.wikipedia.org/wiki/Python_(Programming_Language)'}]