-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dfb66b3
commit 2271561
Showing
3 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,54 @@ | ||
from typing import Any, Mapping | ||
|
||
import pytest | ||
|
||
import aiointeractions | ||
import discord | ||
|
||
|
||
class MockRequest: | ||
def __init__( | ||
self, | ||
headers: Mapping[str, Any], | ||
data: Any | ||
): | ||
self.headers = headers | ||
self._data = data | ||
|
||
async def text(self) -> str: | ||
return str(self._data) | ||
|
||
|
||
class MockApp(aiointeractions.InteractionsApp): | ||
verification: str = '{}{"type": 1}' | ||
|
||
def _verify_request(self, headers: Mapping[str, Any], body: str) -> bool: | ||
return f'{headers}{body}' == self.verification | ||
|
||
|
||
intents = discord.Intents.none() | ||
client = discord.Client(intents=intents) | ||
tree = discord.app_commands.CommandTree(client) | ||
|
||
app = MockApp(client) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_no_verification() -> None: | ||
request = MockRequest({}, '') | ||
response = await app.interactions_handler(request) # type: ignore | ||
assert response.status == 401 | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_invalid_verification() -> None: | ||
request = MockRequest({}, 'badtext') | ||
response = await app.interactions_handler(request) # type: ignore | ||
assert response.status == 401 | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_valid_verification() -> None: | ||
request = MockRequest({}, '{"type": 1}') | ||
response = await app.interactions_handler(request) # type: ignore | ||
assert response.status == 200 |