test_dashboard.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. from django.test import TestCase, Client
  2. from jet.dashboard.modules import LinkList, RecentActions
  3. from jet.dashboard.models import UserDashboardModule
  4. from jet.tests.dashboard import TestIndexDashboard
  5. class DashboardTestCase(TestCase):
  6. class Request:
  7. def __init__(self, user):
  8. self.user = user
  9. def setUp(self):
  10. self._login()
  11. self._init_dashboard()
  12. @property
  13. def User(self):
  14. from django.contrib.auth.models import User
  15. return User
  16. def _login(self):
  17. username = 'admin'
  18. email = 'admin@example.com'
  19. password = 'admin'
  20. self.admin = Client()
  21. self.admin_user = self.User.objects.create_superuser(username, email, password)
  22. return self.admin.login(username=username, password=password)
  23. def _init_dashboard(self):
  24. UserDashboardModule.objects.create(
  25. title='',
  26. module='jet.dashboard.modules.LinkList',
  27. app_label=None,
  28. user=self.admin_user.pk,
  29. column=0,
  30. order=0
  31. )
  32. UserDashboardModule.objects.create(
  33. title='',
  34. module='jet.dashboard.modules.RecentActions',
  35. app_label=None,
  36. user=self.admin_user.pk,
  37. column=0,
  38. order=1
  39. )
  40. self.dashboard = TestIndexDashboard({'request': self.Request(self.admin_user)})
  41. def test_custom_columns(self):
  42. self.assertEqual(self.dashboard.columns, 3)
  43. def test_init_with_context_called(self):
  44. self.assertTrue(self.dashboard.init_with_context_called)
  45. def test_load_modules(self):
  46. self.assertEqual(len(self.dashboard.modules), 2)
  47. self.assertTrue(isinstance(self.dashboard.modules[0], LinkList))
  48. self.assertTrue(isinstance(self.dashboard.modules[1], RecentActions))
  49. def test_media(self):
  50. media = self.dashboard.media()
  51. self.assertEqual(len(media.js), 2)
  52. self.assertEqual(media.js[0], 'file.js')
  53. self.assertEqual(media.js[1], 'file2.js')
  54. self.assertEqual(len(media.css), 2)
  55. self.assertEqual(media.css[0], 'file.css')
  56. self.assertEqual(media.css[1], 'file2.css')