This repository has been archived by the owner on Jun 28, 2024. It is now read-only.
forked from Rapptz/discord.py
-
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
6aae098
commit 590afe1
Showing
1 changed file
with
26 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import pytest | ||
from discord import http | ||
|
||
|
||
class CustomResponse: | ||
def __init__(self, text_data, content_type): | ||
self._text = text_data | ||
self.headers = {'content-type': content_type} | ||
|
||
async def text(self, encoding='utf-8'): | ||
return self._text | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_json_or_text(): | ||
# Testing with json data | ||
response = CustomResponse('{"key": "value"}', 'application/json') | ||
result = await http.json_or_text(response) | ||
assert isinstance(result, dict) | ||
assert result == {"key": "value"} | ||
|
||
# Testing with plain text data | ||
response = CustomResponse('Hello world!', 'text/plain') | ||
result = await http.json_or_text(response) | ||
assert isinstance(result, str) | ||
assert result == 'Hello world!' |