Skip to content

Commit e8d0048

Browse files
authored
V2 (#16)
* Update v2.0.0 * fix test
1 parent 20b72df commit e8d0048

3 files changed

Lines changed: 41 additions & 37 deletions

File tree

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Changelog
2+
3+
## [2.0.0](https://github.com/ScrapingBee/scrapingbee-python/compare/v1.2.0...v2.0.0) (2023-10-03)
4+
5+
### Improvement
6+
7+
- Properly url encode all params (Thanks to @tuky with [PR15](https://github.com/ScrapingBee/scrapingbee-python/pull/15)).
8+
9+
### Breaking change
10+
11+
- No need to url encode params anymore.

scrapingbee/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.2.0'
1+
__version__ = "2.0.0"

tests/test_utils.py

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,67 +4,60 @@
44
process_headers,
55
process_cookies,
66
process_params,
7-
get_scrapingbee_url
7+
get_scrapingbee_url,
88
)
99

1010

1111
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="
1715

1816

1917
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"})
2220
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",
2523
}
2624

2725

2826
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"
3535

3636

3737
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")
4240
assert output == '{"title": ".title"}'
4341

4442

4543
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")
5246
assert output == '{"instructions": [{"click": "#buttonId"}]}'
5347

5448

5549
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}
5953

6054

6155
def test_get_scrapingbee_url():
62-
'''It should generate a url'''
56+
"""It should generate a url"""
6357
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"
6863
)
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

Comments
 (0)