您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

user_tests.py 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. from django.contrib.auth.models import User
  2. from django.core.urlresolvers import reverse
  3. from django_dynamic_fixture import new, get, F
  4. from oscar.test import ClientTestCase
  5. from oscar.apps.dashboard.users.views import IndexView
  6. class IndexViewTests(ClientTestCase):
  7. is_staff = True
  8. active_users_ids = []
  9. inactive_users_ids = []
  10. def setUp(self):
  11. super(IndexViewTests, self).setUp()
  12. for i in range(1, 25):
  13. get(User, is_active=True)
  14. for i in range(1, 25):
  15. get(User, is_active=False)
  16. user_queryset = User.objects.all()
  17. self.active_users_ids = user_queryset.filter(is_active=True).values_list('id', flat=True)
  18. self.inactive_users_ids = user_queryset.filter(is_active=False).values_list('id', flat=True)
  19. def test_user_list_view(self):
  20. response = self.client.get(reverse('dashboard:users-index'))
  21. self.assertInContext(response, 'user_list')
  22. self.assertEquals(len(response.context['user_list']), IndexView.paginate_by)
  23. def test_make_active(self):
  24. params = {'action': 'make_active',
  25. 'selected_user': self.inactive_users_ids}
  26. response = self.client.post(reverse('dashboard:users-index'), params)
  27. ex_inactive = User.objects.get(id=self.inactive_users_ids[10])
  28. self.assertIsRedirect(response)
  29. self.assertTrue(ex_inactive.is_active)
  30. def test_make_inactive(self):
  31. params = {'action': 'make_inactive',
  32. 'selected_user': self.active_users_ids}
  33. response = self.client.post(reverse('dashboard:users-index'), params)
  34. ex_active = User.objects.get(id=self.active_users_ids[10])
  35. self.assertIsRedirect(response)
  36. self.assertFalse(ex_active.is_active)
  37. class DetailViewTests(ClientTestCase):
  38. is_staff = True
  39. def test_user_detail_view(self):
  40. response = self.client.get(reverse('dashboard:user-detail', kwargs={'pk': 1} ))
  41. self.assertInContext(response, 'user')
  42. self.assertIsOk(response)