|
4 | 4 | process_headers, |
5 | 5 | process_cookies, |
6 | 6 | process_params, |
7 | | - get_scrapingbee_url |
| 7 | + get_scrapingbee_url, |
8 | 8 | ) |
9 | 9 |
|
10 | 10 |
|
11 | 11 | def test_process_js_snippet(): |
12 | | - '''It should encode JavaScript code''' |
13 | | - output = process_js_snippet( |
14 | | - 'window.scrollTo(0, document.body.scrollHeight);') |
15 | | - assert output == \ |
16 | | - 'd2luZG93LnNjcm9sbFRvKDAsIGRvY3VtZW50LmJvZHkuc2Nyb2xsSGVpZ2h0KTs=' |
| 12 | + """It should encode JavaScript code""" |
| 13 | + output = process_js_snippet("window.scrollTo(0, document.body.scrollHeight);") |
| 14 | + assert output == "d2luZG93LnNjcm9sbFRvKDAsIGRvY3VtZW50LmJvZHkuc2Nyb2xsSGVpZ2h0KTs=" |
17 | 15 |
|
18 | 16 |
|
19 | 17 | def test_process_headers(): |
20 | | - '''It should add a Spb- prefix to header names''' |
21 | | - output = process_headers({'Accept-Language': 'En-US'}) |
| 18 | + """It should add a Spb- prefix to header names""" |
| 19 | + output = process_headers({"Accept-Language": "En-US"}) |
22 | 20 | assert output == { |
23 | | - 'User-Agent': 'ScrapingBee-Python/1.2.0', |
24 | | - 'Spb-Accept-Language': 'En-US', |
| 21 | + "User-Agent": "ScrapingBee-Python/2.0.0", |
| 22 | + "Spb-Accept-Language": "En-US", |
25 | 23 | } |
26 | 24 |
|
27 | 25 |
|
28 | 26 | def test_process_cookies(): |
29 | | - '''It should format cookies to a string''' |
30 | | - output = process_cookies({ |
31 | | - 'name_1': 'value_1', |
32 | | - 'name_2': 'value_2', |
33 | | - }) |
34 | | - assert output == 'name_1=value_1;name_2=value_2' |
| 27 | + """It should format cookies to a string""" |
| 28 | + output = process_cookies( |
| 29 | + { |
| 30 | + "name_1": "value_1", |
| 31 | + "name_2": "value_2", |
| 32 | + } |
| 33 | + ) |
| 34 | + assert output == "name_1=value_1;name_2=value_2" |
35 | 35 |
|
36 | 36 |
|
37 | 37 | def test_process_extract_rules(): |
38 | | - '''It should format extract_rules to a stringified JSON''' |
39 | | - output = process_json_stringify_param({ |
40 | | - 'title': '.title' |
41 | | - }, 'extract_rules') |
| 38 | + """It should format extract_rules to a stringified JSON""" |
| 39 | + output = process_json_stringify_param({"title": ".title"}, "extract_rules") |
42 | 40 | assert output == '{"title": ".title"}' |
43 | 41 |
|
44 | 42 |
|
45 | 43 | def test_process_js_scenario(): |
46 | | - '''It should format js_scenario to a stringified JSON''' |
47 | | - output = process_json_stringify_param({ |
48 | | - 'instructions': [ |
49 | | - {"click": "#buttonId"} |
50 | | - ] |
51 | | - }, 'js_scenario') |
| 44 | + """It should format js_scenario to a stringified JSON""" |
| 45 | + output = process_json_stringify_param({"instructions": [{"click": "#buttonId"}]}, "js_scenario") |
52 | 46 | assert output == '{"instructions": [{"click": "#buttonId"}]}' |
53 | 47 |
|
54 | 48 |
|
55 | 49 | def test_process_params(): |
56 | | - '''It should keep boolean parameters''' |
57 | | - output = process_params({'render_js': True}) |
58 | | - assert output == {'render_js': True} |
| 50 | + """It should keep boolean parameters""" |
| 51 | + output = process_params({"render_js": True}) |
| 52 | + assert output == {"render_js": True} |
59 | 53 |
|
60 | 54 |
|
61 | 55 | def test_get_scrapingbee_url(): |
62 | | - '''It should generate a url''' |
| 56 | + """It should generate a url""" |
63 | 57 | output = get_scrapingbee_url( |
64 | | - 'https://app.scrapingbee.com/api/v1/', |
65 | | - 'API_KEY', |
66 | | - 'https://httpbin.org', |
67 | | - {'render_js': True, 'wait_for': '#foo'} |
| 58 | + "https://app.scrapingbee.com/api/v1/", "API_KEY", "https://httpbin.org", {"render_js": True, "wait_for": "#foo"} |
| 59 | + ) |
| 60 | + assert ( |
| 61 | + output == "https://app.scrapingbee.com/api/v1/" |
| 62 | + "?api_key=API_KEY&url=https%3A%2F%2Fhttpbin.org&render_js=True&wait_for=%23foo" |
68 | 63 | ) |
69 | | - assert output == 'https://app.scrapingbee.com/api/v1/' \ |
70 | | - '?api_key=API_KEY&url=https%3A%2F%2Fhttpbin.org&render_js=True&wait_for=%23foo' |
0 commit comments