You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

model_tests.py 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # -*- coding: utf-8 -*-
  2. from django.test import TestCase
  3. from oscar.apps.basket.models import Basket
  4. from oscar.apps.partner import strategy
  5. from oscar.test.factories import (
  6. BasketFactory, BasketLineAttributeFactory, ProductFactory, OptionFactory)
  7. class TestANewBasket(TestCase):
  8. def setUp(self):
  9. self.basket = Basket()
  10. self.basket.strategy = strategy.Default()
  11. def test_has_zero_lines(self):
  12. self.assertEqual(0, self.basket.num_lines)
  13. def test_has_zero_items(self):
  14. self.assertEqual(0, self.basket.num_items)
  15. def test_doesnt_contain_vouchers(self):
  16. self.assertFalse(self.basket.contains_a_voucher)
  17. def test_can_be_edited(self):
  18. self.assertTrue(self.basket.can_be_edited)
  19. def test_is_empty(self):
  20. self.assertTrue(self.basket.is_empty)
  21. def test_is_not_submitted(self):
  22. self.assertFalse(self.basket.is_submitted)
  23. def test_has_no_applied_offers(self):
  24. self.assertEqual({}, self.basket.applied_offers())
  25. class TestBasketLine(TestCase):
  26. def test_description(self):
  27. basket = BasketFactory()
  28. product = ProductFactory(title="A product")
  29. basket.add_product(product)
  30. line = basket.lines.first()
  31. self.assertEqual(line.description, "A product")
  32. def test_description_with_attributes(self):
  33. basket = BasketFactory()
  34. product = ProductFactory(title="A product")
  35. basket.add_product(product)
  36. line = basket.lines.first()
  37. BasketLineAttributeFactory(
  38. line=line, value=u'\u2603', option__name='with')
  39. self.assertEqual(line.description, u"A product (with = '\u2603')")
  40. def test_create_line_reference(self):
  41. basket = BasketFactory()
  42. product = ProductFactory(title="A product")
  43. option = OptionFactory(name="product_option", code="product_option")
  44. option_product = ProductFactory(title=u'Asunción')
  45. options = [{'option' : option, 'value': option_product}]
  46. basket.add_product(product, options = options)