Skip to content

V2 #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 3, 2023
Merged

V2 #16

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Changelog

## [2.0.0](https://github.com/ScrapingBee/scrapingbee-python/compare/v1.2.0...v2.0.0) (2023-10-03)

### Improvement

- Properly url encode all params (Thanks to @tuky with [PR15](https://github.com/ScrapingBee/scrapingbee-python/pull/15)).

### Breaking change

- No need to url encode params anymore.
2 changes: 1 addition & 1 deletion scrapingbee/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.2.0'
__version__ = "2.0.0"
65 changes: 29 additions & 36 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,67 +4,60 @@
process_headers,
process_cookies,
process_params,
get_scrapingbee_url
get_scrapingbee_url,
)


def test_process_js_snippet():
'''It should encode JavaScript code'''
output = process_js_snippet(
'window.scrollTo(0, document.body.scrollHeight);')
assert output == \
'd2luZG93LnNjcm9sbFRvKDAsIGRvY3VtZW50LmJvZHkuc2Nyb2xsSGVpZ2h0KTs='
"""It should encode JavaScript code"""
output = process_js_snippet("window.scrollTo(0, document.body.scrollHeight);")
assert output == "d2luZG93LnNjcm9sbFRvKDAsIGRvY3VtZW50LmJvZHkuc2Nyb2xsSGVpZ2h0KTs="


def test_process_headers():
'''It should add a Spb- prefix to header names'''
output = process_headers({'Accept-Language': 'En-US'})
"""It should add a Spb- prefix to header names"""
output = process_headers({"Accept-Language": "En-US"})
assert output == {
'User-Agent': 'ScrapingBee-Python/1.2.0',
'Spb-Accept-Language': 'En-US',
"User-Agent": "ScrapingBee-Python/2.0.0",
"Spb-Accept-Language": "En-US",
}


def test_process_cookies():
'''It should format cookies to a string'''
output = process_cookies({
'name_1': 'value_1',
'name_2': 'value_2',
})
assert output == 'name_1=value_1;name_2=value_2'
"""It should format cookies to a string"""
output = process_cookies(
{
"name_1": "value_1",
"name_2": "value_2",
}
)
assert output == "name_1=value_1;name_2=value_2"


def test_process_extract_rules():
'''It should format extract_rules to a stringified JSON'''
output = process_json_stringify_param({
'title': '.title'
}, 'extract_rules')
"""It should format extract_rules to a stringified JSON"""
output = process_json_stringify_param({"title": ".title"}, "extract_rules")
assert output == '{"title": ".title"}'


def test_process_js_scenario():
'''It should format js_scenario to a stringified JSON'''
output = process_json_stringify_param({
'instructions': [
{"click": "#buttonId"}
]
}, 'js_scenario')
"""It should format js_scenario to a stringified JSON"""
output = process_json_stringify_param({"instructions": [{"click": "#buttonId"}]}, "js_scenario")
assert output == '{"instructions": [{"click": "#buttonId"}]}'


def test_process_params():
'''It should keep boolean parameters'''
output = process_params({'render_js': True})
assert output == {'render_js': True}
"""It should keep boolean parameters"""
output = process_params({"render_js": True})
assert output == {"render_js": True}


def test_get_scrapingbee_url():
'''It should generate a url'''
"""It should generate a url"""
output = get_scrapingbee_url(
'https://app.scrapingbee.com/api/v1/',
'API_KEY',
'https://httpbin.org',
{'render_js': True, 'wait_for': '#foo'}
"https://app.scrapingbee.com/api/v1/", "API_KEY", "https://httpbin.org", {"render_js": True, "wait_for": "#foo"}
)
assert (
output == "https://app.scrapingbee.com/api/v1/"
"?api_key=API_KEY&url=https%3A%2F%2Fhttpbin.org&render_js=True&wait_for=%23foo"
)
assert output == 'https://app.scrapingbee.com/api/v1/' \
'?api_key=API_KEY&url=https%3A%2F%2Fhttpbin.org&render_js=True&wait_for=%23foo'