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.

tests.py 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. from django.utils import unittest
  2. from django.test.client import Client
  3. from django.core.urlresolvers import reverse
  4. from oscar.apps.basket.models import Basket, Line
  5. from oscar.test.helpers import create_product
  6. class BasketModelTest(unittest.TestCase):
  7. def setUp(self):
  8. self.basket = Basket.objects.create()
  9. self.dummy_product = create_product()
  10. def test_empty_baskets_have_zero_lines(self):
  11. self.assertTrue(Basket().num_lines == 0)
  12. def test_new_baskets_are_empty(self):
  13. self.assertTrue(Basket().is_empty)
  14. def test_basket_have_with_one_line(self):
  15. Line.objects.create(basket=self.basket, product=self.dummy_product)
  16. self.assertTrue(self.basket.num_lines == 1)
  17. def test_add_product_creates_line(self):
  18. self.basket.add_product(self.dummy_product)
  19. self.assertTrue(self.basket.num_lines == 1)
  20. def test_adding_multiproduct_line_returns_correct_number_of_items(self):
  21. self.basket.add_product(self.dummy_product, 10)
  22. self.assertEqual(self.basket.num_items, 10)
  23. class BasketViewsTest(unittest.TestCase):
  24. def setUp(self):
  25. self.client = Client()
  26. def test_empty_basket_view(self):
  27. url = reverse('oscar-basket')
  28. response = self.client.get(url)
  29. self.assertEquals(200, response.status_code)
  30. self.assertEquals(0, response.context['basket'].num_lines)
  31. def test_anonymous_add_to_basket_creates_cookie(self):
  32. dummy_product = create_product()
  33. url = reverse('oscar-basket')
  34. post_params = {'product_id': dummy_product.id,
  35. 'action': 'add',
  36. 'quantity': 1}
  37. response = self.client.post(url, post_params)
  38. self.assertTrue('oscar_open_basket' in response.cookies)