Пример #1
0
    def test_ongoing(self):
        """
        Test that given:
            session 1 - order 1 - status created
            session 2 - order 1 - status submitted
            session 3 - order 1 - status failed
            session 4 - order 2 - status started
            session 5 - order 2 - status success
            session 6 - order 2 - status cancelled

        the method .ongoing() on the queryset only returns the sessions
        which are considered not finished.
        """
        order1, order2 = OrderWithAcceptedQuoteFactory.create_batch(2)

        order1_sessions = PaymentGatewaySessionFactory.create_batch(
            3,
            order=order1,
            status=factory.Iterator([
                PaymentGatewaySessionStatus.CREATED,
                PaymentGatewaySessionStatus.SUBMITTED,
                PaymentGatewaySessionStatus.FAILED,
            ]),
        )
        order2_sessions = PaymentGatewaySessionFactory.create_batch(
            3,
            order=order2,
            status=factory.Iterator([
                PaymentGatewaySessionStatus.STARTED,
                PaymentGatewaySessionStatus.SUCCESS,
                PaymentGatewaySessionStatus.CANCELLED,
            ]),
        )

        # test qs without filters
        qs = PaymentGatewaySession.objects.ongoing()
        assert set(qs.values_list('id', flat=True)) == {
            order1_sessions[0].id,
            order1_sessions[1].id,
            order2_sessions[0].id,
        }

        # test qs with order filter
        qs = PaymentGatewaySession.objects.filter(order=order1).ongoing()
        assert set(qs.values_list('id', flat=True)) == {
            order1_sessions[0].id,
            order1_sessions[1].id,
        }
 def test_404_if_session_belongs_to_another_order(self, public_omis_api_client):
     """
     Test that if the payment gateway session belongs to another order,
     the endpoint returns 404.
     """
     orders = OrderWithAcceptedQuoteFactory.create_batch(2)
     sessions = PaymentGatewaySessionFactory.create_batch(2, order=factory.Iterator(orders))
     url = reverse(
         'api-v3:public-omis:payment-gateway-session:detail',
         kwargs={
             'public_token': orders[0].public_token,
             'pk': sessions[1].id,
         },
     )
     response = public_omis_api_client.get(url)
     assert response.status_code == status.HTTP_404_NOT_FOUND
 def test_404_if_session_belongs_to_another_order(self):
     """
     Test that if the payment gateway session belongs to another order,
     the endpoint returns 404.
     """
     orders = OrderWithAcceptedQuoteFactory.create_batch(2)
     sessions = PaymentGatewaySessionFactory.create_batch(
         2, order=factory.Iterator(orders))
     url = reverse(
         'api-v3:omis-public:payment-gateway-session:detail',
         kwargs={
             'public_token': orders[0].public_token,
             'pk': sessions[1].id,
         },
     )
     client = self.create_api_client(
         scope=Scope.public_omis_front_end,
         grant_type=Application.GRANT_CLIENT_CREDENTIALS,
     )
     response = client.get(url)
     assert response.status_code == status.HTTP_404_NOT_FOUND