コード例 #1
0
 def __init__(self, show_bank_transfer_first=False, **kwargs):
     super().__init__(**kwargs)
     if show_bank_transfer_first:
         self['payment_method'].field.choices = reversed(self['payment_method'].field.choices)
     if not check_payment_service_available():
         self.fields['payment_method'].initial = PaymentMethod.bank_transfer.name
         self.fields['payment_method'].disabled = True
コード例 #2
0
 def test_healthcheck_with_service_down_returns_message_to_users(self):
     with responses.RequestsMock() as rsps:
         rsps.add(rsps.GET, api_url('/service-availability/'), json={
             'gov_uk_pay': {'status': False, 'message_to_users': 'Scheduled downtime'}
         })
         available, message_to_users = check_payment_service_available()
     self.assertFalse(available)
     self.assertEqual(message_to_users, 'Scheduled downtime')
    def __init__(self, **kwargs):
        django_choices = PaymentMethodBankTransferDisabled.django_choices()
        self.base_fields['payment_method'] = forms.ChoiceField(
            error_messages={
                'required': _('Please choose how you want to send money')
            },
            choices=django_choices)

        payment_service_available, message_to_users = check_payment_service_available(
        )
        if not payment_service_available:
            self.base_fields[
                'payment_method'].message_to_users = message_to_users
            self.base_fields['payment_method'].disabled = True
        # Handle session deserialization of fields defined against instance manually :(
        if 'payment_method' in kwargs:
            kwargs['data']['payment_method'] = kwargs.pop('payment_method')
        super().__init__(**kwargs)
コード例 #4
0
 def test_healthcheck_with_service_down_returns_false(self):
     with responses.RequestsMock() as rsps:
         rsps.add(rsps.GET, api_url('/service-availability/'), json={'gov_uk_pay': {'status': False}})
         available, message_to_users = check_payment_service_available()
     self.assertFalse(available)
     self.assertIsNone(message_to_users)
コード例 #5
0
 def test_healthcheck_with_service_unspecified_returns_true(self):
     with responses.RequestsMock() as rsps:
         rsps.add(rsps.GET, api_url('/service-availability/'), json={'another_service': {'status': False}})
         available, message_to_users = check_payment_service_available()
     self.assertTrue(available)
     self.assertIsNone(message_to_users)
コード例 #6
0
 def test_failed_healthcheck_returns_true(self):
     with responses.RequestsMock() as rsps:
         rsps.add(rsps.GET, api_url('/service-availability/'), body=b'Server error', status=500)
         available, message_to_users = check_payment_service_available()
     self.assertTrue(available)
     self.assertIsNone(message_to_users)
コード例 #7
0
 def test_healthcheck_timeout_returns_true(self):
     with responses.RequestsMock() as rsps:
         rsps.add(rsps.GET, api_url('/service-availability/'), body=Timeout())
         available, message_to_users = check_payment_service_available()
     self.assertTrue(available)
     self.assertIsNone(message_to_users)
コード例 #8
0
 def test_failed_healthcheck_with_service_down_returns_false(self, mock_requests):
     mock_requests.get.return_value.status_code = 500
     mock_requests.get.return_value.json.return_value = {'gov_uk_pay': {'status': False}}
     self.assertFalse(check_payment_service_available())
コード例 #9
0
 def test_failed_healthcheck_with_service_unspecified_returns_true(self, mock_requests):
     mock_requests.get.return_value.status_code = 500
     mock_requests.get.return_value.json.return_value = {}
     self.assertTrue(check_payment_service_available())
コード例 #10
0
 def test_healthcheck_timeout_returns_true(self, mock_requests):
     mock_requests.get.side_effect = Timeout()
     self.assertTrue(check_payment_service_available())
コード例 #11
0
 def test_passed_healthcheck_returns_true(self, mock_requests):
     mock_requests.get.return_value.status_code = 200
     self.assertTrue(check_payment_service_available())