Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
stolpeo committed Dec 5, 2024
1 parent 8fcf583 commit 8301918
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 2 deletions.
74 changes: 72 additions & 2 deletions adminsec/tests/test_views_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ class ApiTestCase(TestCase):
def setUp(self):
super().setUp()
# Create usersec.models records.
self.hpcuser_user = HpcUserFactory()
self.hpcuser_group = HpcGroupFactory()
self.hpcuser_project = HpcProjectFactory()
self.hpcuser_user = HpcUserFactory(primary_group=self.hpcuser_group)
self.hpcuser_project = HpcProjectFactory(group=self.hpcuser_group)
# Create Django users.
self.user_user = self.make_user("user")
self.user_staff = self.make_user("staff")
Expand All @@ -52,6 +52,7 @@ def setUp(self):
)
# Create HpcProjectCreateRequest.
self.hpcprojectcreaterequest = HpcProjectCreateRequestFactory(
group=self.hpcuser_group,
requester=self.user_user,
status=REQUEST_STATUS_ACTIVE,
)
Expand Down Expand Up @@ -625,3 +626,72 @@ def test_delete_fail(self):
self.response_405()
else:
self.response_403()


class TestHpcAccessStatusApiView(ApiTestCase):
"""Tests for the HpcAccessStatusApiView."""

def test_get_succeed(self):
"""Test the GET method (staff users can do)."""

self.maxDiff = None

expected = {
"hpc_users": [
{
"uid": self.hpcuser_user.user.uid,
"email": self.hpcuser_user.user.email,
"full_name": "User Name",
"first_name": self.hpcuser_user.user.first_name,
"last_name": self.hpcuser_user.user.last_name,
"phone_number": None,
"primary_group": self.hpcuser_group.name,
"resources_requested": self.hpcuser_user.resources_requested,
"status": "INITIAL",
"description": self.hpcuser_user.description,
"username": self.hpcuser_user.username,
"expiration": self.hpcuser_user.expiration.strftime("%Y-%m-%dT%H:%M:%SZ"),
"home_directory": self.hpcuser_user.home_directory,
"login_shell": self.hpcuser_user.login_shell,
}
],
"hpc_groups": [
{
"owner": None,
"delegate": None,
"resources_requested": self.hpcuser_group.resources_requested,
"status": "INITIAL",
"description": self.hpcuser_group.description,
"name": self.hpcuser_group.name,
"folders": self.hpcuser_group.folders,
"expiration": self.hpcuser_group.expiration.strftime("%Y-%m-%dT%H:%M:%SZ"),
"gid": self.hpcuser_group.gid,
}
],
"hpc_projects": [
{
"gid": self.hpcuser_project.gid,
"group": self.hpcuser_group.name,
"delegate": None,
"resources_requested": self.hpcuser_project.resources_requested,
"status": "INITIAL",
"description": self.hpcuser_project.description,
"name": self.hpcuser_project.name,
"folders": self.hpcuser_project.folders,
"expiration": self.hpcuser_project.expiration.strftime("%Y-%m-%dT%H:%M:%SZ"),
"members": [],
}
],
}
for user in [self.user_staff, self.user_admin, self.user_hpcadmin]:
with self.login(user):
self.get("adminsec:api-hpcaccess-status")
self.response_200()
self.assertEqual(self.last_response.json(), expected)

def test_get_fail(self):
"""Test the GET method (non-staff cannot do)."""
for user in [self.user_user]:
with self.login(user):
self.get("adminsec:api-hpcaccess-status")
self.response_403()
1 change: 1 addition & 0 deletions adminsec/views_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ class HpcAccessStatusApiView(RetrieveAPIView):
"""API view for listing all users."""

serializer_class = HpcAccessStatusSerializer
permission_classes = [IsAdminUser | IsHpcAdminUser]

def get_object(self):
"""Return the object to be used in the view."""
Expand Down

0 comments on commit 8301918

Please sign in to comment.