Debian Codegraph @

tests/test_maximum_connections.py

raw symbols SCIP
1 import functools
2
3 import pytest
4
5 import aioftp
6
7
8 @pytest.mark.asyncio
9 async def test_multiply_connections_no_limits(pair_factory):
10 Client = functools.partial(
11 aioftp.Client,
12 path_io_factory=aioftp.MemoryPathIO,
13 )
14 async with pair_factory() as pair:
15 s = pair.server
16 clients = [Client() for _ in range(4)]
17 for c in clients:
18 await c.connect(s.server_host, s.server_port)
19 await c.login()
20 for c in clients:
21 await c.quit()
22
23
24 @pytest.mark.asyncio
25 async def test_multiply_connections_limited_error(
26 pair_factory,
27 Server,
28 expect_codes_in_exception,
29 ):
30 Client = functools.partial(
31 aioftp.Client,
32 path_io_factory=aioftp.MemoryPathIO,
33 )
34 s = Server(maximum_connections=4)
35 async with pair_factory(None, s) as pair:
36 s = pair.server
37 clients = [Client() for _ in range(4)]
38 for c in clients[:-1]:
39 await c.connect(s.server_host, s.server_port)
40 await c.login()
41 with expect_codes_in_exception("421"):
42 await clients[-1].connect(s.server_host, s.server_port)
43 for c in clients[:-1]:
44 await c.quit()
45
46
47 @pytest.mark.asyncio
48 async def test_multiply_user_commands(pair_factory, Server):
49 s = Server(maximum_connections=1)
50 async with pair_factory(None, s) as pair:
51 for _ in range(10):
52 await pair.client.login()
53
54
55 @pytest.mark.asyncio
56 async def test_multiply_connections_with_user_limited_error(
57 pair_factory,
58 Server,
59 expect_codes_in_exception,
60 ):
61 Client = functools.partial(
62 aioftp.Client,
63 path_io_factory=aioftp.MemoryPathIO,
64 )
65 s = Server([aioftp.User("foo", maximum_connections=4)])
66 async with pair_factory(None, s, connected=False) as pair:
67 s = pair.server
68 clients = [Client() for _ in range(5)]
69 for c in clients[:-1]:
70 await c.connect(s.server_host, s.server_port)
71 await c.login("foo")
72 await clients[-1].connect(s.server_host, s.server_port)
73 with expect_codes_in_exception("530"):
74 await clients[-1].login("foo")
75 for c in clients[:-1]:
76 await c.quit()
77
78
79 @pytest.mark.asyncio
80 async def test_multiply_connections_relogin_balanced(
81 pair_factory,
82 Server,
83 expect_codes_in_exception,
84 ):
85 Client = functools.partial(
86 aioftp.Client,
87 path_io_factory=aioftp.MemoryPathIO,
88 )
89 s = Server(maximum_connections=4)
90 async with pair_factory(None, s, connected=False) as pair:
91 s = pair.server
92 clients = [Client() for _ in range(5)]
93 for c in clients[:-1]:
94 await c.connect(s.server_host, s.server_port)
95 await c.login()
96 await clients[0].quit()
97 await clients[-1].connect(s.server_host, s.server_port)
98 await clients[-1].login()
99 for c in clients[1:]:
100 await c.quit()