您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

tests.py 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. from decimal import Decimal as D
  2. from django.conf import settings
  3. from django.core.urlresolvers import reverse
  4. from django.test import TestCase
  5. from oscar.apps.basket.models import Basket, Line
  6. from oscar.test.helpers import create_product, TwillTestCase
  7. class ViewTest(TwillTestCase):
  8. def test_for_smoke(self):
  9. self.visit('basket:summary')
  10. self.assertResponseCodeIs(200)
  11. self.assertPageContains('Basket')
  12. self.assertPageTitleMatches('Oscar')
  13. class BasketModelTest(TestCase):
  14. def setUp(self):
  15. self.basket = Basket.objects.create()
  16. self.dummy_product = create_product()
  17. def test_empty_baskets_have_zero_lines(self):
  18. self.assertTrue(Basket().num_lines == 0)
  19. def test_new_baskets_are_empty(self):
  20. self.assertTrue(Basket().is_empty)
  21. def test_basket_have_with_one_line(self):
  22. Line.objects.create(basket=self.basket, product=self.dummy_product)
  23. self.assertTrue(self.basket.num_lines == 1)
  24. def test_add_product_creates_line(self):
  25. self.basket.add_product(self.dummy_product)
  26. self.assertTrue(self.basket.num_lines == 1)
  27. def test_adding_multiproduct_line_returns_correct_number_of_items(self):
  28. self.basket.add_product(self.dummy_product, 10)
  29. self.assertEqual(self.basket.num_items, 10)
  30. class BasketViewsTest(TestCase):
  31. def test_empty_basket_view(self):
  32. url = reverse('basket:summary')
  33. response = self.client.get(url)
  34. self.assertEquals(200, response.status_code)
  35. self.assertEquals(0, response.context['basket'].num_lines)
  36. def test_anonymous_add_to_basket_creates_cookie(self):
  37. dummy_product = create_product(price=D('10.00'))
  38. url = reverse('basket:add')
  39. post_params = {'product_id': dummy_product.id,
  40. 'action': 'add',
  41. 'quantity': 1}
  42. response = self.client.post(url, post_params)
  43. self.assertTrue('oscar_open_basket' in response.cookies)
  44. class BasketThresholdTest(TestCase):
  45. def setUp(self):
  46. self._old_threshold = settings.OSCAR_MAX_BASKET_QUANTITY_THRESHOLD
  47. settings.OSCAR_MAX_BASKET_QUANTITY_THRESHOLD = 3
  48. def tearDown(self):
  49. settings.OSCAR_MAX_BASKET_QUANTITY_THRESHOLD = self._old_threshold
  50. def test_adding_more_than_threshold_raises(self):
  51. dummy_product = create_product(price=D('10.00'))
  52. url = reverse('basket:add')
  53. post_params = {'product_id': dummy_product.id,
  54. 'action': 'add',
  55. 'quantity': 2}
  56. response = self.client.post(url, post_params)
  57. self.assertTrue('oscar_open_basket' in response.cookies)
  58. post_params = {'product_id': dummy_product.id,
  59. 'action': 'add',
  60. 'quantity': 2}
  61. response = self.client.post(url, post_params)
  62. self.assertTrue('Your basket currently has 2 items.' in
  63. response.cookies['messages'].value)