Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

scales_tests.py 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. from decimal import Decimal as D
  2. from django.test import TestCase
  3. from nose.plugins.attrib import attr
  4. from oscar.apps.shipping import Scales
  5. from oscar.apps.basket.models import Basket
  6. from oscar.test import factories
  7. @attr('shipping')
  8. class TestScales(TestCase):
  9. def test_weighs_uses_specified_attribute(self):
  10. scales = Scales(attribute_code='weight')
  11. p = factories.create_product(attributes={'weight': '1'})
  12. self.assertEqual(1, scales.weigh_product(p))
  13. def test_uses_default_weight_when_attribute_is_missing(self):
  14. scales = Scales(attribute_code='weight', default_weight=0.5)
  15. p = factories.create_product()
  16. self.assertEqual(0.5, scales.weigh_product(p))
  17. def test_raises_exception_when_attribute_is_missing(self):
  18. scales = Scales(attribute_code='weight')
  19. p = factories.create_product()
  20. with self.assertRaises(ValueError):
  21. scales.weigh_product(p)
  22. def test_returns_zero_for_empty_basket(self):
  23. basket = Basket()
  24. scales = Scales(attribute_code='weight')
  25. self.assertEquals(0, scales.weigh_basket(basket))
  26. def test_returns_correct_weight_for_nonempty_basket(self):
  27. basket = factories.create_basket(empty=True)
  28. products = [
  29. factories.create_product(attributes={'weight': '1'},
  30. price=D('5.00')),
  31. factories.create_product(attributes={'weight': '2'},
  32. price=D('5.00'))]
  33. for product in products:
  34. basket.add(product)
  35. scales = Scales(attribute_code='weight')
  36. self.assertEquals(1 + 2, scales.weigh_basket(basket))
  37. def test_returns_correct_weight_for_nonempty_basket_with_line_quantities(self):
  38. basket = factories.create_basket(empty=True)
  39. products = [
  40. (factories.create_product(attributes={'weight': '1'},
  41. price=D('5.00')), 3),
  42. (factories.create_product(attributes={'weight': '2'},
  43. price=D('5.00')), 4)]
  44. for product, quantity in products:
  45. basket.add(product, quantity=quantity)
  46. scales = Scales(attribute_code='weight')
  47. self.assertEquals(1*3 + 2*4, scales.weigh_basket(basket))