Skip to content

Commit d6c1d73

Browse files
authored
chore: rm classes from tests and improve their names (#294)
1 parent 62de501 commit d6c1d73

29 files changed

+2469
-2514
lines changed

tests/integration/test_actor_api_helpers.py

Lines changed: 294 additions & 315 deletions
Large diffs are not rendered by default.

tests/integration/test_actor_create_proxy_configuration.py

Lines changed: 54 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -8,68 +8,62 @@
88
from .conftest import ActorFactory
99

1010

11-
class TestActorCreateProxyConfiguration:
12-
async def test_create_proxy_configuration_basic(
13-
self: TestActorCreateProxyConfiguration,
14-
make_actor: ActorFactory,
15-
) -> None:
16-
async def main() -> None:
17-
groups = ['SHADER']
18-
country_code = 'US'
19-
20-
async with Actor:
21-
proxy_configuration = await Actor.create_proxy_configuration(
22-
groups=groups,
23-
country_code=country_code,
24-
)
25-
26-
assert proxy_configuration is not None
27-
assert proxy_configuration._groups == groups
28-
assert proxy_configuration._password is not None
29-
assert proxy_configuration._country_code == country_code
30-
31-
actor = await make_actor('proxy-configuration', main_func=main)
32-
33-
run_result = await actor.call()
34-
assert run_result is not None
35-
assert run_result['status'] == 'SUCCEEDED'
36-
37-
async def test_create_proxy_configuration_complex(
38-
self: TestActorCreateProxyConfiguration,
39-
make_actor: ActorFactory,
40-
) -> None:
41-
async def main() -> None:
42-
await Actor.init()
43-
44-
proxy_url_suffix = f'{Actor.config.proxy_password}@{Actor.config.proxy_hostname}:{Actor.config.proxy_port}'
11+
async def test_create_basic_proxy_configuration(make_actor: ActorFactory) -> None:
12+
async def main() -> None:
13+
groups = ['SHADER']
14+
country_code = 'US'
4515

16+
async with Actor:
4617
proxy_configuration = await Actor.create_proxy_configuration(
47-
actor_proxy_input={
48-
'useApifyProxy': True,
49-
}
18+
groups=groups,
19+
country_code=country_code,
5020
)
51-
assert proxy_configuration is not None
52-
assert await proxy_configuration.new_url() == f'http://auto:{proxy_url_suffix}'
5321

54-
groups = ['SHADER', 'BUYPROXIES94952']
55-
country_code = 'US'
56-
proxy_configuration = await Actor.create_proxy_configuration(
57-
actor_proxy_input={
58-
'useApifyProxy': True,
59-
'apifyProxyGroups': groups,
60-
'apifyProxyCountry': country_code,
61-
}
62-
)
6322
assert proxy_configuration is not None
64-
assert (
65-
await proxy_configuration.new_url()
66-
== f'http://groups-{"+".join(groups)},country-{country_code}:{proxy_url_suffix}'
67-
)
68-
69-
await Actor.exit()
70-
71-
actor = await make_actor('proxy-configuration', main_func=main)
72-
73-
run_result = await actor.call()
74-
assert run_result is not None
75-
assert run_result['status'] == 'SUCCEEDED'
23+
assert proxy_configuration._groups == groups
24+
assert proxy_configuration._password is not None
25+
assert proxy_configuration._country_code == country_code
26+
27+
actor = await make_actor('proxy-configuration', main_func=main)
28+
29+
run_result = await actor.call()
30+
assert run_result is not None
31+
assert run_result['status'] == 'SUCCEEDED'
32+
33+
34+
async def test_create_proxy_configuration_with_groups_and_country(make_actor: ActorFactory) -> None:
35+
async def main() -> None:
36+
await Actor.init()
37+
38+
proxy_url_suffix = f'{Actor.config.proxy_password}@{Actor.config.proxy_hostname}:{Actor.config.proxy_port}'
39+
40+
proxy_configuration = await Actor.create_proxy_configuration(
41+
actor_proxy_input={
42+
'useApifyProxy': True,
43+
}
44+
)
45+
assert proxy_configuration is not None
46+
assert await proxy_configuration.new_url() == f'http://auto:{proxy_url_suffix}'
47+
48+
groups = ['SHADER', 'BUYPROXIES94952']
49+
country_code = 'US'
50+
proxy_configuration = await Actor.create_proxy_configuration(
51+
actor_proxy_input={
52+
'useApifyProxy': True,
53+
'apifyProxyGroups': groups,
54+
'apifyProxyCountry': country_code,
55+
}
56+
)
57+
assert proxy_configuration is not None
58+
assert (
59+
await proxy_configuration.new_url()
60+
== f'http://groups-{"+".join(groups)},country-{country_code}:{proxy_url_suffix}'
61+
)
62+
63+
await Actor.exit()
64+
65+
actor = await make_actor('proxy-configuration', main_func=main)
66+
67+
run_result = await actor.call()
68+
assert run_result is not None
69+
assert run_result['status'] == 'SUCCEEDED'

tests/integration/test_actor_dataset.py

Lines changed: 73 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -15,104 +15,101 @@
1515
from .conftest import ActorFactory
1616

1717

18-
class TestActorPushData:
19-
async def test_push_data(self: TestActorPushData, make_actor: ActorFactory) -> None:
20-
desired_item_count = 100 # Also change inside main() if you're changing this
18+
async def test_push_and_verify_data_in_default_dataset(make_actor: ActorFactory) -> None:
19+
desired_item_count = 100 # Also change inside main() if you're changing this
2120

22-
async def main() -> None:
23-
desired_item_count = 100
24-
async with Actor:
25-
await Actor.push_data([{'id': i} for i in range(desired_item_count)])
21+
async def main() -> None:
22+
desired_item_count = 100
23+
async with Actor:
24+
await Actor.push_data([{'id': i} for i in range(desired_item_count)])
25+
26+
actor = await make_actor('push-data', main_func=main)
27+
28+
run_result = await actor.call()
29+
30+
assert run_result is not None
31+
assert run_result['status'] == 'SUCCEEDED'
32+
list_page = await actor.last_run().dataset().list_items()
33+
assert list_page.items[0]['id'] == 0
34+
assert list_page.items[-1]['id'] == desired_item_count - 1
35+
assert len(list_page.items) == list_page.count == desired_item_count
2636

27-
actor = await make_actor('push-data', main_func=main)
2837

29-
run_result = await actor.call()
38+
async def test_push_large_data_chunks_over_9mb(make_actor: ActorFactory) -> None:
39+
async def main() -> None:
40+
async with Actor:
41+
await Actor.push_data([{'str': 'x' * 10000} for _ in range(5000)]) # ~50MB
3042

31-
assert run_result is not None
32-
assert run_result['status'] == 'SUCCEEDED'
33-
list_page = await actor.last_run().dataset().list_items()
34-
assert list_page.items[0]['id'] == 0
35-
assert list_page.items[-1]['id'] == desired_item_count - 1
36-
assert len(list_page.items) == list_page.count == desired_item_count
43+
actor = await make_actor('push-data-over-9mb', main_func=main)
3744

38-
async def test_push_data_over_9mb(self: TestActorPushData, make_actor: ActorFactory) -> None:
39-
async def main() -> None:
40-
async with Actor:
41-
await Actor.push_data([{'str': 'x' * 10000} for _ in range(5000)]) # ~50MB
45+
run_result = await actor.call()
4246

43-
actor = await make_actor('push-data-over-9mb', main_func=main)
47+
assert run_result is not None
48+
assert run_result['status'] == 'SUCCEEDED'
49+
async for item in actor.last_run().dataset().iterate_items():
50+
assert item['str'] == 'x' * 10000
4451

45-
run_result = await actor.call()
4652

47-
assert run_result is not None
48-
assert run_result['status'] == 'SUCCEEDED'
49-
async for item in actor.last_run().dataset().iterate_items():
50-
assert item['str'] == 'x' * 10000
53+
async def test_same_references_in_default_dataset(make_actor: ActorFactory) -> None:
54+
async def main() -> None:
55+
async with Actor:
56+
dataset1 = await Actor.open_dataset()
57+
dataset2 = await Actor.open_dataset()
58+
assert dataset1 is dataset2
5159

60+
actor = await make_actor('dataset-same-ref-default', main_func=main)
5261

53-
class TestActorOpenDataset:
54-
async def test_same_references_default(self: TestActorOpenDataset, make_actor: ActorFactory) -> None:
55-
async def main() -> None:
56-
async with Actor:
57-
dataset1 = await Actor.open_dataset()
58-
dataset2 = await Actor.open_dataset()
59-
assert dataset1 is dataset2
62+
run_result = await actor.call()
63+
assert run_result is not None
64+
assert run_result['status'] == 'SUCCEEDED'
6065

61-
actor = await make_actor('dataset-same-ref-default', main_func=main)
6266

63-
run_result = await actor.call()
64-
assert run_result is not None
65-
assert run_result['status'] == 'SUCCEEDED'
67+
async def test_same_references_in_named_dataset(make_actor: ActorFactory) -> None:
68+
dataset_name = generate_unique_resource_name('dataset')
6669

67-
async def test_same_references_named(self: TestActorOpenDataset, make_actor: ActorFactory) -> None:
68-
dataset_name = generate_unique_resource_name('dataset')
70+
async def main() -> None:
71+
async with Actor:
72+
input_object = await Actor.get_input()
73+
dataset_name = input_object['datasetName']
74+
dataset_by_name_1 = await Actor.open_dataset(name=dataset_name)
75+
dataset_by_name_2 = await Actor.open_dataset(name=dataset_name)
76+
assert dataset_by_name_1 is dataset_by_name_2
6977

70-
async def main() -> None:
71-
async with Actor:
72-
input_object = await Actor.get_input()
73-
dataset_name = input_object['datasetName']
74-
dataset_by_name_1 = await Actor.open_dataset(name=dataset_name)
75-
dataset_by_name_2 = await Actor.open_dataset(name=dataset_name)
76-
assert dataset_by_name_1 is dataset_by_name_2
78+
dataset_by_id_1 = await Actor.open_dataset(id=dataset_by_name_1._id)
79+
dataset_by_id_2 = await Actor.open_dataset(id=dataset_by_name_1._id)
80+
assert dataset_by_id_1 is dataset_by_name_1
81+
assert dataset_by_id_2 is dataset_by_id_1
7782

78-
dataset_by_id_1 = await Actor.open_dataset(id=dataset_by_name_1._id)
79-
dataset_by_id_2 = await Actor.open_dataset(id=dataset_by_name_1._id)
80-
assert dataset_by_id_1 is dataset_by_name_1
81-
assert dataset_by_id_2 is dataset_by_id_1
83+
await dataset_by_name_1.drop()
8284

83-
await dataset_by_name_1.drop()
85+
actor = await make_actor('dataset-same-ref-named', main_func=main)
8486

85-
actor = await make_actor('dataset-same-ref-named', main_func=main)
87+
run_result = await actor.call(run_input={'datasetName': dataset_name})
88+
assert run_result is not None
89+
assert run_result['status'] == 'SUCCEEDED'
8690

87-
run_result = await actor.call(run_input={'datasetName': dataset_name})
88-
assert run_result is not None
89-
assert run_result['status'] == 'SUCCEEDED'
9091

91-
async def test_force_cloud(
92-
self: TestActorOpenDataset,
93-
apify_client_async: ApifyClientAsync,
94-
monkeypatch: pytest.MonkeyPatch,
95-
) -> None:
96-
assert apify_client_async.token is not None
97-
monkeypatch.setenv(ApifyEnvVars.TOKEN, apify_client_async.token)
92+
async def test_force_cloud(apify_client_async: ApifyClientAsync, monkeypatch: pytest.MonkeyPatch) -> None:
93+
assert apify_client_async.token is not None
94+
monkeypatch.setenv(ApifyEnvVars.TOKEN, apify_client_async.token)
9895

99-
dataset_name = generate_unique_resource_name('dataset')
100-
dataset_item = {'foo': 'bar'}
96+
dataset_name = generate_unique_resource_name('dataset')
97+
dataset_item = {'foo': 'bar'}
10198

102-
async with Actor:
103-
dataset = await Actor.open_dataset(name=dataset_name, force_cloud=True)
104-
dataset_id = dataset._id
99+
async with Actor:
100+
dataset = await Actor.open_dataset(name=dataset_name, force_cloud=True)
101+
dataset_id = dataset._id
105102

106-
await dataset.push_data(dataset_item)
103+
await dataset.push_data(dataset_item)
107104

108-
dataset_client = apify_client_async.dataset(dataset_id)
105+
dataset_client = apify_client_async.dataset(dataset_id)
109106

110-
try:
111-
dataset_details = await dataset_client.get()
112-
assert dataset_details is not None
113-
assert dataset_details.get('name') == dataset_name
107+
try:
108+
dataset_details = await dataset_client.get()
109+
assert dataset_details is not None
110+
assert dataset_details.get('name') == dataset_name
114111

115-
dataset_items = await dataset_client.list_items()
116-
assert dataset_items.items == [dataset_item]
117-
finally:
118-
await dataset_client.delete()
112+
dataset_items = await dataset_client.list_items()
113+
assert dataset_items.items == [dataset_item]
114+
finally:
115+
await dataset_client.delete()

0 commit comments

Comments
 (0)