Skip to content

Commit b4ad24f

Browse files
committed
Reduce some test code repetition.
1 parent ff3e047 commit b4ad24f

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

tests/unit/actor/test_actor_inputs.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,25 +136,26 @@ async def test_actor_create_request_list_from_url() -> None:
136136
async def test_actor_create_request_list_from_url_additional_inputs() -> None:
137137
"""Test that all generated request properties are correctly populated from input values."""
138138
expected_simple_url = 'https://www.someurl.com'
139-
example_actor_input: dict[str, Any] = {ActorInputKeys.startUrls:[
140-
{ActorInputKeys.startUrls.requestsFromUrl: 'https://crawlee.dev/file.txt', 'method': 'POST',
141-
ActorInputKeys.startUrls.headers: {'key': 'value'},
142-
ActorInputKeys.startUrls.payload: 'some_payload',
143-
ActorInputKeys.startUrls.userData: {'another_key': 'another_value'}},
144-
]}
139+
example_start_url_input = {
140+
ActorInputKeys.startUrls.requestsFromUrl: 'https://crawlee.dev/file.txt',
141+
ActorInputKeys.startUrls.method: 'POST',
142+
ActorInputKeys.startUrls.headers: {'key': 'value'},
143+
ActorInputKeys.startUrls.payload: 'some_payload',
144+
ActorInputKeys.startUrls.userData: {'another_key': 'another_value'}}
145+
example_actor_input: dict[str, Any] = {ActorInputKeys.startUrls:[example_start_url_input]}
145146
response_bodies = iter((expected_simple_url,))
146147
http_client = HttpxHttpClient()
147148
with mock.patch.object(http_client, 'send_request', return_value=_create_dummy_response(response_bodies)):
148149
generated_input = await Input.read(example_actor_input, http_client=http_client)
149150
request = await generated_input.start_urls.fetch_next_request()
150151

151152
# Check all properties correctly created for request
153+
example_start_url_input = example_actor_input[ActorInputKeys.startUrls][0]
152154
assert request
153155
assert request.url == expected_simple_url
154-
assert request.method == example_actor_input[ActorInputKeys.startUrls][0][ActorInputKeys.startUrls.method]
155-
assert request.headers.root == example_actor_input[ActorInputKeys.startUrls][0][ActorInputKeys.startUrls.headers]
156-
assert request.payload == example_actor_input[ActorInputKeys.startUrls][0][ActorInputKeys.startUrls.payload].encode(
157-
'utf-8')
156+
assert request.method == example_start_url_input[ActorInputKeys.startUrls.method]
157+
assert request.headers.root == example_start_url_input[ActorInputKeys.startUrls.headers]
158+
assert request.payload == str(example_start_url_input[ActorInputKeys.startUrls.payload]).encode('utf-8')
158159
expected_user_data = UserData()
159160
for key, value in example_actor_input[ActorInputKeys.startUrls][0][ActorInputKeys.startUrls.userData].items():
160161
expected_user_data[key] = value
@@ -174,7 +175,7 @@ async def test_actor_create_request_list_from_url_additional_inputs() -> None:
174175
'http://www.something.com/somethignelse.txt',
175176
'http://non-english-chars-áíéåü.com',
176177
'http://www.port.com:1234',
177-
'http://username:password@something.apify.com'
178+
'http://username:password@something.else.com'
178179
])
179180
def test_url_no_commas_regex_true_positives(true_positive: str) -> None:
180181
example_string= f'Some text {true_positive} some more text'

0 commit comments

Comments
 (0)