"""Tests for OpenAPI helpers.""" from __future__ import annotations from django.test import SimpleTestCase from drf_yasg import openapi from rest_framework import serializers from apps.core.openapi import _get_status_description, api_docs class DummySerializer(serializers.Serializer): name = serializers.CharField() class OpenAPIDocsTest(SimpleTestCase): def test_get_status_description_default(self): self.assertEqual(_get_status_description(418), "HTTP 418") def test_api_docs_builds_responses(self): decorator = api_docs( summary="Test", description="Desc", responses={ 200: DummySerializer, 404: "Not found", 400: openapi.Response(description="Bad request"), }, tags=["tag"], ) def view(_request): return None decorated = decorator(view) self.assertTrue(callable(decorated))