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_dashboard.py 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. from decimal import Decimal as D
  2. from django.urls import reverse
  3. from oscar.core import prices
  4. from oscar.apps.dashboard.views import IndexView
  5. from oscar.apps.order.models import Order
  6. from oscar.test.testcases import WebTestCase
  7. from oscar.test.factories import create_order
  8. class TestDashboardIndexForAnonUser(WebTestCase):
  9. is_anonymous = True
  10. def test_is_not_available(self):
  11. response = self.get(reverse('dashboard:index')).follow()
  12. self.assertContains(response, 'username', status_code=200)
  13. class TestDashboardIndexForStaffUser(WebTestCase):
  14. is_staff = True
  15. def test_is_available(self):
  16. urls = ('dashboard:index',
  17. 'dashboard:order-list',
  18. 'dashboard:users-index',)
  19. for name in urls:
  20. response = self.get(reverse(name))
  21. self.assertTrue('Password' not in response.content.decode('utf8'))
  22. def test_includes_hourly_report_with_no_orders(self):
  23. report = IndexView().get_hourly_report(Order.objects.all())
  24. self.assertEqual(len(report), 3)
  25. keys = ['max_revenue', 'order_total_hourly', 'y_range']
  26. for i, j in zip(sorted(report.keys()), keys):
  27. self.assertEqual(i, j)
  28. self.assertEqual(len(report['order_total_hourly']), 12)
  29. self.assertEqual(len(report['y_range']), 0)
  30. self.assertEqual(report['max_revenue'], 0)
  31. def test_includes_hourly_report_with_orders(self):
  32. create_order(total=prices.Price('GBP', excl_tax=D('34.05'),
  33. tax=D('0.00')))
  34. create_order(total=prices.Price('GBP', excl_tax=D('21.90'),
  35. tax=D('0.00')))
  36. report = IndexView().get_hourly_report(Order.objects.all())
  37. self.assertEqual(len(report['order_total_hourly']), 12)
  38. self.assertEqual(len(report['y_range']), 11)
  39. self.assertEqual(report['max_revenue'], D('60'))
  40. def test_has_stats_vars_in_context(self):
  41. response = self.get(reverse('dashboard:index'))
  42. self.assertInContext(response, 'total_orders_last_day')
  43. self.assertInContext(response, 'total_lines_last_day')
  44. self.assertInContext(response, 'average_order_costs')
  45. self.assertInContext(response, 'total_revenue_last_day')
  46. self.assertInContext(response, 'hourly_report_dict')
  47. self.assertInContext(response, 'total_products')
  48. self.assertInContext(response, 'total_open_stock_alerts')
  49. self.assertInContext(response, 'total_closed_stock_alerts')
  50. self.assertInContext(response, 'total_site_offers')
  51. self.assertInContext(response, 'total_vouchers')
  52. self.assertInContext(response, 'total_orders')
  53. self.assertInContext(response, 'total_lines')
  54. self.assertInContext(response, 'total_revenue')
  55. self.assertInContext(response, 'order_status_breakdown')