def test_coregroup_update(self, request_factory, org_admin): coregroup = factories.CoreGroup.create( name='Program Admin', organization=org_admin.organization) data = { 'name': 'Admin of something else', 'permissions': { 'create': True, 'read': False, 'update': False, 'delete': True }, } request = request_factory.put(reverse('coregroup-detail', args=(coregroup.pk, )), data, format='json') request.user = org_admin response = CoreGroupViewSet.as_view({'put': 'update'})(request, pk=coregroup.pk) assert response.status_code == 200 coregroup_upd = wfm.CoreGroup.objects.get(pk=coregroup.pk) assert coregroup_upd.name == 'Admin of something else' assert coregroup_upd.permissions == 9
def test_coregroup_create_fail_again(self, request_factory, org_admin): request = request_factory.post(reverse('coregroup-list'), { 'name': 'New Group', 'permissions': '1001' }, format='json') request.user = org_admin response = CoreGroupViewSet.as_view({'post': 'create'})(request) assert response.status_code == 400
def test_coregroup_detail_another_org(self, request_factory, org_admin): another_org = factories.Organization(name='Another org') coregroup = factories.CoreGroup.create(organization=another_org) request = request_factory.get( reverse('coregroup-detail', args=(coregroup.pk, ))) request.user = org_admin response = CoreGroupViewSet.as_view({'get': 'retrieve'})(request, pk=coregroup.pk) assert response.status_code == 403
def test_coregroup_detail(self, request_factory, org_admin): coregroup = factories.CoreGroup.create( organization=org_admin.organization) request = request_factory.get( reverse('coregroup-detail', args=(coregroup.pk, ))) request.user = org_admin response = CoreGroupViewSet.as_view({'get': 'retrieve'})(request, pk=coregroup.pk) assert response.status_code == 200
def test_coregroup_list_another_org(self, request_factory, org_admin): another_org = factories.Organization(name='Another org') factories.CoreGroup.create(name='Group 1', organization=org_admin.organization) factories.CoreGroup.create(name='Group 2', organization=another_org) request = request_factory.get(reverse('coregroup-list')) request.user = org_admin response = CoreGroupViewSet.as_view({'get': 'list'})(request) assert response.status_code == 200 assert len(response.data) == 3 # Admins and Users groups + 1 new
def test_coregroup_create_min(self, request_factory, org_admin): data = {'name': 'New Group'} request = request_factory.post(reverse('coregroup-list'), data, format='json') request.user = org_admin response = CoreGroupViewSet.as_view({'post': 'create'})(request) assert response.status_code == 201 coregroup = wfm.CoreGroup.objects.get(name='New Group') assert coregroup.permissions == 4 # check default permissions assert coregroup.organization == org_admin.organization
def test_coregroup_list_global(self, request_factory, org_admin): factories.CoreGroup.create(name='Group 1', organization=org_admin.organization) factories.CoreGroup.create(name='Group Global', organization=None, is_global=True) request = request_factory.get(reverse('coregroup-list')) request.user = org_admin response = CoreGroupViewSet.as_view({'get': 'list'})(request) assert response.status_code == 200 assert len(response.data) == 3 # Admins and Users groups + 1 new
def test_coregroup_views_permissions_org_admin(self, request_factory, org_admin): request = request_factory.get(reverse('coregroup-list')) request.user = org_admin response = CoreGroupViewSet.as_view({'get': 'list'})(request) assert response.status_code == 200 request = request_factory.post(reverse('coregroup-list')) request.user = org_admin response = CoreGroupViewSet.as_view({'post': 'create'})(request) assert response.status_code == 400 request = request_factory.get(reverse('coregroup-detail', args=(1, ))) request.user = org_admin response = CoreGroupViewSet.as_view({'get': 'retrieve'})(request, pk=1) assert response.status_code == 404 request = request_factory.put(reverse('coregroup-detail', args=(1, ))) request.user = org_admin response = CoreGroupViewSet.as_view({'put': 'update'})(request, pk=1) assert response.status_code == 404 request = request_factory.patch(reverse('coregroup-detail', args=(1, ))) request.user = org_admin response = CoreGroupViewSet.as_view({'patch': 'partial_update'})(request, pk=1) assert response.status_code == 404 request = request_factory.delete( reverse('coregroup-detail', args=(1, ))) request.user = org_admin response = CoreGroupViewSet.as_view({'delete': 'destroy'})(request, pk=1) assert response.status_code == 404
def test_coregroup_delete(self, request_factory, org_admin): coregroup = factories.CoreGroup.create( organization=org_admin.organization) request = request_factory.delete( reverse('coregroup-detail', args=(coregroup.pk, ))) request.user = org_admin response = CoreGroupViewSet.as_view({'delete': 'destroy'})(request, pk=coregroup.pk) assert response.status_code == 204 with pytest.raises(wfm.CoreGroup.DoesNotExist): wfm.CoreGroup.objects.get(pk=coregroup.pk)
def test_coregroup_update_fail(self, request_factory, org_admin): coregroup = factories.CoreGroup.create( name='Program Admin', organization=org_admin.organization) data = { 'name': 'Admin of something else', 'permissions': 9, } request = request_factory.put(reverse('coregroup-detail', args=(coregroup.pk, )), data, format='json') request.user = org_admin response = CoreGroupViewSet.as_view({'put': 'update'})(request, pk=coregroup.pk) assert response.status_code == 400
def test_coregroup_create(self, request_factory, org_admin): data = { 'name': 'New Group', 'permissions': { 'create': True, 'read': False, 'update': False, 'delete': True } } request = request_factory.post(reverse('coregroup-list'), data, format='json') request.user = org_admin response = CoreGroupViewSet.as_view({'post': 'create'})(request) assert response.status_code == 201 coregroup = wfm.CoreGroup.objects.get(name='New Group') assert coregroup.permissions == 9 assert coregroup.organization == org_admin.organization
def test_coregroup_views_permissions_org_member(self, request_factory, org_member): request = request_factory.get(reverse('coregroup-list')) request.user = org_member response = CoreGroupViewSet.as_view({'get': 'list'})(request) assert response.status_code == 200 request = request_factory.post(reverse('coregroup-list')) request.user = org_member response = CoreGroupViewSet.as_view({'post': 'create'})(request) assert response.status_code == 403 request = request_factory.get( reverse('coregroup-detail', args=(1000, ))) request.user = org_member response = CoreGroupViewSet.as_view({'get': 'retrieve'})(request, pk=1000) assert response.status_code == 404 # it's allowed but doesn't exist request = request_factory.put( reverse('coregroup-detail', args=(1000, ))) request.user = org_member response = CoreGroupViewSet.as_view({'put': 'update'})(request, pk=1000) assert response.status_code == 404 # it's allowed but wf1 is from different org request = request_factory.patch( reverse('coregroup-detail', args=(1000, ))) request.user = org_member response = CoreGroupViewSet.as_view({'patch': 'partial_update'})(request, pk=1000) assert response.status_code == 404 # it's allowed but wf1 is from different org request = request_factory.delete( reverse('coregroup-detail', args=(1000, ))) request.user = org_member response = CoreGroupViewSet.as_view({'delete': 'destroy'})(request, pk=1000) assert response.status_code == 404 # first checks if exists, then checks object permissions
def test_coregroup_create_fail_empty(self, request_factory, org_admin): request = request_factory.post(reverse('coregroup-list'), {}, format='json') request.user = org_admin response = CoreGroupViewSet.as_view({'post': 'create'})(request) assert response.status_code == 400