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 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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, TwillTestCase
  6. class ViewTest(TwillTestCase):
  7. def test_for_smoke(self):
  8. self.visit('basket:summary')
  9. self.assertResponseCodeIs(200)
  10. self.assertPageContains('Basket')
  11. self.assertPageTitleMatches('Oscar')
  12. class BasketModelTest(unittest.TestCase):
  13. def setUp(self):
  14. self.basket = Basket.objects.create()
  15. self.dummy_product = create_product()
  16. def test_empty_baskets_have_zero_lines(self):
  17. self.assertTrue(Basket().num_lines == 0)
  18. def test_new_baskets_are_empty(self):
  19. self.assertTrue(Basket().is_empty)
  20. def test_basket_have_with_one_line(self):
  21. Line.objects.create(basket=self.basket, product=self.dummy_product)
  22. self.assertTrue(self.basket.num_lines == 1)
  23. def test_add_product_creates_line(self):
  24. self.basket.add_product(self.dummy_product)
  25. self.assertTrue(self.basket.num_lines == 1)
  26. def test_adding_multiproduct_line_returns_correct_number_of_items(self):
  27. self.basket.add_product(self.dummy_product, 10)
  28. self.assertEqual(self.basket.num_items, 10)
  29. class BasketViewsTest(unittest.TestCase):
  30. def setUp(self):
  31. self.client = Client()
  32. def test_empty_basket_view(self):
  33. url = reverse('basket:summary')
  34. response = self.client.get(url)
  35. self.assertEquals(200, response.status_code)
  36. self.assertEquals(0, response.context['basket'].num_lines)
  37. def test_anonymous_add_to_basket_creates_cookie(self):
  38. dummy_product = create_product()
  39. url = reverse('basket:add')
  40. post_params = {'product_id': dummy_product.id,
  41. 'action': 'add',
  42. 'quantity': 1}
  43. response = self.client.post(url, post_params)
  44. self.assertTrue('oscar_open_basket' in response.cookies)