Exemplo n.º 1
0
    def test_409_if_order_in_disallowed_status(
        self,
        disallowed_status,
        quote_fields,
        public_omis_api_client,
    ):
        """
        Test that if the order is not in one of the allowed statuses, the endpoint
        returns 409.
        """
        quote = QuoteFactory(**quote_fields)
        order = OrderFactory(
            status=disallowed_status,
            quote=quote,
        )

        url = reverse(
            'api-v3:public-omis:quote:accept',
            kwargs={'public_token': order.public_token},
        )
        response = public_omis_api_client.post(url, json_={})

        assert response.status_code == status.HTTP_409_CONFLICT
        assert response.json() == {
            'detail': ('The action cannot be performed '
                       f'in the current status {disallowed_status.label}.'),
        }
    def test_get_draft_with_cancelled_quote(self):
        """Test getting a cancelled quote with order in draft is allowed."""
        order = OrderFactory(
            quote=QuoteFactory(cancelled_on=now()),
            status=OrderStatus.draft,
        )

        url = reverse(
            'api-v3:omis-public:quote:detail',
            kwargs={'public_token': order.public_token},
        )
        client = self.create_api_client(
            scope=Scope.public_omis_front_end,
            grant_type=Application.GRANT_CLIENT_CREDENTIALS,
        )
        response = client.get(url)

        quote = order.quote
        assert response.status_code == status.HTTP_200_OK
        assert response.json() == {
            'created_on': format_date_or_datetime(quote.created_on),
            'cancelled_on': format_date_or_datetime(quote.cancelled_on),
            'accepted_on': None,
            'expires_on': quote.expires_on.isoformat(),
            'content': quote.content,
            'terms_and_conditions': TermsAndConditions.objects.first().content,
        }
    def test_409_if_order_in_disallowed_status(self, disallowed_status, quote_fields):
        """
        Test that if the order is not in one of the allowed statuses, the endpoint
        returns 409.
        """
        quote = QuoteFactory(**quote_fields)
        order = OrderFactory(
            status=disallowed_status,
            quote=quote,
        )

        url = reverse(
            f'api-v3:omis-public:quote:accept',
            kwargs={'public_token': order.public_token},
        )
        client = self.create_api_client(
            scope=Scope.public_omis_front_end,
            grant_type=Application.GRANT_CLIENT_CREDENTIALS,
        )
        response = client.post(url)

        assert response.status_code == status.HTTP_409_CONFLICT
        assert response.json() == {
            'detail': (
                'The action cannot be performed '
                f'in the current status {OrderStatus[disallowed_status]}.'
            ),
        }
    def test_get_without_ts_and_cs(self):
        """Test a successful call to get a quote without Ts and Cs."""
        order = OrderFactory(
            quote=QuoteFactory(terms_and_conditions=None),
            status=OrderStatus.QUOTE_AWAITING_ACCEPTANCE,
        )

        url = reverse('api-v3:omis:quote:detail', kwargs={'order_pk': order.pk})
        response = self.api_client.get(url)

        assert response.status_code == status.HTTP_200_OK
        assert response.json()['terms_and_conditions'] == ''
Exemplo n.º 5
0
    def test_verbs_not_allowed(self, verb, public_omis_api_client):
        """Test that makes sure the other verbs are not allowed."""
        order = OrderFactory(
            quote=QuoteFactory(),
            status=OrderStatus.QUOTE_AWAITING_ACCEPTANCE,
        )

        url = reverse(
            'api-v3:public-omis:quote:detail',
            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
Exemplo n.º 6
0
    def test_get_without_ts_and_cs(self, public_omis_api_client):
        """Test a successful call to get a quote without Ts and Cs."""
        order = OrderFactory(
            quote=QuoteFactory(accepted_on=now(), terms_and_conditions=None),
            status=OrderStatus.QUOTE_ACCEPTED,
        )

        url = reverse(
            'api-v3:public-omis:quote:detail',
            kwargs={'public_token': order.public_token},
        )
        response = public_omis_api_client.get(url)

        assert response.status_code == status.HTTP_200_OK
        assert response.json()['terms_and_conditions'] == ''
    def test_403_if_scope_not_allowed(self, scope):
        """Test that other oauth2 scopes are not allowed."""
        order = OrderFactory(
            quote=QuoteFactory(),
            status=OrderStatus.quote_awaiting_acceptance,
        )

        url = reverse(
            'api-v3:omis-public:quote:detail',
            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
    def test_verbs_not_allowed(self, verb):
        """Test that makes sure the other verbs are not allowed."""
        order = OrderFactory(
            quote=QuoteFactory(),
            status=OrderStatus.quote_awaiting_acceptance,
        )

        url = reverse(
            'api-v3:omis-public:quote:detail',
            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
    def test_get_without_ts_and_cs(self):
        """Test a successful call to get a quote without Ts and Cs."""
        order = OrderFactory(
            quote=QuoteFactory(accepted_on=now(), terms_and_conditions=None),
            status=OrderStatus.quote_accepted,
        )

        url = reverse(
            'api-v3:omis-public:quote:detail',
            kwargs={'public_token': order.public_token},
        )
        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_200_OK
        assert response.json()['terms_and_conditions'] == ''
Exemplo n.º 10
0
    def test_accept_open_quote(self):
        """Test that an open quote can be accepted."""
        quote = QuoteFactory()
        assert not quote.accepted_on
        assert not quote.accepted_by

        contact = ContactFactory()

        with freeze_time('2017-07-12 13:00'):
            quote.accept(by=contact)

            quote.refresh_from_db()
            assert quote.accepted_on == now()
            assert quote.accepted_by == contact
Exemplo n.º 11
0
    def test_cancel_open_quote(self):
        """Test that an open quote can be cancelled."""
        quote = QuoteFactory()
        assert not quote.cancelled_on
        assert not quote.cancelled_by

        adviser = AdviserFactory()

        with freeze_time('2017-07-12 13:00'):
            quote.cancel(by=adviser)

            quote.refresh_from_db()
            assert quote.cancelled_on == now()
            assert quote.cancelled_by == adviser
Exemplo n.º 12
0
    def test_get(self, order_status, public_omis_api_client):
        """Test a successful call to get a quote."""
        order = OrderFactory(
            quote=QuoteFactory(accepted_on=now()),
            status=order_status,
        )

        url = reverse(
            'api-v3:public-omis:quote:detail',
            kwargs={'public_token': order.public_token},
        )
        response = public_omis_api_client.get(url)

        quote = order.quote
        assert response.status_code == status.HTTP_200_OK
        assert response.json() == {
            'created_on': format_date_or_datetime(quote.created_on),
            'cancelled_on': None,
            'accepted_on': format_date_or_datetime(quote.accepted_on),
            'expires_on': quote.expires_on.isoformat(),
            'content': quote.content,
            'terms_and_conditions': TermsAndConditions.objects.first().content,
        }
Exemplo n.º 13
0
    def test_get_draft_with_cancelled_quote(self, public_omis_api_client):
        """Test getting a cancelled quote with order in draft is allowed."""
        order = OrderFactory(
            quote=QuoteFactory(cancelled_on=now()),
            status=OrderStatus.DRAFT,
        )

        url = reverse(
            'api-v3:public-omis:quote:detail',
            kwargs={'public_token': order.public_token},
        )
        response = public_omis_api_client.get(url)

        quote = order.quote
        assert response.status_code == status.HTTP_200_OK
        assert response.json() == {
            'created_on': format_date_or_datetime(quote.created_on),
            'cancelled_on': format_date_or_datetime(quote.cancelled_on),
            'accepted_on': None,
            'expires_on': quote.expires_on.isoformat(),
            'content': quote.content,
            'terms_and_conditions': TermsAndConditions.objects.first().content,
        }
Exemplo n.º 14
0
    def test_409_if_order_in_disallowed_status(self, disallowed_status):
        """
        Test that if the order is not in one of the allowed statuses, the endpoint
        returns 409.
        """
        quote = QuoteFactory()
        order = OrderFactory(
            status=disallowed_status,
            quote=quote,
        )

        url = reverse(
            f'api-v3:omis:quote:cancel',
            kwargs={'order_pk': order.pk},
        )
        response = self.api_client.post(url)

        assert response.status_code == status.HTTP_409_CONFLICT
        assert response.json() == {
            'detail':
            ('The action cannot be performed '
             f'in the current status {OrderStatus[disallowed_status]}.'),
        }
    def test_get(self, order_status, public_omis_api_client):
        """Test getting an existing order by `public_token`."""
        order = OrderFactory(
            quote=QuoteFactory(),
            status=order_status,
        )

        url = reverse(
            'api-v3:public-omis:order:detail',
            kwargs={'public_token': order.public_token},
        )
        response = public_omis_api_client.get(url)

        assert response.status_code == status.HTTP_200_OK
        assert response.json() == {
            'public_token': order.public_token,
            'reference': order.reference,
            'status': order.status,
            'created_on': format_date_or_datetime(order.created_on),
            'company': {
                'id': str(order.company.pk),
                'name': order.company.name,
            },
            'contact': {
                'id': str(order.contact.pk),
                'name': order.contact.name,
            },
            'primary_market': {
                'id': str(order.primary_market.id),
                'name': order.primary_market.name,
            },
            'uk_region': {
                'id': str(order.uk_region.id),
                'name': order.uk_region.name,
            },
            'contact_email': order.contact_email,
            'contact_phone': order.contact_phone,
            'vat_status': order.vat_status,
            'vat_number': order.vat_number,
            'vat_verified': order.vat_verified,
            'po_number': order.po_number,
            'discount_value': order.discount_value,
            'net_cost': order.net_cost,
            'subtotal_cost': order.subtotal_cost,
            'vat_cost': order.vat_cost,
            'total_cost': order.total_cost,
            'billing_company_name': order.billing_company_name,
            'billing_contact_name': order.billing_contact_name,
            'billing_email': order.billing_email,
            'billing_phone': order.billing_phone,
            'billing_address_1': order.billing_address_1,
            'billing_address_2': order.billing_address_2,
            'billing_address_town': order.billing_address_town,
            'billing_address_county': order.billing_address_county,
            'billing_address_postcode': order.billing_address_postcode,
            'billing_address_country': {
                'id': str(order.billing_address_country.pk),
                'name': order.billing_address_country.name,
            },
            'paid_on': None,
            'completed_on': None,
        }