Возможно ли django APIView распознать запрос от django Testcase? [дубликат]
Могу ли я определить, был ли запрос сделан из тестового кейса django, когда запрос сделан в django APIView?
views.py
class BackendView(APIView):
filter_backends = (DjangoFilterBackend,)
filterset_class = BackendFilter
@swagger_auto_schema(responses={200: BackendSerializer()})
@transaction.atomic()
def post(self, request, *args, **kwargs):
# 1. service call
# 2. kafka produce
## Here, I will determine whether the request has been received from the test case and try not to produce kafka if it has been received from the test case.
tests.py
class PrivateBackendApiTests(TestCase):
def test_create_backend(self):
payload = {}
res = self.client.post(BACKENDS_URL, payload, format="json")
self.assertEqual(res.status_code, status.HTTP_201_CREATED)