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.

test_voucher.py 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. from django.urls import reverse
  2. from oscar.test.testcases import WebTestCase
  3. class TestVoucherListSearch(WebTestCase):
  4. is_staff = True
  5. TEST_CASES = [
  6. ({}, ['Not in a set']),
  7. (
  8. {'name': 'Bob Smith'},
  9. ['Name matches "Bob Smith"']
  10. ),
  11. (
  12. {'code': 'abcd1234'},
  13. ['Code is "ABCD1234"']
  14. ),
  15. (
  16. {'offer_name': 'Shipping offer'},
  17. ['Offer name matches "Shipping offer"']
  18. ),
  19. (
  20. {'is_active': True},
  21. ['Is active']
  22. ),
  23. (
  24. {'is_active': False},
  25. ['Is inactive']
  26. ),
  27. (
  28. {'in_set': True},
  29. ['In a set']
  30. ),
  31. (
  32. {'in_set': False},
  33. ['Not in a set']
  34. ),
  35. (
  36. {'has_offers': True},
  37. ['Has offers']
  38. ),
  39. (
  40. {'has_offers': False},
  41. ['Has no offers']
  42. ),
  43. (
  44. {
  45. 'name': 'Bob Smith',
  46. 'code': 'abcd1234',
  47. 'offer_name': 'Shipping offer',
  48. 'is_active': True,
  49. 'in_set': True,
  50. 'has_offers': True,
  51. },
  52. [
  53. 'Name matches "Bob Smith"',
  54. 'Code is "ABCD1234"',
  55. 'Offer name matches "Shipping offer"',
  56. 'Is active',
  57. 'In a set',
  58. 'Has offers',
  59. ]
  60. ),
  61. ]
  62. def test_search_filter_descriptions(self):
  63. url = reverse('dashboard:voucher-list')
  64. for params, expected_filters in self.TEST_CASES:
  65. response = self.get(url, params=params)
  66. self.assertEqual(response.status_code, 200)
  67. applied_filters = [
  68. el.text.strip() for el in
  69. response.html.select('.search-filter-list .badge')
  70. ]
  71. self.assertEqual(applied_filters, expected_filters)