Skip to content

Commit 9ce170e

Browse files
committed
add a collection of tests generated by serpapi-library-generator
those tests provide real life usage example of SerpApi backend service
1 parent fab5e4e commit 9ce170e

21 files changed

Lines changed: 388 additions & 0 deletions
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Example: apple_app_store search engine
2+
import pytest
3+
import os
4+
import serpapi
5+
6+
@pytest.mark.skipif((os.getenv("API_KEY") == None), reason="no api_key provided")
7+
def test_search_apple_app_store():
8+
client = serpapi.Client(api_key=os.getenv("API_KEY"))
9+
data = client.search({
10+
'engine': 'apple_app_store',
11+
'term': 'coffee',
12+
})
13+
assert data.get('error') is None
14+
assert data['organic_results']
15+
16+
# os.getenv("API_KEY") is your secret API Key
17+
# copy/paste from [http://serpapi.com/dashboard] to your bash
18+
# ```export API_KEY="your_secure_api_key"```

tests/example_search_baidu_test.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Example: baidu search engine
2+
import pytest
3+
import os
4+
import serpapi
5+
6+
@pytest.mark.skipif((os.getenv("API_KEY") == None), reason="no api_key provided")
7+
def test_search_baidu():
8+
client = serpapi.Client(api_key=os.getenv("API_KEY"))
9+
data = client.search({
10+
'engine': 'baidu',
11+
'q': 'coffee',
12+
})
13+
assert data.get('error') is None
14+
assert data['organic_results']
15+
16+
# os.getenv("API_KEY") is your secret API Key
17+
# copy/paste from [http://serpapi.com/dashboard] to your bash
18+
# ```export API_KEY="your_secure_api_key"```

tests/example_search_bing_test.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Example: bing search engine
2+
import pytest
3+
import os
4+
import serpapi
5+
6+
@pytest.mark.skipif((os.getenv("API_KEY") == None), reason="no api_key provided")
7+
def test_search_bing():
8+
client = serpapi.Client(api_key=os.getenv("API_KEY"))
9+
data = client.search({
10+
'engine': 'bing',
11+
'q': 'coffee',
12+
})
13+
assert data.get('error') is None
14+
assert data['organic_results']
15+
16+
# os.getenv("API_KEY") is your secret API Key
17+
# copy/paste from [http://serpapi.com/dashboard] to your bash
18+
# ```export API_KEY="your_secure_api_key"```
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Example: duckduckgo search engine
2+
import pytest
3+
import os
4+
import serpapi
5+
6+
@pytest.mark.skipif((os.getenv("API_KEY") == None), reason="no api_key provided")
7+
def test_search_duckduckgo():
8+
client = serpapi.Client(api_key=os.getenv("API_KEY"))
9+
data = client.search({
10+
'engine': 'duckduckgo',
11+
'q': 'coffee',
12+
})
13+
assert data.get('error') is None
14+
assert data['organic_results']
15+
16+
# os.getenv("API_KEY") is your secret API Key
17+
# copy/paste from [http://serpapi.com/dashboard] to your bash
18+
# ```export API_KEY="your_secure_api_key"```

tests/example_search_ebay_test.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Example: ebay search engine
2+
import pytest
3+
import os
4+
import serpapi
5+
6+
@pytest.mark.skipif((os.getenv("API_KEY") == None), reason="no api_key provided")
7+
def test_search_ebay():
8+
client = serpapi.Client(api_key=os.getenv("API_KEY"))
9+
data = client.search({
10+
'engine': 'ebay',
11+
'_nkw': 'coffee',
12+
})
13+
assert data.get('error') is None
14+
assert data['organic_results']
15+
16+
# os.getenv("API_KEY") is your secret API Key
17+
# copy/paste from [http://serpapi.com/dashboard] to your bash
18+
# ```export API_KEY="your_secure_api_key"```
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Example: google_autocomplete search engine
2+
import pytest
3+
import os
4+
import serpapi
5+
6+
@pytest.mark.skipif((os.getenv("API_KEY") == None), reason="no api_key provided")
7+
def test_search_google_autocomplete():
8+
client = serpapi.Client(api_key=os.getenv("API_KEY"))
9+
data = client.search({
10+
'engine': 'google_autocomplete',
11+
'q': 'coffee',
12+
})
13+
assert data.get('error') is None
14+
assert data['suggestions']
15+
16+
# os.getenv("API_KEY") is your secret API Key
17+
# copy/paste from [http://serpapi.com/dashboard] to your bash
18+
# ```export API_KEY="your_secure_api_key"```
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Example: google_events search engine
2+
import pytest
3+
import os
4+
import serpapi
5+
6+
@pytest.mark.skipif((os.getenv("API_KEY") == None), reason="no api_key provided")
7+
def test_search_google_events():
8+
client = serpapi.Client(api_key=os.getenv("API_KEY"))
9+
data = client.search({
10+
'engine': 'google_events',
11+
'q': 'coffee',
12+
})
13+
assert data.get('error') is None
14+
assert data['events_results']
15+
16+
# os.getenv("API_KEY") is your secret API Key
17+
# copy/paste from [http://serpapi.com/dashboard] to your bash
18+
# ```export API_KEY="your_secure_api_key"```
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Example: google_images search engine
2+
import pytest
3+
import os
4+
import serpapi
5+
6+
@pytest.mark.skipif((os.getenv("API_KEY") == None), reason="no api_key provided")
7+
def test_search_google_images():
8+
client = serpapi.Client(api_key=os.getenv("API_KEY"))
9+
data = client.search({
10+
'engine': 'google_images',
11+
'engine': 'google_images',
12+
'tbm': 'isch',
13+
'q': 'coffee',
14+
})
15+
assert data.get('error') is None
16+
assert data['images_results']
17+
18+
# os.getenv("API_KEY") is your secret API Key
19+
# copy/paste from [http://serpapi.com/dashboard] to your bash
20+
# ```export API_KEY="your_secure_api_key"```
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Example: google_jobs search engine
2+
import pytest
3+
import os
4+
import serpapi
5+
6+
@pytest.mark.skipif((os.getenv("API_KEY") == None), reason="no api_key provided")
7+
def test_search_google_jobs():
8+
client = serpapi.Client(api_key=os.getenv("API_KEY"))
9+
data = client.search({
10+
'engine': 'google_jobs',
11+
'q': 'coffee',
12+
})
13+
assert data.get('error') is None
14+
assert data['jobs_results']
15+
16+
# os.getenv("API_KEY") is your secret API Key
17+
# copy/paste from [http://serpapi.com/dashboard] to your bash
18+
# ```export API_KEY="your_secure_api_key"```
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Example: google_local_services search engine
2+
import pytest
3+
import os
4+
import serpapi
5+
6+
@pytest.mark.skipif((os.getenv("API_KEY") == None), reason="no api_key provided")
7+
def test_search_google_local_services():
8+
client = serpapi.Client(api_key=os.getenv("API_KEY"))
9+
data = client.search({
10+
'engine': 'google_local_services',
11+
'q': 'electrician',
12+
'data_cid': '6745062158417646970',
13+
})
14+
assert data.get('error') is None
15+
assert data['local_ads']
16+
17+
# os.getenv("API_KEY") is your secret API Key
18+
# copy/paste from [http://serpapi.com/dashboard] to your bash
19+
# ```export API_KEY="your_secure_api_key"```

0 commit comments

Comments
 (0)