def test_add_user(self, api_client): user = UserFactory() group = GroupFactory() res = api_client.post(f"/api/v3/group/{group.id}/add_user/", {"user_id": user.id}) assert res.status_code == 204 assert user.groups.filter(pk=group.pk).count() == 1
def test_it_works(self, api_client): group = GroupFactory() res = api_client.get("/api/v3/group/") assert res.status_code == 200 assert res.data == { "count": 1, "next": None, "previous": None, "results": [{"id": group.id, "name": group.name}], }
def test_groups_in_read_only_mode(self, api_client, settings): settings.ADMIN_ENABLED = False res = api_client.get("/api/v3/group/") assert res.status_code == 403 assert res.data["detail"] == AdminEnabled.message res = api_client.post("/api/v3/group/", {"name": "Test"}) assert res.status_code == 403 assert res.data["detail"] == AdminEnabled.message assert not Group.objects.all().exists() g = GroupFactory(name="abc") res = api_client.put(f"/api/v3/group/{g.id}/", {"name": "def"}) assert res.status_code == 403 assert res.data["detail"] == AdminEnabled.message
def test_it_works(self, api_client): user = User.objects.first() group = GroupFactory() user.groups.add(group) res = api_client.get("/api/v3/user/") assert res.status_code == 200 assert res.data == { "count": 1, "next": None, "previous": None, "results": [ { "id": user.id, "first_name": user.first_name, "last_name": user.last_name, "email": user.email, "groups": [{"id": group.id, "name": group.name}], } ], }
def test_remove_user_not_in_group(self, api_client): user = UserFactory() group = GroupFactory() res = api_client.post(f"/api/v3/group/{group.id}/remove_user/", {"user_id": user.id}) assert res.status_code == 400
def test_remove_user_bad_user_id(self, api_client): group = GroupFactory() res = api_client.post(f"/api/v3/group/{group.id}/remove_user/", {"user_id": 9999}) assert res.status_code == 400
def test_add_user_cannot_add_self(self, api_client): user = User.objects.first() group = GroupFactory() res = api_client.post(f"/api/v3/group/{group.id}/add_user/", {"user_id": user.id}) assert res.status_code == 403
def test_add_user_no_user_id(self, api_client): group = GroupFactory() res = api_client.post(f"/api/v3/group/{group.id}/add_user/") assert res.status_code == 400
def test_delete_group(self, api_client): g = GroupFactory() res = api_client.delete(f"/api/v3/group/{g.id}/") assert res.status_code == 204 assert Group.objects.all().count() == 0
def test_update_group(self, api_client): g = GroupFactory(name="abc") res = api_client.put(f"/api/v3/group/{g.id}/", {"name": "def"}) assert res.status_code == 200 g.refresh_from_db() assert g.name == "def"
def test_resolve_group_by_name(self, gql_client): g = GroupFactory() res = gql_client.execute(GQ().query.group(name=g.name).fields("id")) assert res == {"data": {"group": {"id": str(g.id)}}}
def test_resolve_group_by_id(self, gql_client): g = GroupFactory() res = gql_client.execute(GQ().query.group(id=g.id).fields("name")) assert res == {"data": {"group": {"name": g.name}}}
def test_resolve_all_groups(self, gql_client): g = GroupFactory() res = gql_client.execute(GQ().query.allGroups.fields("id")) assert res == {"data": {"allGroups": [{"id": str(g.id)}]}}
def test_update_group(self, api_client): g = GroupFactory(name="abc") res = api_client.put(f"/api/v3/group/{g.id}/", {"name": "def"}) assert res.status_code == 200 g.refresh_from_db() assert g.name == "def"