Ejemplo n.º 1
0
def test_serp_goog_return_correct_result():
    result = serp_goog(q='testing hotels', cx=goog_cse_cx,
                       key=goog_cse_key, searchType=['image', None])
    assert isinstance(result, pd.core.frame.DataFrame)
    assert 'title' in result
    assert 'image' in result
    assert len(result) == 20
Ejemplo n.º 2
0
def test_serp_goog_return_correct_result():
    result = serp_goog(q='testing hotels', cx=goog_cse_cx,
                       key=goog_cse_key, searchType=['image', None])
    assert isinstance(result, pd.core.frame.DataFrame)
    assert 'title' in result
    assert 'image' in result
    assert len(result) == 20
Ejemplo n.º 3
0
def test_serp_goog_handles_no_search_results():
    q = 'aquerythatdoesntgetrezultssss'
    result = serp_goog(q=q,
                       cx=goog_cse_cx,
                       key=goog_cse_key,
                       cr='countryRU',
                       hl='zh-TW',
                       gl='nf')
    assert len(result) == 1
    assert result['searchTerms'].values[0] == q
Ejemplo n.º 4
0
def test_serp_goog_restult_df_contains_all_provided_params():
    keys_vals_to_test = {k: list(SERP_GOOG_VALID_VALS[k])[0] for k in SERP_GOOG_VALID_VALS}
    for key, val in keys_vals_to_test.items():
        result = serp_goog(cx=goog_cse_cx, key=goog_cse_key, q='fashion', **{key: val})
        if key == 'searchType':
            continue
        assert key in result.columns
        if key == 'filter':
            val = str(val)
        assert result[key].iloc[0] == val
Ejemplo n.º 5
0
def test_serp_goog_raises_error_on_invalid_args():
    with pytest.raises(ValueError):
        for val in SERP_GOOG_VALID_VALS:
            params = {val: 'WRONG VALUE'}
            serp_goog(q='q', cx='cx', key='key', **params)
Ejemplo n.º 6
0
def test_serp_raises_error_on_wrong_key():
    with pytest.raises(Exception):
        serp_goog(q='test credit cart', cx=goog_cse_cx, key='wrong key')
Ejemplo n.º 7
0
def test_serp_raises_error_on_wrong_key():
    with pytest.raises(Exception):
        serp_goog(q='test credit cart', cx=goog_cse_cx, key='wrong key')
Ejemplo n.º 8
0
def test_serp_goog_handles_no_search_results():
    q = 'aquerythatdoesntgetrezultssss'
    result = serp_goog(q=q, cx=goog_cse_cx, key=goog_cse_key,
                       cr='countryRU', hl='zh-TW', gl='nf')
    assert len(result) == 1
    assert result['searchTerms'].values[0] == q
Ejemplo n.º 9
0
def test_serp_goog_raises_error_on_invalid_args():
    with pytest.raises(ValueError):
        for val in SERP_GOOG_VALID_VALS:
            params = {val: 'WRONG VALUE'}
            serp_goog(q='q', cx='cx', key='key', **params)