tests.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # coding: utf-8
  2. """
  3. Test permissions
  4. """
  5. from __future__ import print_function
  6. from __future__ import absolute_import
  7. from __future__ import division
  8. from __future__ import unicode_literals
  9. from django.test import TestCase
  10. from backend import const
  11. from backend.test_common import *
  12. class PermissionsTestCase(NMBasicFixtureMixin, NMTestUtilsMixin, TestCase):
  13. def setUp(self):
  14. super(PermissionsTestCase, self).setUp()
  15. self.app = self.make_user("app", const.STATUS_DC, alioth=True, fd_comment="FD_COMMENTS")
  16. self.adv = self.make_user("adv", const.STATUS_DD_NU)
  17. self.am = self.make_user("am", const.STATUS_DD_NU)
  18. self.proc = self.make_process(self.app, const.STATUS_DD_NU, const.PROGRESS_AM, advocates=[self.adv], manager=self.am)
  19. def test_status_all(self):
  20. class WhenView(NMTestUtilsWhen):
  21. url = reverse("api_status")
  22. self.assertVisit(WhenView(), ThenForbidden())
  23. for u in self.users.viewkeys():
  24. self.assertVisit(WhenView(user=self.users[u]), ThenSuccess())
  25. def test_status_one(self):
  26. class WhenView(NMTestUtilsWhen):
  27. url = reverse("api_status")
  28. data = { "person": "enrico@debian.org" }
  29. self.assertVisit(WhenView(), ThenSuccess())
  30. for u in self.users.viewkeys():
  31. self.assertVisit(WhenView(user=self.users[u]), ThenSuccess())
  32. def test_status_status(self):
  33. class WhenView(NMTestUtilsWhen):
  34. url = reverse("api_status")
  35. data = { "status": "dd_u,dd_nu" }
  36. self.assertVisit(WhenView(), ThenForbidden())
  37. for u in self.users.viewkeys():
  38. self.assertVisit(WhenView(user=self.users[u]), ThenSuccess())
  39. def test_status_post(self):
  40. class WhenView(NMTestUtilsWhen):
  41. url = reverse("api_status")
  42. method = "post"
  43. data_content_type = "application/json"
  44. data = '["enrico@debian.org","example-guest@users.alioth.debian.org"]'
  45. self.assertVisit(WhenView(), ThenSuccess())
  46. for u in self.users.viewkeys():
  47. self.assertVisit(WhenView(user=self.users[u]), ThenSuccess())