|
| 1 | +""" |
| 2 | +The MIT License (MIT) |
| 3 | +
|
| 4 | +Copyright (c) 2021-present Pycord Development |
| 5 | +
|
| 6 | +Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | +copy of this software and associated documentation files (the "Software"), |
| 8 | +to deal in the Software without restriction, including without limitation |
| 9 | +the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | +and/or sell copies of the Software, and to permit persons to whom the |
| 11 | +Software is furnished to do so, subject to the following conditions: |
| 12 | +
|
| 13 | +The above copyright notice and this permission notice shall be included in |
| 14 | +all copies or substantial portions of the Software. |
| 15 | +
|
| 16 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 17 | +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 21 | +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 | +DEALINGS IN THE SOFTWARE. |
| 23 | +""" |
| 24 | +from __future__ import annotations |
| 25 | + |
| 26 | +import random |
| 27 | + |
| 28 | +import pytest |
| 29 | + |
| 30 | +from discord.types import components |
| 31 | +from discord.types import embed as embed_type |
| 32 | +from discord.types import message, sticker |
| 33 | + |
| 34 | +from ..helpers import ( |
| 35 | + random_allowed_mentions, |
| 36 | + random_amount, |
| 37 | + random_bool, |
| 38 | + random_bytes, |
| 39 | + random_embed, |
| 40 | + random_snowflake, |
| 41 | + random_snowflake_list, |
| 42 | + random_sticker, |
| 43 | + random_string, |
| 44 | +) |
| 45 | + |
| 46 | +__all__ = ( |
| 47 | + "user_id", |
| 48 | + "channel_id", |
| 49 | + "guild_id", |
| 50 | + "message_id", |
| 51 | + "message_ids", |
| 52 | + "reason", |
| 53 | + "limit", |
| 54 | + "after", |
| 55 | + "before", |
| 56 | + "around", |
| 57 | + "emoji", |
| 58 | + "name", |
| 59 | + "invitable", |
| 60 | + "content", |
| 61 | + "embed", |
| 62 | + "embeds", |
| 63 | + "nonce", |
| 64 | + "allowed_mentions", |
| 65 | + "stickers", |
| 66 | + "components", |
| 67 | + "avatar", |
| 68 | + "applied_tags", |
| 69 | + "icon", |
| 70 | +) |
| 71 | + |
| 72 | + |
| 73 | +@pytest.fixture |
| 74 | +def user_id() -> int: |
| 75 | + """A random user ID fixture.""" |
| 76 | + return random_snowflake() |
| 77 | + |
| 78 | + |
| 79 | +@pytest.fixture |
| 80 | +def channel_id() -> int: |
| 81 | + """A random channel ID fixture.""" |
| 82 | + return random_snowflake() |
| 83 | + |
| 84 | + |
| 85 | +@pytest.fixture |
| 86 | +def guild_id() -> int: |
| 87 | + """A random guild ID fixture.""" |
| 88 | + return random_snowflake() |
| 89 | + |
| 90 | + |
| 91 | +@pytest.fixture |
| 92 | +def message_id() -> int: |
| 93 | + """A random message ID fixture.""" |
| 94 | + return random_snowflake() |
| 95 | + |
| 96 | + |
| 97 | +@pytest.fixture |
| 98 | +def message_ids() -> list[int]: |
| 99 | + """A random amount of message IDs fixture.""" |
| 100 | + return random_amount(random_snowflake) |
| 101 | + |
| 102 | + |
| 103 | +@pytest.fixture(params=[None, "random"]) |
| 104 | +def reason(request) -> str: |
| 105 | + """A random reason fixture.""" |
| 106 | + if request.param == "random": |
| 107 | + return random_string() |
| 108 | + return request.param |
| 109 | + |
| 110 | + |
| 111 | +@pytest.fixture |
| 112 | +def limit() -> int: |
| 113 | + """A random limit fixture.""" |
| 114 | + return random.randrange(0, 1000) |
| 115 | + |
| 116 | + |
| 117 | +@pytest.fixture(params=(None, "random")) |
| 118 | +def after(request) -> int | None: |
| 119 | + """A random after fixture.""" |
| 120 | + if request.param == "random": |
| 121 | + return random_snowflake() |
| 122 | + return None |
| 123 | + |
| 124 | + |
| 125 | +@pytest.fixture(params=(None, "random")) |
| 126 | +def before(request) -> int | None: |
| 127 | + """A random before fixture.""" |
| 128 | + if request.param == "random": |
| 129 | + return random_snowflake() |
| 130 | + return None |
| 131 | + |
| 132 | + |
| 133 | +@pytest.fixture(params=(None, "random")) |
| 134 | +def around(request) -> int | None: |
| 135 | + """A random around fixture.""" |
| 136 | + if request.param == "random": |
| 137 | + return random_snowflake() |
| 138 | + return None |
| 139 | + |
| 140 | + |
| 141 | +@pytest.fixture |
| 142 | +def emoji() -> str: |
| 143 | + """A random emoji fixture.""" |
| 144 | + return "👍" # TODO: Randomize emoji fixture |
| 145 | + |
| 146 | + |
| 147 | +@pytest.fixture |
| 148 | +def name() -> str | None: |
| 149 | + return random_string() |
| 150 | + |
| 151 | + |
| 152 | +@pytest.fixture |
| 153 | +def invitable() -> bool: |
| 154 | + # Only checks one case to shorten tests |
| 155 | + return random_bool() |
| 156 | + |
| 157 | + |
| 158 | +@pytest.fixture(params=(None, "random")) |
| 159 | +def content(request) -> str | None: |
| 160 | + if request.param == "random": |
| 161 | + return random_string() |
| 162 | + return None |
| 163 | + |
| 164 | + |
| 165 | +@pytest.fixture(name="embed", params=(None, random_embed())) |
| 166 | +def embed(request) -> embed_type.Embed | None: |
| 167 | + return request.param |
| 168 | + |
| 169 | + |
| 170 | +@pytest.fixture(params=(None, random_amount(random_embed))) |
| 171 | +def embeds(request) -> list[embed_type.Embed] | None: |
| 172 | + return request.param |
| 173 | + |
| 174 | + |
| 175 | +@pytest.fixture(params=(None, "...")) # TODO: Replace string value |
| 176 | +def nonce(request) -> str | None: |
| 177 | + return request.param |
| 178 | + |
| 179 | + |
| 180 | +@pytest.fixture(params=(None, random_allowed_mentions())) |
| 181 | +def allowed_mentions(request) -> message.AllowedMentions | None: |
| 182 | + return request.param |
| 183 | + |
| 184 | + |
| 185 | +@pytest.fixture(params=(None, [], random_amount(random_sticker))) |
| 186 | +def stickers(request) -> list[sticker.StickerItem] | None: |
| 187 | + return request.param |
| 188 | + |
| 189 | + |
| 190 | +@pytest.fixture(params=(None,)) # TODO: Add components to tests |
| 191 | +def components(request) -> components.Component | None: |
| 192 | + return request.param |
| 193 | + |
| 194 | + |
| 195 | +@pytest.fixture(params=(None, "random")) |
| 196 | +def avatar(request) -> bytes | None: |
| 197 | + if request.param == "random": |
| 198 | + return random_bytes() |
| 199 | + return None |
| 200 | + |
| 201 | + |
| 202 | +@pytest.fixture(params=(None, "random")) |
| 203 | +def icon(request) -> bytes | None: |
| 204 | + """A random icon fixture""" |
| 205 | + if request.param == "random": |
| 206 | + return random_bytes() |
| 207 | + return None |
| 208 | + |
| 209 | + |
| 210 | +@pytest.fixture(params=(None, "random")) |
| 211 | +def applied_tags(request) -> list[int] | None: |
| 212 | + if request.param == "random": |
| 213 | + return random_snowflake_list() |
| 214 | + return None |
0 commit comments