-
Notifications
You must be signed in to change notification settings - Fork 105
/
Copy pathtest_ebay_search.py
53 lines (40 loc) · 1.37 KB
/
test_ebay_search.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import random
import unittest
import os
import pprint
from serpapi import EbaySearch
class TestEbaySearchApi(unittest.TestCase):
def setUp(self):
EbaySearch.SERP_API_KEY = os.getenv("API_KEY", "demo")
@unittest.skipIf((os.getenv("API_KEY") == None), "no api_key provided")
def test_get_json(self):
search = EbaySearch({"_nkw": "Coffee"})
data = search.get_json()
self.assertIsNone(data.get("error"))
self.assertEqual(data["search_metadata"]["status"], "Success")
self.assertIsNotNone(data["search_metadata"]["ebay_url"])
self.assertIsNotNone(data["search_metadata"]["id"])
self.assertIsNotNone(data["organic_results"][0]["title"])
for organic_result in data.get("organic_results", []):
self.assertIsNotNone(organic_result.get("title"))
# pp = pprint.PrettyPrinter(indent=2)
# pp.pprint(data)
@unittest.skipIf((os.getenv("API_KEY") == None), "no api_key provided")
def test_paginate(self):
page_size = 60
params = {
"_nkw": "coffee",
"_ipg": page_size,
}
search = EbaySearch(params)
limit = 3
pages = search.pagination(limit = limit)
page_count = 0
result_count = 0
for page in pages:
page_count += 1
result_count += len(page["organic_results"])
self.assertEqual(page_count, limit)
self.assertEqual(result_count, page_size * limit)
if __name__ == '__main__':
unittest.main()