Skip to content

Commit fc6a2cf

Browse files
committed
✅ Add modal tests
Signed-off-by: Paillat-dev <[email protected]>
1 parent bd16ea8 commit fc6a2cf

File tree

1 file changed

+31
-22
lines changed

1 file changed

+31
-22
lines changed

tests/test_components.py

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,20 @@
2222
DEALINGS IN THE SOFTWARE.
2323
"""
2424

25-
from typing import Any
26-
import pytest
2725
import random
2826
import string
27+
from typing import Any
28+
29+
import pytest
2930

30-
from discord import components
3131
import discord
32+
from discord import components
3233

3334
random.seed(42)
3435

36+
3537
def random_string(
36-
min_len, max_len, spaces: bool = True, punctuation: bool = True, separators: tuple[str, ...] = ("-", "_")
38+
min_len, max_len, spaces: bool = True, punctuation: bool = True, separators: tuple[str, ...] = ("-", "_")
3739
):
3840
chars = string.ascii_letters + string.digits
3941
if spaces:
@@ -94,7 +96,8 @@ def generate_test_user_select_modal(
9496

9597
return MODAL, EXPECTED_PAYLOAD
9698

97-
USER_SELECT_MODAL_CASES = [
99+
100+
USER_SELECT_MODAL_CASES = [
98101
generate_test_user_select_modal(
99102
modal_title=random_string(1, 45),
100103
modal_custom_id=random_string(1, 100),
@@ -105,30 +108,33 @@ def generate_test_user_select_modal(
105108
)
106109
for _ in range(10)
107110
]
111+
112+
108113
@pytest.mark.parametrize(
109114
("modal", "payload"),
110115
USER_SELECT_MODAL_CASES,
111116
)
112117
def test_user_select_modal_to_dict(
113118
modal: components.Modal,
114-
payload: dict[Any, Any],
119+
payload: dict[Any, Any],
115120
):
116121
# Test that the modal generates the expected payload
117122
assert modal.to_dict() == payload
118123

124+
119125
def generate_test_text_input_modal(
120-
*,
121-
modal_title: str,
122-
modal_custom_id: str,
123-
label_title: str,
124-
label_description: str,
125-
text_input_custom_id: str,
126-
text_input_value: str,
127-
text_input_placeholder: str,
128-
text_input_min_length: int,
129-
text_input_max_length: int,
130-
text_input_required: bool,
131-
text_input_multiline: bool,
126+
*,
127+
modal_title: str,
128+
modal_custom_id: str,
129+
label_title: str,
130+
label_description: str,
131+
text_input_custom_id: str,
132+
text_input_value: str,
133+
text_input_placeholder: str,
134+
text_input_min_length: int,
135+
text_input_max_length: int,
136+
text_input_required: bool,
137+
text_input_multiline: bool,
132138
):
133139
MODAL: components.Modal = components.Modal(
134140
components.Label(
@@ -174,7 +180,8 @@ def generate_test_text_input_modal(
174180

175181
return MODAL, EXPECTED_PAYLOAD
176182

177-
TEXT_INPUT_MODAL_CASES = [
183+
184+
TEXT_INPUT_MODAL_CASES = [
178185
generate_test_text_input_modal(
179186
modal_title=random_string(1, 45),
180187
modal_custom_id=random_string(1, 100),
@@ -189,14 +196,16 @@ def generate_test_text_input_modal(
189196
text_input_multiline=random.choice([True, False]),
190197
)
191198
for _ in range(10)
192-
]
199+
]
200+
201+
193202
@pytest.mark.parametrize(
194203
("modal", "payload"),
195204
TEXT_INPUT_MODAL_CASES,
196205
)
197206
def test_text_input_modal_to_dict(
198207
modal: components.Modal,
199-
payload: dict[Any, Any],
208+
payload: dict[Any, Any],
200209
):
201210
# Test that the modal generates the expected payload
202-
assert modal.to_dict() == payload
211+
assert modal.to_dict() == payload

0 commit comments

Comments
 (0)