Esempio n. 1
0
    def setUp(self):
        self.country = CountryFactory()
        self.country2 = CountryFactory()
        self.address = AddressFactory()
        self.address2 = AddressFactory()
        self.address2.country = self.country2
        self.address2.save()

        self.assertNotEqual(self.country.pk, self.country2.pk,
                            'Try again. Random got you!')

        request = RequestFactory().get('/')
        request.session = {}

        self.basket_id = 'bar'
        BasketItemFactory(basket_id=self.basket_id)
        BasketItemFactory(basket_id=self.basket_id)

        self.rate1 = ShippingRate.objects.create(
            name='rate1',
            rate=99,
            carrier='rate1c',
            description='rate1d',
            basket_id=self.basket_id,
        )

        self.rate2 = ShippingRate.objects.create(
            name='rate2',
            rate=97,
            carrier='rate2c',
            description='rate2d',
            basket_id=self.basket_id,
            destination=self.address,
        )

        self.rate3 = ShippingRate.objects.create(
            name='rate3',
            rate=95,
            carrier='rate3c',
            description='rate3d',
            destination=self.address,
        )

        self.rate4 = ShippingRate.objects.create(
            name='rate4',
            rate=93,
            carrier='rate4c',
            description='rate4d',
        )
        self.rate4.countries.add(self.country)

        self.rate5 = ShippingRate.objects.create(
            name='rate5',
            rate=95,
            carrier='rate5c',
            description='rate5d',
            destination=self.address2,
        )
Esempio n. 2
0
class ShippingRateProcessorAPITest(LongclawTestCase):
    def setUp(self):
        self.country = CountryFactory()
        self.country.iso = '11'
        self.country.save()

        self.address = AddressFactory()
        self.address.country = self.country
        self.address.save()

        self.processor = ShippingRateProcessor()
        self.processor.save()
        self.processor.countries.add(self.country)

    def test_shipping_option_endpoint_without_destination(self):
        params = {
            'country_code': self.country.pk,
        }
        response = self.get_test('longclaw_applicable_shipping_rate_list',
                                 params=params,
                                 success_expected=False)
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(response.data['message'],
                         "Destination address is required for rates to 11.")

    def test_shipping_option_endpoint_gets_processor_rates(self):
        params = {
            'destination': self.address.pk,
        }
        with mock.patch('longclaw.shipping.api.ShippingRateProcessor.get_rates'
                        ) as mocked_get_rates:
            mocked_get_rates.return_value = []

            response = self.get_test('longclaw_applicable_shipping_rate_list',
                                     params=params)
            self.assertTrue(mocked_get_rates.called)
            self.assertEqual(mocked_get_rates.call_count, 1)

            processor = ShippingRateProcessor()
            processor.save()
            processor.countries.add(self.country)

            response = self.get_test('longclaw_applicable_shipping_rate_list',
                                     params=params)
            self.assertEqual(mocked_get_rates.call_count, 3)
Esempio n. 3
0
 def test_post_checkout(self):
     """
     Test correctly posting to the checkout view
     """
     country = CountryFactory()
     request = RequestFactory().post(
         reverse('longclaw_checkout_view'), {
             'shipping-name': 'bob',
             'shipping-line_1': 'blah blah',
             'shipping-postcode': 'ytxx 23x',
             'shipping-city': 'London',
             'shipping-country': country.pk,
             'email': '*****@*****.**'
         })
     request.session = {}
     bid = basket_id(request)
     BasketItemFactory(basket_id=bid)
     response = CheckoutView.as_view()(request)
     self.assertEqual(response.status_code, 302)
Esempio n. 4
0
    def setUp(self):
        self.country = CountryFactory()
        self.address = AddressFactory()

        request = RequestFactory().get('/')
        request.session = {}

        self.basket_id = 'foo'
        BasketItemFactory(basket_id=self.basket_id)
        BasketItemFactory(basket_id=self.basket_id)

        self.rate1 = ShippingRate.objects.create(
            name='rate1',
            rate=99,
            carrier='rate1c',
            description='rate1d',
            basket_id=self.basket_id,
        )

        self.rate2 = ShippingRate.objects.create(
            name='rate2',
            rate=97,
            carrier='rate2c',
            description='rate2d',
            basket_id=self.basket_id,
            destination=self.address,
        )

        self.rate3 = ShippingRate.objects.create(
            name='rate3',
            rate=95,
            carrier='rate3c',
            description='rate3d',
            destination=self.address,
        )

        self.rate4 = ShippingRate.objects.create(
            name='rate4',
            rate=93,
            carrier='rate4c',
            description='rate4d',
        )
        self.rate4.countries.add(self.country)
Esempio n. 5
0
    def setUp(self):
        self.country = CountryFactory()
        self.address = AddressFactory()
        self.address_data = {
            'name': 'JANE DOE',
            'line_1': '1600 Pennsylvania Ave NW',
            'city': 'DC',
            'postcode': '20500',
            'country': self.country.pk,
        }

        request = RequestFactory().get('/')
        request.session = {}
        self.bid = bid = basket_id(request)
        self.item = BasketItemFactory(basket_id=bid)
        BasketItemFactory(basket_id=bid)

        self.ratedAddress = address = AddressFactory()

        self.rate1 = ShippingRate.objects.create(
            name='98d17c43-7e20-42bd-b603-a4c83c829c5a',
            rate=99,
            carrier='8717ca67-4691-4dff-96ec-c43cccd15241',
            description='313037e1-644a-4570-808a-f9ba82ecfb34',
            basket_id=bid,
        )

        self.rate2 = ShippingRate.objects.create(
            name='8e721550-594c-482b-b512-54dc1744dff8',
            rate=97,
            carrier='4f4cca35-1a7a-47ec-ab38-a9918e0c04af',
            description='eacb446d-eb17-4ea7-82c1-ac2f62a53a7d',
            basket_id=bid,
            destination=address,
        )

        self.rate3 = ShippingRate.objects.create(
            name='72991859-dc0b-463e-821a-bf8b04aaed2c',
            rate=95,
            carrier='0aa3c318-b045-4a96-a456-69b4cc71d46a',
            description='78b03c47-b20f-4f91-8161-47340367fb34',
            destination=address,
        )
Esempio n. 6
0
 def setUp(self):
     self.country = CountryFactory()