def test_to_json(self): profile = factories.ShippingProfileFactory() factories.ShippingRuleFactory(profile=profile) result = profile.to_json() self.assertEqual(len(result["rules"]), 1) self.assertEqual(result["shipping_country"]["code"], "GB") self.assertEqual(result["ships_worldwide"], False)
def test_to_json_on_ships_worldwide(self): profile = factories.ShippingProfileFactory(others_price=10, others_price_extra=20) factories.ShippingRuleFactory(profile=profile) result = profile.to_json() self.assertTrue(result["ships_worldwide"]) self.assertEqual(result["others_price"], 10.0) self.assertEqual(result["others_price_extra"], 20.0)
def test_rules_from_other_countries_not_used(self): rule = factories.ShippingRuleFactory( profile=self.prod_1.shipping_profile, rule_price=100, rule_price_extra=1000) rule.countries.add(factories.CountryFactory(code="USA")) self.add_to_cartstall(self.prod_1, 3) self.assertEqual(self.cart_stall.delivery_total().amount, 20)
def test_generates_shipping(self): profile = self.product.shipping_profile rule = factories.ShippingRuleFactory( profile=profile, rule_price=10, rule_price_extra=5, ) rule.countries.add(Country.objects.get(code="GB")) rule.save() expected = "<g:shipping xmlns:g=\"http://base.google.com/ns/1.0\" xmlns=\"\"><g:country>GB</g:country><g:price>10 GBP</g:price></g:shipping>" actual_elems = self.builder.generate_shipping() self.assertEqual(len(actual_elems), 1) actual = etree.tostring(actual_elems[0]) self.assertEqual(expected, actual)
def test_speculative_country_used_if_exists(self): country2 = factories.CountryFactory(code="ES") rule2 = factories.ShippingRuleFactory( profile=self.prod_1.shipping_profile, rule_price=30, rule_price_extra=10) rule2.countries.add(country2) rule2.save() self.cart_stall.address = None self.cart_stall.speculative_country = country2 self.cart_stall.save() self.add_to_cartstall(self.prod_1, 1) delivery = self.cart_stall.delivery_total() self.assertEqual(delivery.amount, 30)
def create_product_with_profile(self, price, price_extra): ship_prof = factories.ShippingProfileFactory( stall=self.cart_stall.stall, others_price=None, others_price_extra=None, ) rule = factories.ShippingRuleFactory( profile=ship_prof, rule_price=price, rule_price_extra=price_extra, ) rule.countries.add(self.country) return factories.ProductFactory(stall=self.cart_stall.stall, shipping_profile=ship_prof)
def test_to_json(self): rule = factories.ShippingRuleFactory(rule_price=10, rule_price_extra=20, despatch_time=2, delivery_time=10, delivery_time_max=20) country1 = factories.CountryFactory(code="USA") country2 = factories.CountryFactory(code="NL") rule.countries.add(country1) rule.countries.add(country2) rule.save() expected = { "rule_price": 10.0, "rule_price_extra": 20.0, "dispatch_time": 2, "delivery_time": 10, "delivery_time_max": 20, } result = rule.to_json() countries = result.pop("countries") self.assertEqual(len(countries), 2) self.assertEqual(expected, result)
def test(self): profile = self.product.shipping_profile rule = factories.ShippingRuleFactory( profile=profile, rule_price=10, rule_price_extra=5, ) rule.countries.add(Country.objects.get(code="GB")) rule.save() expected = [ str(self.product.id), self.product.title, self.product.description, "http://localhost:8000/products/12345678/my-product-title/", "http://localhost:8000/static/images/product/400/default.png", "new", "10 GBP", "in stock", "some category > some child category", "Test Category", "GB:::10 GBP", ] actual = self.builder.generate() self.assertEqual(expected, actual)
def _create_shipping_rule(self, shipping_profile, countries): return factories.ShippingRuleFactory(profile=shipping_profile)
def create_profile_with_uk(self): rule = factories.ShippingRuleFactory() uk = Country.objects.get(code="GB") rule.countries.add(uk) rule.save() return rule.profile
def test_get_default_country_returns_none_if_no_rules(self): rule = factories.ShippingRuleFactory() self.assertIsNone(rule.profile.get_default_country())
def test_get_default_country_returns_first_in_list_if_not_uk(self): country1 = factories.CountryFactory(code="USA") rule = factories.ShippingRuleFactory() rule.countries = [country1] rule.save() self.assertEqual(rule.profile.get_default_country(), country1)