Skip to content
Snippets Groups Projects
Commit 894e8e5b authored by Erwan Rouchet's avatar Erwan Rouchet Committed by Bastien Abadie
Browse files

Update tests and documentation for RetrieveAgentActions

parent cdfc85a6
No related branches found
No related tags found
1 merge request!2049Update tests and documentation for RetrieveAgentActions
......@@ -185,6 +185,8 @@ class AgentsState(ListAPIView):
class AgentActions(RetrieveAPIView):
"""
Fetch the next actions an agent should perform.
Requires authentication as a Ponos agent.
"""
permission_classes = (IsAgent,)
......
......@@ -1087,23 +1087,31 @@ class TestAPI(FixtureAPITestCase):
)
def test_agent_actions_requires_token(self):
resp = self.client.get(reverse("api:agent-actions"))
self.assertEqual(resp.status_code, status.HTTP_401_UNAUTHORIZED)
with self.assertNumQueries(0):
resp = self.client.get(reverse("api:agent-actions"))
self.assertEqual(resp.status_code, status.HTTP_401_UNAUTHORIZED)
def test_agent_actions_no_user(self):
self.client.force_login(self.superuser)
try:
with self.assertNumQueries(0):
resp = self.client.get(reverse("api:agent-actions"))
self.assertEqual(resp.status_code, status.HTTP_401_UNAUTHORIZED)
finally:
self.client.logout()
def test_agent_actions_no_task(self):
with self.assertNumQueries(0):
resp = self.client.get(
reverse("api:agent-actions"),
HTTP_AUTHORIZATION=f'Ponos {self.task1.token}',
)
self.assertEqual(resp.status_code, status.HTTP_401_UNAUTHORIZED)
def test_agent_actions_query_params_required(self):
resp = self.client.get(
reverse("api:agent-actions"),
HTTP_AUTHORIZATION=f'Bearer {self.agent.token.access_token}',
)
self.assertEqual(resp.status_code, status.HTTP_400_BAD_REQUEST)
with self.assertNumQueries(1):
resp = self.client.get(
reverse("api:agent-actions"),
HTTP_AUTHORIZATION=f'Bearer {self.agent.token.access_token}',
)
self.assertEqual(resp.status_code, status.HTTP_400_BAD_REQUEST)
self.assertDictEqual(
resp.json(),
{
......@@ -1113,12 +1121,13 @@ class TestAPI(FixtureAPITestCase):
)
def test_agent_actions_query_params_validation(self):
resp = self.client.get(
reverse("api:agent-actions"),
HTTP_AUTHORIZATION=f'Bearer {self.agent.token.access_token}',
data={"cpu_load": "high", "ram_load": "low"},
)
self.assertEqual(resp.status_code, status.HTTP_400_BAD_REQUEST)
with self.assertNumQueries(1):
resp = self.client.get(
reverse("api:agent-actions"),
HTTP_AUTHORIZATION=f'Bearer {self.agent.token.access_token}',
data={"cpu_load": "high", "ram_load": "low"},
)
self.assertEqual(resp.status_code, status.HTTP_400_BAD_REQUEST)
self.assertDictEqual(
resp.json(),
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment