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.

dashboard_tests.py 2.8KB

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