Пример #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_shorten_summary_with_long_summary():
    summary = 'a ' * 30
    expected = '{0} ...'.format(' '.join(['a'] * 25))

    assert Wikipedia._shorten_summary(summary) == expected
Пример #4
0
def test_shorten_summary_with_no_summary():
    assert Wikipedia._shorten_summary('') == ''
Пример #5
0
def test_shorten_summary_with_short():
    summary = 'a short summary'

    assert Wikipedia._shorten_summary(summary) == summary
Пример #6
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('')
Пример #7
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'}
Пример #8
0
def test_wikipedia_search_blows_up(fakewiki):
    fakewiki.search.side_effect = wikipedia.WikipediaException('Whoops..')
    wiki = Wikipedia(fakewiki)

    with pytest.raises(WikipediaError):
        wiki.search('')
Пример #9
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)'}]
Пример #10
0
def test_convert_wiki_error():
    e = wikipedia.WikipediaException("Something bad happened")
    with pytest.raises(WikipediaError) as excinfo:
        Wikipedia._throw_from_wikipedia_error(e)

    assert excinfo.value.msg == 'Something bad happened' and excinfo.value.code == 500