Пример #1
0
    def test_create_from_order(
        self,
        mocked_generate_datetime_based_reference,
    ):
        """Test that Payment.objects.create_from_order creates a payment."""
        mocked_generate_datetime_based_reference.return_value = '201702010004'

        order = OrderPaidFactory()
        by = AdviserFactory()
        attrs = {
            'transaction_reference': 'lorem ipsum',
            'amount': 1001,
            'received_on': dateutil_parse('2017-01-01').date(),
        }
        payment = Payment.objects.create_from_order(
            order=order, by=by, attrs=attrs,
        )

        payment.refresh_from_db()
        assert payment.reference == '201702010004'
        assert payment.created_by == by
        assert payment.order == order
        assert payment.transaction_reference == attrs['transaction_reference']
        assert payment.additional_reference == ''
        assert payment.amount == attrs['amount']
        assert payment.received_on == attrs['received_on']
Пример #2
0
    def test_advisers_notified(self):
        """
        Test that calling `quote_accepted` sends an email to all advisers notifying them that
        the quote has been accepted.
        """
        order = OrderPaidFactory(assignees=[])
        assignees = OrderAssigneeFactory.create_batch(2, order=order)
        subscribers = OrderSubscriberFactory.create_batch(2, order=order)

        notify.client.reset_mock()

        notify.quote_accepted(order)

        assert notify.client.send_email_notification.called
        # 1 = customer, 4 = assignees/subscribers
        assert len(
            notify.client.send_email_notification.call_args_list) == (4 + 1)

        calls_by_email = {
            data['email_address']: {
                'template_id': data['template_id'],
                'personalisation': data['personalisation'],
            }
            for _, data in notify.client.send_email_notification.call_args_list
        }
        for item in itertools.chain(assignees, subscribers):
            call = calls_by_email[item.adviser.get_current_email()]
            assert call[
                'template_id'] == Template.quote_accepted_for_adviser.value
            assert call['personalisation'][
                'recipient name'] == item.adviser.name
            assert call['personalisation'][
                'embedded link'] == order.get_datahub_frontend_url()
Пример #3
0
    def test_get(self):
        """Test a successful call to get a list of payments."""
        order = OrderPaidFactory()
        PaymentFactory.create_batch(2, order=order)
        PaymentFactory.create_batch(
            5)  # create some extra ones not linked to `order`

        url = reverse('api-v3:omis:payment:collection',
                      kwargs={'order_pk': order.pk})
        response = self.api_client.get(url)
        assert response.status_code == status.HTTP_200_OK
        assert response.json() == [{
            'created_on':
            format_date_or_datetime(payment.created_on),
            'reference':
            payment.reference,
            'transaction_reference':
            payment.transaction_reference,
            'additional_reference':
            payment.additional_reference,
            'amount':
            payment.amount,
            'method':
            payment.method,
            'received_on':
            payment.received_on.isoformat(),
        } for payment in order.payments.all()]
Пример #4
0
    def test_verbs_not_allowed(self, verb, public_omis_api_client):
        """Test that makes sure the other verbs are not allowed."""
        order = OrderPaidFactory()

        url = reverse(
            'api-v3:public-omis:payment:collection',
            kwargs={'public_token': order.public_token},
        )
        response = getattr(public_omis_api_client, verb)(url, json_={})
        assert response.status_code == status.HTTP_405_METHOD_NOT_ALLOWED
Пример #5
0
    def test_quote_accepted(self, end_to_end_notify, notify_task_return_value_tracker):
        """
        Test templates of quote accepted for customer and advisers.
        If the template variables have been changed in GOV.UK notifications the
        celery task will be unsuccessful.
        """
        order = OrderPaidFactory()

        end_to_end_notify.quote_accepted(order)
        self._assert_tasks_successful(2, notify_task_return_value_tracker)
Пример #6
0
    def test_verbs_not_allowed(self, verb):
        """Test that makes sure the other verbs are not allowed."""
        order = OrderPaidFactory()

        url = reverse(
            'api-v3:omis-public:payment:collection',
            kwargs={'public_token': order.public_token},
        )
        client = self.create_api_client(
            scope=Scope.public_omis_front_end,
            grant_type=Application.GRANT_CLIENT_CREDENTIALS,
        )
        response = getattr(client, verb)(url)
        assert response.status_code == status.HTTP_405_METHOD_NOT_ALLOWED
Пример #7
0
    def test_403_if_scope_not_allowed(self, scope):
        """Test that other oauth2 scopes are not allowed."""
        order = OrderPaidFactory()

        url = reverse(
            'api-v3:omis-public:payment:collection',
            kwargs={'public_token': order.public_token},
        )
        client = self.create_api_client(
            scope=scope,
            grant_type=Application.GRANT_CLIENT_CREDENTIALS,
        )
        response = client.get(url)
        assert response.status_code == status.HTTP_403_FORBIDDEN
Пример #8
0
    def test_customer_notified(self):
        """
        Test that calling `quote_accepted` sends an email notifying the customer that
        they have accepted the quote.
        """
        order = OrderPaidFactory()

        notify.client.reset_mock()

        notify.quote_accepted(order)

        assert notify.client.send_email_notification.called
        call_args = notify.client.send_email_notification.call_args_list[0][1]
        assert call_args['email_address'] == order.get_current_contact_email()
        assert call_args[
            'template_id'] == Template.quote_accepted_for_customer.value
        assert call_args['personalisation'][
            'recipient name'] == order.contact.name
        assert call_args['personalisation'][
            'embedded link'] == order.get_public_facing_url()