def test_list_milestone_superuser(self):
     request = self.factory.get('/api/milestone/')
     request.user = factories.User.build(is_superuser=True, is_staff=True)
     view = MilestoneViewSet.as_view({'get': 'list'})
     response = view(request)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(len(response.data), 2)
    def test_create_milestone(self):
        user_url = reverse('user-detail',
                           kwargs={'pk': self.user.id},
                           request=self.request)

        data = {'name': 'Project Implementation'}
        self.request = APIRequestFactory().post('/api/milestone/', data)
        self.request.user = self.user
        view = MilestoneViewSet.as_view({'post': 'create'})
        response = view(self.request)

        self.assertEqual(response.status_code, 201)
        self.assertEqual(response.data['name'], u'Project Implementation')
        self.assertEqual(response.data['created_by'], user_url)
    def test_list_milestone_view_only(self):
        request = self.factory.get('/api/milestone/')
        WorkflowTeam.objects.create(workflow_user=self.tola_user,
                                    role=factories.Group(name=ROLE_VIEW_ONLY))
        request.user = self.tola_user.user
        view = MilestoneViewSet.as_view({'get': 'list'})
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 0)

        factories.Milestone(organization=self.tola_user.organization)
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 1)
    def test_list_milestone_org_admin(self):
        request = self.factory.get('/api/milestone/')
        group_org_admin = factories.Group(name=ROLE_ORGANIZATION_ADMIN)
        self.tola_user.user.groups.add(group_org_admin)

        request.user = self.tola_user.user
        view = MilestoneViewSet.as_view({'get': 'list'})
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 0)

        factories.Milestone(organization=self.tola_user.organization)
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 1)