Добавлены классы ответов
This commit is contained in:
41
net/xeaf/rack/tests/models/responses/data_response_tests.py
Normal file
41
net/xeaf/rack/tests/models/responses/data_response_tests.py
Normal file
@@ -0,0 +1,41 @@
|
||||
# DRF Rack
|
||||
# Библиотека классов расширений для Django REST Framework
|
||||
#
|
||||
# Автор: Николай В. Анохин <n.anokhin@xeaf.net>
|
||||
# Все права защищены. Лицензия: MIT
|
||||
|
||||
"""
|
||||
Описание класса DataResponseTests
|
||||
"""
|
||||
|
||||
from django.test import SimpleTestCase
|
||||
from rest_framework import status
|
||||
|
||||
from net.xeaf.rack.models.responses import DataResponse
|
||||
|
||||
|
||||
class DataResponseTests(SimpleTestCase):
|
||||
"""
|
||||
Тесты для класса DataResponse
|
||||
"""
|
||||
|
||||
def test_init_with_dict_data(self):
|
||||
"""
|
||||
Проверяет корректное создание ответа со словарем данных и дефолтными статус-кодами
|
||||
"""
|
||||
|
||||
test_dict = {"id": 42, "name": "Main Project", "is_active": True}
|
||||
test_meta = {"version": "1.0.0"}
|
||||
|
||||
response = DataResponse(data=test_dict, meta=test_meta)
|
||||
|
||||
# Проверяем честный HTTP-статус в заголовках
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
# Проверяем контракт тела JSON
|
||||
self.assertEqual(response.data["status"], status.HTTP_200_OK)
|
||||
# Так как код 200 (< 400), объект обязан лежать именно в "data"
|
||||
self.assertEqual(response.data["data"], test_dict)
|
||||
|
||||
# Проверяем проброс метаданных
|
||||
self.assertEqual(response.data["meta"], test_meta)
|
||||
Reference in New Issue
Block a user