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.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. from decimal import Decimal as D
  2. from django.core.urlresolvers import reverse
  3. from oscar.apps.dashboard.orders.tests import *
  4. from oscar.apps.dashboard.reports.tests import *
  5. from oscar.apps.dashboard.users.tests import *
  6. from oscar.apps.dashboard.promotions.tests import *
  7. from oscar.apps.dashboard.catalogue.tests import *
  8. from oscar.apps.dashboard.pages.tests import *
  9. from oscar.apps.dashboard.offers.tests import *
  10. from oscar.apps.dashboard.views import IndexView
  11. from oscar.test import ClientTestCase
  12. from oscar.test.helpers import create_order
  13. class AnonymousUserTests(ClientTestCase):
  14. def test_login_form_is_displayed_for_anon_user(self):
  15. response = self.client.get(reverse('dashboard:index'))
  16. self.assertTrue('Username' in response.content)
  17. class DashboardViewTests(ClientTestCase):
  18. is_staff = True
  19. def test_dashboard_index_is_for_staff_only(self):
  20. urls = ('dashboard:index',
  21. 'dashboard:order-list',
  22. 'dashboard:users-index',)
  23. for name in urls:
  24. response = self.client.get(reverse(name))
  25. self.assertTrue('Password' not in response.content)
  26. def test_dashboard_hourly_report_with_no_orders(self):
  27. report = IndexView().get_hourly_report()
  28. self.assertItemsEqual(report, ['order_total_hourly', 'max_revenue',
  29. 'y_range'])
  30. self.assertEquals(len(report['order_total_hourly']), 24)
  31. self.assertEquals(len(report['y_range']), 0)
  32. self.assertEquals(report['max_revenue'], 0)
  33. def test_dashboard_hourly_report_with_orders(self):
  34. create_order(total_incl_tax=D('34.05'), total_excl_tax=D('34.05'))
  35. create_order(total_incl_tax=D('21.90'), total_excl_tax=D('21.90'))
  36. report = IndexView().get_hourly_report()
  37. self.assertEquals(len(report['order_total_hourly']), 24)
  38. self.assertEquals(len(report['y_range']), 11)
  39. self.assertEquals(report['max_revenue'], D('55.95'))
  40. def test_dashboard_index_has_stats_vars_in_context(self):
  41. response = self.client.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')