Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

Commit

Permalink
Added test
Browse files Browse the repository at this point in the history
  • Loading branch information
YasinKaryagdi committed Jun 13, 2024
1 parent 6aae098 commit 590afe1
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/test_http.py
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!'

0 comments on commit 590afe1

Please sign in to comment.