Skip to content

Commit 0b873a4

Browse files
authored
Merge pull request lightspeed-core#724 from tisnik/lcore-740-type-hints-for-quota-limiters-unit-tests
LCORE-740: type hints for quota limiters unit tests
2 parents 7d347b1 + 49f25ce commit 0b873a4

6 files changed

Lines changed: 36 additions & 32 deletions

tests/unit/quota/test_cluster_quota_limiter.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def create_quota_limiter(
3535
return quota_limiter
3636

3737

38-
def test_connected():
38+
def test_connected() -> None:
3939
"""Test the connected method."""
4040
initial_quota = 1000
4141
quota_limit = 100
@@ -44,7 +44,7 @@ def test_connected():
4444
assert quota_limiter.connected()
4545

4646

47-
def test_init_quota():
47+
def test_init_quota() -> None:
4848
"""Test the init quota operation."""
4949
initial_quota = 1000
5050
quota_limit = 100
@@ -59,7 +59,7 @@ def test_init_quota():
5959
)
6060

6161

62-
def test_available_quota():
62+
def test_available_quota() -> None:
6363
"""Test the available quota operation."""
6464
initial_quota = 1000
6565
quota_limit = 100
@@ -73,7 +73,7 @@ def test_available_quota():
7373
assert available_quota == initial_quota
7474

7575

76-
def test_consume_tokens():
76+
def test_consume_tokens() -> None:
7777
"""Test the consume tokens operation."""
7878
initial_quota = 1000
7979
quota_limit = 100
@@ -102,7 +102,7 @@ def test_consume_tokens():
102102
assert available_quota == initial_quota - 4
103103

104104

105-
def test_increase_quota():
105+
def test_increase_quota() -> None:
106106
"""Test the increase_quota operation."""
107107
initial_quota = 1000
108108
quota_limit = 100
@@ -124,7 +124,7 @@ def test_increase_quota():
124124
assert available_quota == initial_quota - 1
125125

126126

127-
def test_ensure_available_quota():
127+
def test_ensure_available_quota() -> None:
128128
"""Test the ensure_available_quota operation."""
129129
initial_quota = 1000
130130
quota_limit = 100
@@ -137,7 +137,7 @@ def test_ensure_available_quota():
137137
quota_limiter.ensure_available_quota("foo")
138138

139139

140-
def test_ensure_available_quota_no_quota():
140+
def test_ensure_available_quota_no_quota() -> None:
141141
"""Test the ensure_available_quota operation."""
142142
initial_quota = 0
143143
quota_limit = 100
@@ -151,7 +151,7 @@ def test_ensure_available_quota_no_quota():
151151
quota_limiter.ensure_available_quota("foo")
152152

153153

154-
def test_revoke_quota():
154+
def test_revoke_quota() -> None:
155155
"""Test the revoke_quota operation."""
156156
initial_quota = 1000
157157
quota_limit = 100

tests/unit/quota/test_connect_pg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from models.config import PostgreSQLDatabaseConfiguration
1010

1111

12-
def test_connect_pg_when_connection_established(mocker: MockerFixture):
12+
def test_connect_pg_when_connection_established(mocker: MockerFixture) -> None:
1313
"""Test the connection to PostgreSQL database."""
1414
# any correct PostgreSQL configuration can be used
1515
configuration = PostgreSQLDatabaseConfiguration(
@@ -24,7 +24,7 @@ def test_connect_pg_when_connection_established(mocker: MockerFixture):
2424
assert connection is not None
2525

2626

27-
def test_connect_pg_when_connection_error(mocker: MockerFixture):
27+
def test_connect_pg_when_connection_error(mocker: MockerFixture) -> None:
2828
"""Test the connection to PostgreSQL database."""
2929
# any correct PostgreSQL configuration can be used
3030
configuration = PostgreSQLDatabaseConfiguration(

tests/unit/quota/test_connect_sqlite.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from models.config import SQLiteDatabaseConfiguration
99

1010

11-
def test_connect_sqlite_when_connection_established():
11+
def test_connect_sqlite_when_connection_established() -> None:
1212
"""Test the connection to SQLite database residing in memory."""
1313
configuration = SQLiteDatabaseConfiguration(db_path=":memory:")
1414

@@ -17,7 +17,7 @@ def test_connect_sqlite_when_connection_established():
1717
assert connection is not None
1818

1919

20-
def test_connect_sqlite_when_connection_error():
20+
def test_connect_sqlite_when_connection_error() -> None:
2121
"""Test the connection to SQLite database."""
2222
configuration = SQLiteDatabaseConfiguration(db_path="/")
2323

tests/unit/quota/test_quota_exceed_error.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from quota.quota_exceed_error import QuotaExceedError
66

77

8-
def test_quota_exceed_error_constructor():
8+
def test_quota_exceed_error_constructor() -> None:
99
"""Test the QuotaExceedError constructor."""
1010
expected = "User 1234 has 100 tokens, but 1000 tokens are needed"
1111
with pytest.raises(QuotaExceedError, match=expected):

tests/unit/quota/test_quota_limiter_factory.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from quota.user_quota_limiter import UserQuotaLimiter
1515

1616

17-
def test_quota_limiters_no_storage():
17+
def test_quota_limiters_no_storage() -> None:
1818
"""Test the quota limiters creating when no storage is configured."""
1919
configuration = QuotaHandlersConfiguration()
2020
configuration.sqlite = None
@@ -24,7 +24,7 @@ def test_quota_limiters_no_storage():
2424
assert not limiters
2525

2626

27-
def test_quota_limiters_no_limiters_pg_storage():
27+
def test_quota_limiters_no_limiters_pg_storage() -> None:
2828
"""Test the quota limiters creating when no limiters are specified."""
2929
configuration = QuotaHandlersConfiguration()
3030
configuration.postgres = PostgreSQLDatabaseConfiguration(
@@ -35,7 +35,7 @@ def test_quota_limiters_no_limiters_pg_storage():
3535
assert not limiters
3636

3737

38-
def test_quota_limiters_no_limiters_sqlite_storage():
38+
def test_quota_limiters_no_limiters_sqlite_storage() -> None:
3939
"""Test the quota limiters creating when no limiters are specified."""
4040
configuration = QuotaHandlersConfiguration()
4141
configuration.sqlite = SQLiteDatabaseConfiguration(
@@ -46,7 +46,7 @@ def test_quota_limiters_no_limiters_sqlite_storage():
4646
assert not limiters
4747

4848

49-
def test_quota_limiters_empty_limiters_pg_storage():
49+
def test_quota_limiters_empty_limiters_pg_storage() -> None:
5050
"""Test the quota limiters creating when no limiters are specified."""
5151
configuration = QuotaHandlersConfiguration()
5252
configuration.postgres = PostgreSQLDatabaseConfiguration(
@@ -57,7 +57,7 @@ def test_quota_limiters_empty_limiters_pg_storage():
5757
assert not limiters
5858

5959

60-
def test_quota_limiters_empty_limiters_sqlite_storage():
60+
def test_quota_limiters_empty_limiters_sqlite_storage() -> None:
6161
"""Test the quota limiters creating when no limiters are specified."""
6262
configuration = QuotaHandlersConfiguration()
6363
configuration.sqlite = SQLiteDatabaseConfiguration(
@@ -68,7 +68,9 @@ def test_quota_limiters_empty_limiters_sqlite_storage():
6868
assert not limiters
6969

7070

71-
def test_quota_limiters_user_quota_limiter_postgres_storage(mocker: MockerFixture):
71+
def test_quota_limiters_user_quota_limiter_postgres_storage(
72+
mocker: MockerFixture,
73+
) -> None:
7274
"""Test the quota limiters creating when one limiter is specified."""
7375
configuration = QuotaHandlersConfiguration()
7476
configuration.postgres = PostgreSQLDatabaseConfiguration(
@@ -90,7 +92,7 @@ def test_quota_limiters_user_quota_limiter_postgres_storage(mocker: MockerFixtur
9092
assert isinstance(limiters[0], UserQuotaLimiter)
9193

9294

93-
def test_quota_limiters_user_quota_limiter_sqlite_storage():
95+
def test_quota_limiters_user_quota_limiter_sqlite_storage() -> None:
9496
"""Test the quota limiters creating when one limiter is specified."""
9597
configuration = QuotaHandlersConfiguration()
9698
configuration.sqlite = SQLiteDatabaseConfiguration(
@@ -110,7 +112,9 @@ def test_quota_limiters_user_quota_limiter_sqlite_storage():
110112
assert isinstance(limiters[0], UserQuotaLimiter)
111113

112114

113-
def test_quota_limiters_cluster_quota_limiter_postgres_storage(mocker: MockerFixture):
115+
def test_quota_limiters_cluster_quota_limiter_postgres_storage(
116+
mocker: MockerFixture,
117+
) -> None:
114118
"""Test the quota limiters creating when one limiter is specified."""
115119
configuration = QuotaHandlersConfiguration()
116120
configuration.postgres = PostgreSQLDatabaseConfiguration(
@@ -132,7 +136,7 @@ def test_quota_limiters_cluster_quota_limiter_postgres_storage(mocker: MockerFix
132136
assert isinstance(limiters[0], ClusterQuotaLimiter)
133137

134138

135-
def test_quota_limiters_cluster_quota_limiter_sqlite_storage():
139+
def test_quota_limiters_cluster_quota_limiter_sqlite_storage() -> None:
136140
"""Test the quota limiters creating when one limiter is specified."""
137141
configuration = QuotaHandlersConfiguration()
138142
configuration.sqlite = SQLiteDatabaseConfiguration(
@@ -152,7 +156,7 @@ def test_quota_limiters_cluster_quota_limiter_sqlite_storage():
152156
assert isinstance(limiters[0], ClusterQuotaLimiter)
153157

154158

155-
def test_quota_limiters_two_limiters(mocker: MockerFixture):
159+
def test_quota_limiters_two_limiters(mocker: MockerFixture) -> None:
156160
"""Test the quota limiters creating when two limiters are specified."""
157161
configuration = QuotaHandlersConfiguration()
158162
configuration.postgres = PostgreSQLDatabaseConfiguration(
@@ -182,7 +186,7 @@ def test_quota_limiters_two_limiters(mocker: MockerFixture):
182186
assert isinstance(limiters[1], ClusterQuotaLimiter)
183187

184188

185-
def test_quota_limiters_invalid_limiter_type(mocker: MockerFixture):
189+
def test_quota_limiters_invalid_limiter_type(mocker: MockerFixture) -> None:
186190
"""Test the quota limiters creating when invalid limiter type is specified."""
187191
configuration = QuotaHandlersConfiguration()
188192
configuration.postgres = PostgreSQLDatabaseConfiguration(

tests/unit/quota/test_user_quota_limiter.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def create_quota_limiter(
3535
return quota_limiter
3636

3737

38-
def test_connected():
38+
def test_connected() -> None:
3939
"""Test the connected method."""
4040
initial_quota = 1000
4141
quota_limit = 100
@@ -44,7 +44,7 @@ def test_connected():
4444
assert quota_limiter.connected()
4545

4646

47-
def test_init_quota():
47+
def test_init_quota() -> None:
4848
"""Test the init quota operation."""
4949
initial_quota = 1000
5050
quota_limit = 100
@@ -57,7 +57,7 @@ def test_init_quota():
5757
assert str(quota_limiter) == "UserQuotaLimiter: initial quota: 1000 increase by: 1"
5858

5959

60-
def test_available_quota():
60+
def test_available_quota() -> None:
6161
"""Test the available quota operation."""
6262
initial_quota = 1000
6363
quota_limit = 100
@@ -71,7 +71,7 @@ def test_available_quota():
7171
assert available_quota == initial_quota
7272

7373

74-
def test_consume_tokens():
74+
def test_consume_tokens() -> None:
7575
"""Test the consume tokens operation."""
7676
initial_quota = 1000
7777
quota_limit = 100
@@ -100,7 +100,7 @@ def test_consume_tokens():
100100
assert available_quota == initial_quota - 4
101101

102102

103-
def test_increase_quota():
103+
def test_increase_quota() -> None:
104104
"""Test the increase_quota operation."""
105105
initial_quota = 1000
106106
quota_limit = 100
@@ -122,7 +122,7 @@ def test_increase_quota():
122122
assert available_quota == initial_quota - 1
123123

124124

125-
def test_ensure_available_quota():
125+
def test_ensure_available_quota() -> None:
126126
"""Test the ensure_available_quota operation."""
127127
initial_quota = 1000
128128
quota_limit = 100
@@ -135,7 +135,7 @@ def test_ensure_available_quota():
135135
quota_limiter.ensure_available_quota("foo")
136136

137137

138-
def test_ensure_available_quota_no_quota():
138+
def test_ensure_available_quota_no_quota() -> None:
139139
"""Test the ensure_available_quota operation."""
140140
initial_quota = 0
141141
quota_limit = 100
@@ -149,7 +149,7 @@ def test_ensure_available_quota_no_quota():
149149
quota_limiter.ensure_available_quota("foo")
150150

151151

152-
def test_revoke_quota():
152+
def test_revoke_quota() -> None:
153153
"""Test the revoke_quota operation."""
154154
initial_quota = 1000
155155
quota_limit = 100

0 commit comments

Comments
 (0)