ykGlory
ykGlory

Reputation: 1

It is possible django APIView recognize request from django Testcase?

Can I determine if the request has been made from the django testcase when the request is made in 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)

Upvotes: 0

Views: 26

Answers (0)

Related Questions