Skip to content

Commit 06688d8

Browse files
committed
tests are fixed
1 parent d765cd5 commit 06688d8

File tree

6 files changed

+15
-18
lines changed

6 files changed

+15
-18
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ repos:
1919
language: system
2020
pass_filenames: false
2121

22-
- id: check-version-conflict
23-
name: Check version conflict
24-
entry: make check-version-conflict
22+
- id: check-version-availability
23+
name: Check version availability
24+
entry: make check-version-availability
2525
language: system
2626
pass_filenames: false

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ max-branches = 18
162162

163163
[tool.pytest.ini_options]
164164
addopts = "-ra"
165+
asyncio_default_fixture_loop_scope = "function"
165166
asyncio_mode = "auto"
166167
timeout = 1200
167168

src/apify/_configuration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,13 +263,13 @@ class Configuration(CrawleeConfiguration):
263263
] = 4321
264264

265265
standby_url: Annotated[
266-
str | None,
266+
str,
267267
BeforeValidator(validate_http_url),
268268
Field(
269269
alias='actor_standby_url',
270270
description='URL for accessing web servers of Actor runs in Standby mode',
271271
),
272-
] = None
272+
] = 'http://localhost'
273273

274274
token: Annotated[
275275
str | None,

src/apify/scrapy/requests.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,7 @@ def to_scrapy_request(apify_request: CrawleeRequest, spider: Spider) -> Request:
165165

166166
# Add optional 'headers' field
167167
if apify_request.headers:
168-
if isinstance(cast(Any, apify_request.headers), dict):
169-
scrapy_request.headers = Headers(apify_request.headers)
170-
else:
171-
Actor.log.warning(
172-
'apify_request[headers] is not an instance of the dict class, '
173-
f'apify_request[headers] = {apify_request.headers}',
174-
)
168+
scrapy_request.headers |= Headers(apify_request.headers)
175169

176170
# Add optional 'userData' field
177171
if apify_request.user_data:

tests/unit/scrapy/requests/test_to_apify_request.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from scrapy import Request, Spider
55
from scrapy.http.headers import Headers
66

7+
from crawlee._types import HttpHeaders
8+
79
from apify.scrapy.requests import to_apify_request
810

911

@@ -36,7 +38,7 @@ def test__to_apify_request__headers(spider: Spider) -> None:
3638
apify_request = to_apify_request(scrapy_request, spider)
3739

3840
assert apify_request is not None
39-
assert apify_request.headers == dict(scrapy_request_headers.to_unicode_dict())
41+
assert apify_request.headers == HttpHeaders(scrapy_request_headers.to_unicode_dict())
4042

4143

4244
def test__to_apify_request__without_id_and_unique_key(spider: Spider) -> None:

tests/unit/scrapy/requests/test_to_scrapy_request.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
import pytest
66
from scrapy import Request, Spider
7-
from scrapy.http.headers import Headers
87

98
from crawlee import Request as CrawleeRequest
9+
from crawlee._types import HttpHeaders
1010

1111
from apify.scrapy.requests import to_scrapy_request
1212

@@ -47,7 +47,7 @@ def test__to_scrapy_request__without_reconstruction_with_optional_fields(spider:
4747
method='GET',
4848
unique_key='https://crawlee.dev',
4949
id='fvwscO2UJLdr10B',
50-
headers={'Authorization': 'Bearer access_token'},
50+
headers=HttpHeaders({'Authorization': 'Bearer access_token'}),
5151
user_data={'some_user_data': 'test'},
5252
)
5353

@@ -58,7 +58,7 @@ def test__to_scrapy_request__without_reconstruction_with_optional_fields(spider:
5858
assert apify_request.method == scrapy_request.method
5959
assert apify_request.id == scrapy_request.meta.get('apify_request_id')
6060
assert apify_request.unique_key == scrapy_request.meta.get('apify_request_unique_key')
61-
assert Headers(apify_request.headers) == scrapy_request.headers
61+
assert apify_request.headers.get('authorization') == scrapy_request.headers.get('authorization').decode()
6262
assert apify_request.user_data == scrapy_request.meta.get('userData')
6363

6464

@@ -91,7 +91,7 @@ def test__to_scrapy_request__with_reconstruction_with_optional_fields(spider: Sp
9191
method='GET',
9292
id='fvwscO2UJLdr10B',
9393
unique_key='https://apify.com',
94-
headers={'Authorization': 'Bearer access_token'},
94+
headers=HttpHeaders({'Authorization': 'Bearer access_token'}),
9595
user_data={
9696
'some_user_data': 'hello',
9797
'scrapy_request': 'gASVJgIAAAAAAAB9lCiMA3VybJSMEWh0dHBzOi8vYXBpZnkuY29tlIwIY2FsbGJhY2uUTowHZXJy\nYmFja5ROjAdoZWFkZXJzlH2UKEMGQWNjZXB0lF2UQz90ZXh0L2h0bWwsYXBwbGljYXRpb24veGh0\nbWwreG1sLGFwcGxpY2F0aW9uL3htbDtxPTAuOSwqLyo7cT0wLjiUYUMPQWNjZXB0LUxhbmd1YWdl\nlF2UQwJlbpRhQwpVc2VyLUFnZW50lF2UQyNTY3JhcHkvMi4xMS4wICgraHR0cHM6Ly9zY3JhcHku\nb3JnKZRhQw9BY2NlcHQtRW5jb2RpbmeUXZRDDWd6aXAsIGRlZmxhdGWUYXWMBm1ldGhvZJSMA0dF\nVJSMBGJvZHmUQwCUjAdjb29raWVzlH2UjARtZXRhlH2UKIwQYXBpZnlfcmVxdWVzdF9pZJSMD2Z2\nd3NjTzJVSkxkcjEwQpSMGGFwaWZ5X3JlcXVlc3RfdW5pcXVlX2tleZSMEWh0dHBzOi8vYXBpZnku\nY29tlIwQZG93bmxvYWRfdGltZW91dJRHQGaAAAAAAACMDWRvd25sb2FkX3Nsb3SUjAlhcGlmeS5j\nb22UjBBkb3dubG9hZF9sYXRlbmN5lEc/tYIIAAAAAHWMCGVuY29kaW5nlIwFdXRmLTiUjAhwcmlv\ncml0eZRLAIwLZG9udF9maWx0ZXKUiYwFZmxhZ3OUXZSMCWNiX2t3YXJnc5R9lHUu\n', # noqa: E501
@@ -105,7 +105,7 @@ def test__to_scrapy_request__with_reconstruction_with_optional_fields(spider: Sp
105105
assert apify_request.method == scrapy_request.method
106106
assert apify_request.id == scrapy_request.meta.get('apify_request_id')
107107
assert apify_request.unique_key == scrapy_request.meta.get('apify_request_unique_key')
108-
assert Headers(apify_request.headers) == scrapy_request.headers
108+
assert apify_request.headers.get('authorization') == scrapy_request.headers.get('authorization').decode()
109109
assert apify_request.user_data == scrapy_request.meta.get('userData')
110110

111111

0 commit comments

Comments
 (0)