Capture work on users test suite updates to track with new coordinator permsissions.
@@ -18,7 +18,6 @@ from TWLight.applications.models import Application
from TWLight.resources.factories import PartnerFactory
from TWLight.resources.models import Partner
-from TWLight.resources.tests import EditorCraftRoom
from . import views
from .authorization import OAuthBackend
@@ -162,33 +161,28 @@ class ViewsTestCase(TestCase):
def test_coordinator_access(self):
"""Coordinators can see someone else's page."""
+ factory = RequestFactory()
+ request = factory.get(self.url1)
+ request.user = self.user_coordinator
- # Create an editor
- editor = EditorCraftRoom(self, Terms=True, Coordinator=False)
- self.client.logout()
-
- # Create a coordinator with a test client session
- coordinator = EditorCraftRoom(self, Terms=True, Coordinator=True)
-
- # Create a partner and designate our new coordinator
partner = PartnerFactory()
- partner.coordinator = coordinator.user
- # url in question is editor profile page.
- url = reverse('users:editor_detail',
- kwargs={'pk': editor.pk})
+ app = ApplicationFactory(
+ status=Application.PENDING, editor=self.editor1, partner=partner)
- # Test response. Should be denied since editor hasn't applied to
- # relevant partner.
- response = self.client.get(url, follow=True)
- self.assertEqual(response.status_code, 403)
+ # Editor details should not be visible to just any coordinator
+ try:
+ response = views.EditorDetailView.as_view()(request, pk=self.editor1.pk)
+ self.fail("Editor details should not be visible to just any coordinator.")
+ except PermissionDenied:
+ pass
- # Editor applies for access to the partner
- app = ApplicationFactory(status=Application.PENDING, editor=editor, partner=partner)
+ # Designate the coordinator
+ partner.coordinator = self.user_coordinator
+ partner.save
- # Test response. Should be allowed now that editor has applied to
- # relevant partner.
- response = self.client.get(url, follow=True)
+ # Editor details should be visible to the designated coordinator
+ response = views.EditorDetailView.as_view()(request, pk=self.editor1.pk)
self.assertEqual(response.status_code, 200)
