API: adhere to Bugsink's DB-transactional model

as per https://www.bugsink.com/blog/database-transactions/
This commit is contained in:
Klaas van Schelven
2025-09-11 18:01:05 +02:00
parent 1c0745f24f
commit 9ad66d7b50
11 changed files with 33 additions and 20 deletions

View File

@@ -2,7 +2,7 @@ from django.shortcuts import get_object_or_404
from rest_framework import viewsets
from bugsink.api_pagination import AscDescCursorPagination
from bugsink.api_mixins import ExpandViewSetMixin
from bugsink.api_mixins import ExpandViewSetMixin, AtomicRequestMixin
from .models import Project
from .serializers import (
@@ -20,7 +20,7 @@ class ProjectPagination(AscDescCursorPagination):
default_direction = "asc"
class ProjectViewSet(ExpandViewSetMixin, viewsets.ModelViewSet):
class ProjectViewSet(AtomicRequestMixin, ExpandViewSetMixin, viewsets.ModelViewSet):
"""
/api/canonical/0/projects/
GET /projects/ → list ordered by name ASC, hides soft-deleted, optional ?team=<uuid> filter

View File

@@ -1,4 +1,4 @@
from django.test import TestCase as DjangoTestCase
from bugsink.test_utils import TransactionTestCase25251 as TransactionTestCase
from django.urls import reverse
from rest_framework.test import APIClient
@@ -7,7 +7,7 @@ from teams.models import Team
from projects.models import Project
class ProjectApiTests(DjangoTestCase):
class ProjectApiTests(TransactionTestCase):
def setUp(self):
self.client = APIClient()
token = AuthToken.objects.create()
@@ -77,7 +77,7 @@ class ProjectApiTests(DjangoTestCase):
self.assertEqual(r.status_code, 405)
class ExpansionTests(DjangoTestCase):
class ExpansionTests(TransactionTestCase):
"""
Expansion tests are exercised via ProjectViewSet, but the intent is to validate the
generic ExpandableSerializerMixin infrastructure.