Пример #1
0
def test_youtube_search_bad_keyword(yt_search):
    """Test if invalid keyword used."""
    mock_method = yt_search().search().list().execute
    mock_method.side_effect = TypeError
    keyword = 10
    with pytest.raises(TypeError):
        youtube_api.youtube_search(keyword)
Пример #2
0
def test_youtube_search_bad_api_name_version(yt_search):
    """Test if server not found error raised if bad API name or version."""
    mock_method = yt_search().search().list().execute
    mock_method.side_effect = UnknownApiNameOrVersion
    keyword = 'test search'
    with pytest.raises(UnknownApiNameOrVersion):
        youtube_api.youtube_search(keyword)
Пример #3
0
def test_youtube_search_no_internet_connection(yt_search):
    """Test if server not found error raised if not connected to internet."""
    mock_method = yt_search().search().list().execute
    mock_method.side_effect = ServerNotFoundError
    keyword = 'test search'
    with pytest.raises(ServerNotFoundError):
        youtube_api.youtube_search(keyword)
Пример #4
0
def test_youtube_search_get_data(yt_search):
    """Test to see if we are getting result from search."""
    mock_method = yt_search().search().list().execute
    mock_method.return_value = API_DATA.GOOD_YOUTUBE_RESPONSE
    keyword = 'test search'
    result = youtube_api.youtube_search(keyword)
    assert 'items' in result
Пример #5
0
def test_youtube_search_bad_max_results(yt_search):
    """Test that we get an HttpError is raised with bad max results."""
    mock_method = yt_search().search().list().execute
    mock_method.side_effect = HttpError(API_DATA.HTTPERROR_RESP_MAX,
                                        API_DATA.HTTPERROR_CONT_MAX)
    keyword = 'test search'
    err = youtube_api.youtube_search(keyword, max_results=-1)
    assert err.resp == API_DATA.HTTPERROR_RESP_MAX
    assert err.content == API_DATA.HTTPERROR_CONT_MAX
Пример #6
0
def test_youtube_search_bad_token(yt_search):
    """Test that we get an HttpError is raised with bad youtube search."""
    mock_method = yt_search().search().list().execute
    mock_method.side_effect = HttpError(API_DATA.HTTPERROR_RESP,
                                        API_DATA.HTTPERROR_CONT)
    keyword = 'test search'
    err = youtube_api.youtube_search(keyword)
    assert err.resp == API_DATA.HTTPERROR_RESP
    assert err.content == API_DATA.HTTPERROR_CONT