コード例 #1
0
    def test_conflict(self, mock_send_email):
        """
        Test that if GOV.UK Pay returns 409 when capturing 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}/capture/'),
                status=409,
            )

            with self.assertRaises(HTTPError) as e:
                client.capture_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.capture_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.capture_govuk_payment(govuk_payment)
        self.assertEqual(returned_status, None)

        self.assertEqual(len(mail.outbox), 0)
    def test_capture(self):
        """
        Test that if the govuk payment is in 'capturable' state, the method captures the payment
        and no email is sent.

        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}/capture/'),
                status=204,
            )

            returned_status = client.capture_govuk_payment(govuk_payment)

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

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

        # try to capture the payment again, nothing should happen
        client.capture_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.capture_govuk_payment(govuk_payment)
            self.assertEqual(returned_status, status)

            mock_send_email.assert_not_called()