示例#1
0
    def test_conflict(self, mock_send_email):
        """
        Test that if GOV.UK Pay returns 409 when cancelling a payment, the method raises an HTTPError.
        """
        client = PaymentClient()

        payment_id = 'invalid'
        govuk_payment = {
            'payment_id': payment_id,
            'state': {
                'status': GovUkPaymentStatus.capturable.name,
            },
        }
        with responses.RequestsMock() as rsps:
            rsps.add(
                rsps.POST,
                govuk_url(f'/payments/{payment_id}/cancel/'),
                status=409,
            )

            with self.assertRaises(HTTPError) as e:
                client.cancel_govuk_payment(govuk_payment)

            self.assertEqual(
                e.exception.response.status_code,
                409,
            )

        mock_send_email.assert_not_called()
示例#2
0
    def test_do_nothing_if_govukpayment_is_falsy(self, mock_send_email):
        """
        Test that if the passed in govuk payment dict is falsy, the method doesn't do anything.
        """
        client = PaymentClient()

        govuk_payment = {}
        returned_status = client.cancel_govuk_payment(govuk_payment)
        self.assertEqual(returned_status, None)

        mock_send_email.assert_not_called()
    def test_do_nothing_if_govukpayment_is_falsy(self):
        """
        Test that if the passed in govuk payment dict is falsy, the method doesn't do anything.
        """
        client = PaymentClient()

        govuk_payment = {}
        returned_status = client.cancel_govuk_payment(govuk_payment)
        self.assertEqual(returned_status, None)

        self.assertEqual(len(mail.outbox), 0)
    def test_cancel(self):
        """
        Test that if the govuk payment is in 'capturable' state, the method cancels the payment.

        If the method is called again, nothing happen so that to avoid side effects.
        """
        client = PaymentClient()

        payment_id = 'payment-id'
        govuk_payment = {
            'payment_id': payment_id,
            'state': {
                'status': GovUkPaymentStatus.capturable.name,
            },
            'email': '*****@*****.**',

        }
        with responses.RequestsMock() as rsps:
            rsps.add(
                rsps.POST,
                govuk_url(f'/payments/{payment_id}/cancel/'),
                status=204,
            )

            returned_status = client.cancel_govuk_payment(govuk_payment)

        self.assertEqual(returned_status, GovUkPaymentStatus.cancelled)
        self.assertEqual(
            govuk_payment['state']['status'],
            GovUkPaymentStatus.cancelled.name,
        )

        self.assertEqual(len(mail.outbox), 0)

        # try to capture the payment again, nothing should happen
        client.cancel_govuk_payment(govuk_payment)
        self.assertEqual(len(mail.outbox), 0)
示例#5
0
    def test_do_nothing_if_payment_in_finished_state(self, mock_send_email):
        """
        Test that if the govuk payment is already in a finished state, the method doesn't
        do anything.
        """
        finished_statuses = [
            status for status in GovUkPaymentStatus if status.finished()
        ]
        for status in finished_statuses:
            govuk_payment = {
                'payment_id': 'payment-id',
                'state': {
                    'status': status.name,
                },
            }

            client = PaymentClient()
            returned_status = client.cancel_govuk_payment(govuk_payment)
            self.assertEqual(returned_status, status)

            mock_send_email.assert_not_called()