def test_signals(self): product = factories.create_product() record = factories.create_stockrecord( currency='USD', product=product, price_excl_tax=D('10.00')) factories.create_purchase_info(record) basket = Basket() basket.strategy = USStrategy() basket.add(product) basket.save() uat1 = cache.get_basket_uat(basket) # Add another product basket.add(product) # Timestamp should have gotten bumped by the BasketLine postsave signal uat2 = cache.get_basket_uat(basket) self.assertTrue(uat2 > uat1) # Save the basket basket.save() # Timestamp should have gotten bumped by the Basket postsave signal uat3 = cache.get_basket_uat(basket) self.assertTrue(uat3 > uat2)
def _create_product(self): product = factories.create_product(title='My Product', product_class='My Product Class') record = factories.create_stockrecord(currency='USD', product=product, num_in_stock=10, price_excl_tax=Decimal('10.00')) factories.create_purchase_info(record) return product
def _create_product(self): product = factories.create_product(title="My Product", product_class="My Product Class") record = factories.create_stockrecord(currency="USD", product=product, num_in_stock=10, price=Decimal("10.00")) factories.create_purchase_info(record) return product
def _create_product(self, price=D('10.00')): product = factories.create_product( title='My Product', product_class='My Product Class') record = factories.create_stockrecord( currency='USD', product=product, num_in_stock=10, price_excl_tax=price) factories.create_purchase_info(record) return product
def setUp(self): self.basket = Basket() self.basket.strategy = strategy.Default() self.product = factories.create_product() self.record = factories.create_stockrecord(self.product, price_excl_tax=D("10.00")) self.purchase_info = factories.create_purchase_info(self.record) self.basket.add(self.product, 10)
def setUp(self): self.basket = Basket() self.basket.strategy = strategy.Default() self.product = factories.create_product() self.record = factories.create_stockrecord(self.product, price_excl_tax=D('10.00')) self.purchase_info = factories.create_purchase_info(self.record) self.basket.add(self.product, 10)
def setUp(self): self.basket = Basket() self.basket.strategy = strategy.Default() self.product = factories.create_product() self.record = factories.create_stockrecord(currency='GBP', product=self.product, price=D('10.00')) self.purchase_info = factories.create_purchase_info(self.record) self.basket.add(self.product)
def test_multi_baskets(self): product = factories.create_product() record = factories.create_stockrecord( currency='USD', product=product, price_excl_tax=D('10.00')) factories.create_purchase_info(record) basket1 = Basket() basket1.strategy = USStrategy() basket1.add(product) basket1.save() basket2 = Basket() basket2.strategy = USStrategy() basket2.add(product) basket2.save() uat11 = cache.get_basket_uat(basket1) uat21 = cache.get_basket_uat(basket2) time.sleep(0.25) # Nothing has changed, so timestamp should be the same as last time we called it uat12 = cache.get_basket_uat(basket1) uat22 = cache.get_basket_uat(basket2) self.assertEqual(uat12, uat11) self.assertEqual(uat22, uat21) # Manually bump one of the timestamps cache.update_basket_uat(basket2) uat13 = cache.get_basket_uat(basket1) uat23 = cache.get_basket_uat(basket2) self.assertEqual(uat13, uat11) self.assertTrue(uat23 > uat13) time.sleep(0.25) # Manually bump the other timestamp cache.update_basket_uat(basket1) uat14 = cache.get_basket_uat(basket1) uat24 = cache.get_basket_uat(basket2) self.assertTrue(uat14 > uat11) self.assertEqual(uat24, uat23)
def prepare_basket(self): basket = Basket() basket.strategy = USStrategy() product = factories.create_product() record = factories.create_stockrecord( currency='USD', product=product, price_excl_tax=D('10.00')) factories.create_purchase_info(record) basket.add(product) from_address = PartnerAddress() from_address.line1 = '221 Baker st' from_address.line2 = 'B' from_address.line4 = 'Anchorage' from_address.state = 'AK' from_address.postcode = '99501' from_address.country = Country.objects.get(pk='US') from_address.partner = record.partner from_address.save() return basket
def setUp(self): self.product = factories.create_product() self.record = factories.create_stockrecord(self.product, price_excl_tax=D("10.00")) self.purchase_info = factories.create_purchase_info(self.record) self.main_basket = Basket() self.main_basket.strategy = strategy.Default() self.main_basket.add(self.product, quantity=2) self.merge_basket = Basket() self.merge_basket.strategy = strategy.Default() self.merge_basket.add(self.product, quantity=1) self.main_basket.merge(self.merge_basket)
def setUp(self): self.product = factories.create_product() self.record = factories.create_stockrecord(self.product, price_excl_tax=D('10.00')) self.purchase_info = factories.create_purchase_info(self.record) self.main_basket = Basket() self.main_basket.strategy = strategy.Default() self.main_basket.add(self.product, quantity=2) self.merge_basket = Basket() self.merge_basket.strategy = strategy.Default() self.merge_basket.add(self.product, quantity=1) self.main_basket.merge(self.merge_basket)
def test_basic(self): product = factories.create_product() record = factories.create_stockrecord( currency='USD', product=product, price_excl_tax=D('10.00')) factories.create_purchase_info(record) basket = Basket() basket.strategy = USStrategy() basket.add(product) basket.save() uat1 = cache.get_basket_uat(basket) time.sleep(0.5) # Nothing has changed, so timestamp should be the same as last time we called it uat2 = cache.get_basket_uat(basket) self.assertEqual(uat2, uat1) # Manually bump the timestamp cache.update_basket_uat(basket) uat3 = cache.get_basket_uat(basket) self.assertTrue(uat3 > uat1)
def test_apply_taxes_custom_sku(self, get_transport): basket = Basket() basket.strategy = USStrategy() product = factories.create_product(attributes={ 'cch_product_sku': 'CCH Product SKU', }) product.attr.cch_product_sku = 'XYZ456' product.save() record = factories.create_stockrecord( currency='USD', product=product, price_excl_tax=D('10.00')) factories.create_purchase_info(record) basket.add(product) from_address = PartnerAddress() from_address.line1 = '221 Baker st' from_address.line2 = 'B' from_address.line4 = 'Anchorage' from_address.state = 'AK' from_address.postcode = '99501' from_address.country = Country.objects.get(pk='US') from_address.partner = record.partner from_address.save() to_address = self.get_to_address() def test_request(request): self.assertNodeText(request.message, p('Body/CalculateRequest/EntityID'), 'TESTSANDBOX') self.assertNodeText(request.message, p('Body/CalculateRequest/DivisionID'), '42') self.assertNodeText(request.message, p('Body/CalculateRequest/order/CustomerType'), '08') self.assertNodeText(request.message, p('Body/CalculateRequest/order/InvoiceDate'), '2016-04-13T12:14:44.018599-04:00') self.assertNodeCount(request.message, p('Body/CalculateRequest/order/LineItems/LineItem'), 1) self.assertNodeText(request.message, p('Body/CalculateRequest/order/LineItems/LineItem/AvgUnitPrice'), '10.00') self.assertNodeText(request.message, p('Body/CalculateRequest/order/LineItems/LineItem/ID'), str(basket.all_lines()[0].id)) self.assertNodeText(request.message, p('Body/CalculateRequest/order/LineItems/LineItem/NexusInfo/ShipFromAddress/City'), 'Anchorage') self.assertNodeText(request.message, p('Body/CalculateRequest/order/LineItems/LineItem/NexusInfo/ShipFromAddress/CountryCode'), 'US') self.assertNodeText(request.message, p('Body/CalculateRequest/order/LineItems/LineItem/NexusInfo/ShipFromAddress/Line1'), '221 Baker st') self.assertNodeText(request.message, p('Body/CalculateRequest/order/LineItems/LineItem/NexusInfo/ShipFromAddress/Line2'), 'B') self.assertNodeText(request.message, p('Body/CalculateRequest/order/LineItems/LineItem/NexusInfo/ShipFromAddress/PostalCode'), '99501') self.assertNodeText(request.message, p('Body/CalculateRequest/order/LineItems/LineItem/NexusInfo/ShipFromAddress/StateOrProvince'), 'AK') self.assertNodeText(request.message, p('Body/CalculateRequest/order/LineItems/LineItem/NexusInfo/ShipToAddress/City'), 'Brooklyn') self.assertNodeText(request.message, p('Body/CalculateRequest/order/LineItems/LineItem/NexusInfo/ShipToAddress/CountryCode'), 'US') self.assertNodeText(request.message, p('Body/CalculateRequest/order/LineItems/LineItem/NexusInfo/ShipToAddress/Line1'), '123 Evergreen Terrace') self.assertNodeText(request.message, p('Body/CalculateRequest/order/LineItems/LineItem/NexusInfo/ShipToAddress/Line2'), 'Apt #1') self.assertNodeText(request.message, p('Body/CalculateRequest/order/LineItems/LineItem/NexusInfo/ShipToAddress/PostalCode'), '11201') self.assertNodeText(request.message, p('Body/CalculateRequest/order/LineItems/LineItem/NexusInfo/ShipToAddress/StateOrProvince'), 'NY') self.assertNodeText(request.message, p('Body/CalculateRequest/order/LineItems/LineItem/Quantity'), '1') self.assertNodeText(request.message, p('Body/CalculateRequest/order/LineItems/LineItem/SKU'), 'XYZ456') self.assertNodeText(request.message, p('Body/CalculateRequest/order/ProviderType'), '70') self.assertNodeText(request.message, p('Body/CalculateRequest/order/SourceSystem'), 'Oscar') self.assertNodeText(request.message, p('Body/CalculateRequest/order/TestTransaction'), 'true') self.assertNodeText(request.message, p('Body/CalculateRequest/order/TransactionID'), '0') self.assertNodeText(request.message, p('Body/CalculateRequest/order/TransactionType'), '01') self.assertNodeText(request.message, p('Body/CalculateRequest/order/finalize'), 'false') resp = self._get_cch_response_normal( basket.all_lines()[0].id ) get_transport.return_value = self._build_transport_with_reply(resp, test_request=test_request) self.assertFalse(basket.is_tax_known) self.assertEqual(basket.total_excl_tax, D('10.00')) CCHTaxCalculator().apply_taxes(basket, to_address) self.assertTrue(basket.is_tax_known) self.assertEqual(basket.total_excl_tax, D('10.00')) self.assertEqual(basket.total_incl_tax, D('10.89')) self.assertEqual(basket.total_tax, D('0.89')) purchase_info = basket.all_lines()[0].purchase_info self.assertEqual(purchase_info.price.excl_tax, D('10.00')) self.assertEqual(purchase_info.price.incl_tax, D('10.89')) self.assertEqual(purchase_info.price.tax, D('0.89'))