def test_list_indicatortype_superuser(self): request = self.factory.get('/api/indicatortype/') request.user = factories.User.build(is_superuser=True, is_staff=True) view = IndicatorTypeViewSet.as_view({'get': 'list'}) response = view(request) self.assertEqual(response.status_code, 200) self.assertEqual(len(response.data), 2)
def test_list_indicatortype_view_only(self): request = self.factory.get('/api/indicatortype/') WorkflowTeam.objects.create(workflow_user=self.tola_user, role=factories.Group(name=ROLE_VIEW_ONLY)) request.user = self.tola_user.user view = IndicatorTypeViewSet.as_view({'get': 'list'}) response = view(request) self.assertEqual(response.status_code, 200) self.assertEqual(len(response.data), 0) factories.IndicatorType(organization=self.tola_user.organization) response = view(request) self.assertEqual(response.status_code, 200) self.assertEqual(len(response.data), 1)
def test_list_indicatortype_org_admin(self): request = self.factory.get('/api/indicatortype/') 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 = IndicatorTypeViewSet.as_view({'get': 'list'}) response = view(request) self.assertEqual(response.status_code, 200) self.assertEqual(len(response.data), 0) factories.IndicatorType(organization=self.tola_user.organization) response = view(request) self.assertEqual(response.status_code, 200) self.assertEqual(len(response.data), 1)
def test_filter_indicatortype_normaluser(self): another_org = factories.Organization(name='Another Org') indicatortype1_1 = factories.IndicatorType( organization=self.tola_user.organization) factories.IndicatorType(indicator_type='Another IndicatorType', organization=another_org) request = self.factory.get('/api/indicatortype/?organization__id=%s' % self.tola_user.organization.pk) request.user = self.tola_user.user view = IndicatorTypeViewSet.as_view({'get': 'list'}) response = view(request) self.assertEqual(response.status_code, 200) self.assertEqual(len(response.data), 1) self.assertEqual(response.data[0]['indicator_type'], indicatortype1_1.indicator_type)