mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-08 19:26:48 +00:00
- Routers use path converters (use_regex_path=False): computes, instances and flavors take <int:...> ids, so non-numeric ids get 404 and drf-spectacular derives the parameter types itself. - Each method declares what it really returns: detail serializers, a shared StatusSerializer for status-only replies, no request body for actions. Instance properties used by the details serializer get return type hints. - The create-instance API drops the firmware field. Its only accepted value was "" (BIOS), which produced an empty, invalid enum, and the UEFI branch behind it was unreachable. Clients that still send it are unaffected; DRF ignores unknown fields. The schema now passes spectacular --validate --fail-on-warn; a test keeps it that way.
18 lines
748 B
Python
18 lines
748 B
Python
import os
|
|
|
|
from django.contrib.auth import get_user_model
|
|
from django.core.management import call_command
|
|
from django.test import TestCase
|
|
from rest_framework.test import APIClient
|
|
|
|
|
|
class APISchemaTestCase(TestCase):
|
|
def test_schema_is_valid_without_warnings(self):
|
|
call_command("spectacular", "--validate", "--fail-on-warn", "--file", os.devnull)
|
|
|
|
def test_non_numeric_compute_id_is_not_routed(self):
|
|
admin = get_user_model().objects.create_superuser("schema_admin", "a@example.com", "pw")
|
|
client = APIClient()
|
|
client.force_login(admin)
|
|
self.assertEqual(client.get("/api/v1/computes/abc/instances/").status_code, 404)
|
|
self.assertEqual(client.get("/api/v1/instances/abc/").status_code, 404)
|