test_dashboard.py 2.1 KB

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