/
liquid-g
/
liquid-code
Обзор
Документация
Войти
/
liquid-g
/
liquid-code
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
develop-0.4
tests/unit/test_test_client.py
160 строк
5 KB
User
0.4.9 - переработка документации, рефакторинг кода, покрытие тестами 70%
06 июл 2026, 13:37
06 июл 2026, 13:37
79b2ebc
Код
Авторство
О чём код?
"""Unit-тесты для TestClient и TestResponse.""" import pytest from liquidcode import Application from liquidcode.test import TestClient, TestResponse from liquidcode.http import HttpResponse class TestTestResponse: """Тесты для TestResponse.""" def test_status_property(self): """Тест свойства status.""" response = HttpResponse(content={"test": True}, status=201) test_response = TestResponse(response) assert test_response.status == 201 def test_headers_property(self): """Тест свойства headers.""" response = HttpResponse( content={"test": True}, headers={"X-Custom": "value"} ) test_response = TestResponse(response) assert test_response.headers == {"X-Custom": "value"} def test_content_property(self): """Тест свойства content.""" response = HttpResponse(content={"test": True}) test_response = TestResponse(response) assert test_response.content == {"test": True} def test_json_with_dict(self): """Тест json() с dict.""" response = HttpResponse(content={"test": True}) test_response = TestResponse(response) assert test_response.json() == {"test": True} def test_json_with_str(self): """Тест json() с строкой.""" response = HttpResponse(content='{"test": true}') test_response = TestResponse(response) assert test_response.json() == {"test": True} def test_json_with_bytes(self): """Тест json() с байтами.""" response = HttpResponse(content=b'{"test": true}') test_response = TestResponse(response) assert test_response.json() == {"test": True} def test_text_with_bytes(self): """Тест text() с байтами.""" response = HttpResponse(content=b'Hello, World!') test_response = TestResponse(response) assert test_response.text() == "Hello, World!" def test_text_with_dict(self): """Тест text() с dict.""" response = HttpResponse(content={"test": True}) test_response = TestResponse(response) assert test_response.text() == "{'test': True}" class TestTestClient: """Тесты для TestClient.""" def test_get_request(self): """GET-запрос.""" app = Application() app.router.add_route("/test", lambda: {"test": True}, ["GET"]) client = TestClient(app) response = client.get("/test") assert response.status == 200 assert response.json() == {"test": True} def test_post_request(self): """POST-запрос.""" app = Application() app.router.add_route("/test", lambda data: {"received": data}, ["POST"]) client = TestClient(app) response = client.post("/test", body={"data": "value"}) assert response.status == 200 assert response.json() == {"received": {"data": "value"}} def test_request_with_headers(self): """Запрос с заголовками.""" app = Application() app.router.add_route("/test", lambda: {"test": True}, ["GET"]) client = TestClient(app) response = client.get("/test", headers={"X-Custom": "value"}) assert response.status == 200 def test_request_with_query_params(self): """Запрос с query-параметрами.""" app = Application() app.router.add_route("/test", lambda: {"test": True}, ["GET"]) client = TestClient(app) response = client.get("/test", query_params={"param": "value"}) assert response.status == 200 def test_put_request(self): """PUT-запрос.""" app = Application() app.router.add_route("/test", lambda data: {"updated": data}, ["PUT"]) client = TestClient(app) response = client.put("/test", body={"data": "value"}) assert response.status == 200 assert response.json() == {"updated": {"data": "value"}} def test_patch_request(self): """PATCH-запрос.""" app = Application() app.router.add_route("/test", lambda data: {"patched": data}, ["PATCH"]) client = TestClient(app) response = client.patch("/test", body={"data": "value"}) assert response.status == 200 assert response.json() == {"patched": {"data": "value"}} def test_delete_request(self): """DELETE-запрос.""" app = Application() app.router.add_route("/test", lambda: {"deleted": True}, ["DELETE"]) client = TestClient(app) response = client.delete("/test") assert response.status == 200 assert response.json() == {"deleted": True} def test_websocket_request(self): """WebSocket-запрос (имитация).""" app = Application() app.router.add_route("/ws", lambda: {"ws": True}, ["WEBSOCKET"]) client = TestClient(app) response = client.websocket("/ws") assert response.status == 200 assert response.json() == {"ws": True}