Skip to content

Commit 711d4fa

Browse files
committed
add api sorting test
1 parent d98c5e2 commit 711d4fa

File tree

2 files changed

+22
-87
lines changed

2 files changed

+22
-87
lines changed

test_collector.py

Lines changed: 0 additions & 64 deletions
This file was deleted.

test_api.py.deleted renamed to tests/test_api.py

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import asyncio
22
import aiohttp
33
import json
4+
import pytest
45

56

6-
API_URL = "http://localhost:55555"
7+
API_URL = "http://localhost:55555/api/v1/"
78

89

910
async def get_proxies(session, request):
@@ -12,7 +13,7 @@ async def get_proxies(session, request):
1213
return json_data['data']
1314

1415

15-
async def test_ordering(session, field_name):
16+
async def check_ordering(session, field_name):
1617
request_data = {
1718
'method': 'get',
1819
'model': 'proxy',
@@ -31,7 +32,7 @@ async def test_ordering(session, field_name):
3132
return True
3233

3334

34-
async def test_complex_ordering(session, *args):
35+
async def check_complex_ordering(session, *args):
3536
fields = args
3637

3738
request_data = {
@@ -58,31 +59,29 @@ async def test_complex_ordering(session, *args):
5859
return True
5960

6061

61-
async def run_tests(session):
62+
@pytest.mark.asyncio
63+
async def test_ordering():
6264
tests = [
63-
(test_ordering, 'response_time'),
64-
(test_ordering, 'uptime'),
65-
(test_ordering, 'number_of_bad_checks'),
66-
(test_ordering, 'last_check_time'),
67-
(test_complex_ordering, 'uptime', 'last_check_time'),
68-
(test_complex_ordering, 'number_of_bad_checks', 'uptime', 'response_time'),
65+
(check_ordering, 'response_time'),
66+
(check_ordering, 'uptime'),
67+
(check_ordering, 'number_of_bad_checks'),
68+
(check_ordering, 'last_check_time'),
6969
]
7070

7171
for test in tests:
72-
try:
72+
async with aiohttp.ClientSession() as session:
7373
result = await test[0](session, *test[1:])
74-
print("PASSED" if result else "FAILED", end='')
75-
except BaseException as ex:
76-
print("FAILED DUE TO EXCEPTION: {}".format(ex), end='')
77-
finally:
78-
print(" test {} ".format(test))
74+
assert result
7975

8076

81-
async def main():
82-
async with aiohttp.ClientSession() as session:
83-
await run_tests(session)
84-
77+
@pytest.mark.asyncio
78+
async def test_complex_ordering():
79+
tests = [
80+
(check_complex_ordering, 'uptime', 'last_check_time'),
81+
(check_complex_ordering, 'number_of_bad_checks', 'uptime', 'response_time'),
82+
]
8583

86-
if __name__ == '__main__':
87-
loop = asyncio.get_event_loop()
88-
loop.run_until_complete(main())
84+
for test in tests:
85+
async with aiohttp.ClientSession() as session:
86+
result = await test[0](session, *test[1:])
87+
assert result

0 commit comments

Comments
 (0)