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, )
def setUp(self): self.shipping_address = AddressFactory() self.billing_address = AddressFactory() self.email = "*****@*****.**" self.request = RequestFactory().get('/') self.request.session = {} self.request.site = Site.find_for_request(self.request) self.basket_id = basket_id(self.request) BasketItemFactory(basket_id=self.basket_id)
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 = TrivialShippingRateProcessor() self.processor.save() self.processor.countries.add(self.country)
def setUp(self): """Create a basket with things in it """ request = RequestFactory().get('/') request.session = {} self.bid = bid = basket_id(request) self.item = BasketItemFactory(basket_id=bid) BasketItemFactory(basket_id=bid) self.address = 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, )
def test_checkout_success(self): """ Test the checkout success view """ address = AddressFactory() order = OrderFactory(shipping_address=address, billing_address=address) response = self.client.get(reverse_lazy('longclaw_checkout_success', kwargs={'pk': order.id})) self.assertEqual(response.status_code, 200)
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)
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, )
def test_get_shipping_cost_kwargs_with_destination(self): destination = AddressFactory() request = RequestFactory().get('/', {'destination': destination.pk}) api_request = upgrade_to_api_request(request) result = get_shipping_cost_kwargs(api_request) self.assertEqual(result['country_code'], destination.country.pk) self.assertEqual(result['destination'], destination) self.assertEqual(result['basket_id'], basket_id(api_request)) self.assertEqual(result['settings'], Configuration.for_site(api_request.site)) self.assertEqual(result['name'], 'standard')
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)
class TrivialShippingRateProcessorAPITest(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 = TrivialShippingRateProcessor() self.processor.save() self.processor.countries.add(self.country) def add_item_to_basket(self): BasketItemFactory(basket_id='foo') def assert_contains_turtle(self, response): self.assertContains(response, 'turtle') def assert_contains_rabbit(self, response): self.assertContains(response, 'rabbit') def assert_contains_cheetah(self, response): self.assertContains(response, 'cheetah') def assert_not_contains_turtle(self, response): self.assertNotContains(response, 'turtle') def assert_not_contains_rabbit(self, response): self.assertNotContains(response, 'rabbit') def assert_not_contains_cheetah(self, response): self.assertNotContains(response, 'cheetah') def test_zero_rates(self, m1): params = { 'destination': self.address.pk, } response = self.get_test('longclaw_applicable_shipping_rate_list', params=params) self.assertEqual(len(response.data), 0) self.assert_not_contains_turtle(response) self.assert_not_contains_rabbit(response) self.assert_not_contains_cheetah(response) def test_one_rate(self, m1): self.add_item_to_basket() params = { 'destination': self.address.pk, } response = self.get_test('longclaw_applicable_shipping_rate_list', params=params) self.assertEqual(len(response.data), 1, response.content) self.assert_contains_turtle(response) self.assert_not_contains_rabbit(response) self.assert_not_contains_cheetah(response) return response def test_one_rate_cost(self, m1): rate_list_response = self.test_one_rate() rate = rate_list_response.data[0] self.assertIn('name', rate) name = rate['name'] params = dict( destination=self.address.pk, shipping_rate_name=name, ) response = self.get_test('longclaw_shipping_cost', params=params) self.assert_contains_turtle(response) self.assertIn('rate', response.data) self.assertEqual(response.data['rate'], 2) def test_two_rates(self, m1): self.add_item_to_basket() self.add_item_to_basket() params = { 'destination': self.address.pk, } response = self.get_test('longclaw_applicable_shipping_rate_list', params=params) self.assertEqual(len(response.data), 2, response.content) self.assert_contains_turtle(response) self.assert_contains_rabbit(response) self.assert_not_contains_cheetah(response) def test_three_rates(self, m1): self.add_item_to_basket() self.add_item_to_basket() self.add_item_to_basket() params = { 'destination': self.address.pk, } response = self.get_test('longclaw_applicable_shipping_rate_list', params=params) self.assertEqual(len(response.data), 3, response.content) self.assert_contains_turtle(response) self.assert_contains_rabbit(response) self.assert_contains_cheetah(response)
def setUp(self): self.address = AddressFactory()
class ShippingOptionEndpointTest(LongclawTestCase): 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, ) @mock.patch('longclaw.shipping.api.basket_id', return_value='bar') def test_get_rate1rate4_option_urlkwargs(self, basket_id_func): """ We expect rate1 because of the basket id. We expect rate4 because of the country. """ expected_pks = [self.rate1.pk, self.rate4.pk] serializer = ShippingRateSerializer( ShippingRate.objects.filter(pk__in=expected_pks), many=True) response = self.get_test('longclaw_shipping_options', urlkwargs={'country': self.country.pk}) self.assertEqual(len(response.data), len(expected_pks)) self.assertEqual(response.data, serializer.data) @mock.patch('longclaw.shipping.api.basket_id', return_value='bar') def test_get_rate1rate4_option(self, basket_id_func): """ We expect rate1 because of the basket id. We expect rate4 because of the country. """ expected_pks = [self.rate1.pk, self.rate4.pk] serializer = ShippingRateSerializer( ShippingRate.objects.filter(pk__in=expected_pks), many=True) params = { 'country_code': self.country.pk, } response = self.get_test('longclaw_applicable_shipping_rate_list', params=params) self.assertEqual(len(response.data), len(expected_pks)) self.assertEqual(response.data, serializer.data) @mock.patch('longclaw.shipping.api.basket_id', return_value='bar') def test_get_rate1rate2rate3_option(self, basket_id_func): """ We expect rate1 because of the basket id. We expect rate2 because of the destination address and basket id. We expect rate3 because of the destination address. """ expected_pks = [self.rate1.pk, self.rate2.pk, self.rate3.pk] serializer = ShippingRateSerializer( ShippingRate.objects.filter(pk__in=expected_pks), many=True) params = { 'destination': self.address.pk, } response = self.get_test('longclaw_applicable_shipping_rate_list', params=params) self.assertEqual(len(response.data), len(expected_pks)) self.assertEqual(response.data, serializer.data) def test_get_rate5_option(self): """ We expect rate5 because of the destination address. """ expected_pks = [self.rate5.pk] serializer = ShippingRateSerializer( ShippingRate.objects.filter(pk__in=expected_pks), many=True) params = { 'destination': self.address2.pk, } response = self.get_test('longclaw_applicable_shipping_rate_list', params=params) self.assertEqual(len(response.data), len(expected_pks)) self.assertEqual(response.data, serializer.data) def test_get_rate4_option(self): """ We expect rate4 because of the country. """ expected_pks = [self.rate4.pk] serializer = ShippingRateSerializer( ShippingRate.objects.filter(pk__in=expected_pks), many=True) params = { 'country_code': self.country.pk, } response = self.get_test('longclaw_applicable_shipping_rate_list', params=params) self.assertEqual(len(response.data), len(expected_pks)) self.assertEqual(response.data, serializer.data) def test_get_rate4_option_urlkwargs(self): """ We expect rate4 because of the country. """ expected_pks = [self.rate4.pk] serializer = ShippingRateSerializer( ShippingRate.objects.filter(pk__in=expected_pks), many=True) response = self.get_test('longclaw_shipping_options', urlkwargs={'country': self.country.pk}) self.assertEqual(len(response.data), len(expected_pks)) self.assertEqual(response.data, serializer.data) @mock.patch('longclaw.shipping.api.basket_id', return_value='bar') def test_get_rate1_option(self, basket_id_func): """ We expect rate1 because of the basket. """ expected_pks = [self.rate1.pk] serializer = ShippingRateSerializer( ShippingRate.objects.filter(pk__in=expected_pks), many=True) params = { 'country_code': self.country2.pk, } response = self.get_test('longclaw_applicable_shipping_rate_list', params=params) self.assertEqual(len(response.data), len(expected_pks)) self.assertEqual(response.data, serializer.data) @mock.patch('longclaw.shipping.api.basket_id', return_value='bar') def test_get_rate6_option(self, basket_id_func): """ We expect rate6 because of the basket id and address. """ expected_pks = [self.rate1.pk] serializer = ShippingRateSerializer( ShippingRate.objects.filter(pk__in=expected_pks), many=True) params = { 'country_code': self.country2.pk, } response = self.get_test('longclaw_applicable_shipping_rate_list', params=params) self.assertEqual(len(response.data), len(expected_pks)) self.assertEqual(response.data, serializer.data)