def test_pick_random_category():
    with patch.multiple('site_parser.index_parser',
                        get_categories=DEFAULT,
                        random=DEFAULT) as values:
        random_mock = values['random']
        get_categories_mock = values['get_categories']
        soup = Mock(BeautifulSoup)

        random_mock.choice.return_value = 'c'
        get_categories_mock.return_value = categories = ['a', 'b', 'c', 'd']

        result = pick_random_category(soup)

        get_categories_mock.assert_called_once_with(soup)
        random_mock.choice.assert_called_once_with(categories)

        assert result == 'c'
Example #2
0
def extract_sample_category_from_site():
    soup = get_soup_from_url('http://p30download.com/')
    # soup = build_beautiful_soup_from_path('sample/sample_post.html')
    return pick_random_category(soup)