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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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.ranges.tests import *
  11. from oscar.apps.dashboard.reviews.tests import *
  12. from oscar.apps.dashboard.views import IndexView
  13. from oscar.test import ClientTestCase
  14. from oscar.test.helpers import create_order
  15. class AnonymousUserTests(ClientTestCase):
  16. def test_login_form_is_displayed_for_anon_user(self):
  17. response = self.client.get(reverse('dashboard:index'))
  18. self.assertTrue('Username' in response.content)
  19. class DashboardViewTests(ClientTestCase):
  20. is_staff = True
  21. def test_dashboard_index_is_for_staff_only(self):
  22. urls = ('dashboard:index',
  23. 'dashboard:order-list',
  24. 'dashboard:users-index',)
  25. for name in urls:
  26. response = self.client.get(reverse(name))
  27. self.assertTrue('Password' not in response.content)
  28. def test_dashboard_hourly_report_with_no_orders(self):
  29. report = IndexView().get_hourly_report()
  30. self.assertItemsEqual(report, ['order_total_hourly', 'max_revenue',
  31. 'y_range'])
  32. self.assertEquals(len(report['order_total_hourly']), 24)
  33. self.assertEquals(len(report['y_range']), 0)
  34. self.assertEquals(report['max_revenue'], 0)
  35. def test_dashboard_hourly_report_with_orders(self):
  36. create_order(total_incl_tax=D('34.05'), total_excl_tax=D('34.05'))
  37. create_order(total_incl_tax=D('21.90'), total_excl_tax=D('21.90'))
  38. report = IndexView().get_hourly_report()
  39. self.assertEquals(len(report['order_total_hourly']), 24)
  40. self.assertEquals(len(report['y_range']), 11)
  41. self.assertEquals(report['max_revenue'], D('55.95'))
  42. def test_dashboard_index_has_stats_vars_in_context(self):
  43. response = self.client.get(reverse('dashboard:index'))
  44. self.assertInContext(response, 'total_orders_last_day')
  45. self.assertInContext(response, 'total_lines_last_day')
  46. self.assertInContext(response, 'average_order_costs')
  47. self.assertInContext(response, 'total_revenue_last_day')
  48. self.assertInContext(response, 'hourly_report_dict')
  49. self.assertInContext(response, 'total_products')
  50. self.assertInContext(response, 'total_open_stock_alerts')
  51. self.assertInContext(response, 'total_closed_stock_alerts')
  52. self.assertInContext(response, 'total_site_offers')
  53. self.assertInContext(response, 'total_vouchers')
  54. self.assertInContext(response, 'total_orders')
  55. self.assertInContext(response, 'total_lines')
  56. self.assertInContext(response, 'total_revenue')
  57. self.assertInContext(response, 'order_status_breakdown')