Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Arkindex
Backend
Commits
894e8e5b
Commit
894e8e5b
authored
1 year ago
by
Erwan Rouchet
Committed by
Bastien Abadie
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Update tests and documentation for RetrieveAgentActions
parent
cdfc85a6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!2049
Update tests and documentation for RetrieveAgentActions
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex/ponos/api.py
+2
-0
2 additions, 0 deletions
arkindex/ponos/api.py
arkindex/ponos/tests/test_api.py
+25
-16
25 additions, 16 deletions
arkindex/ponos/tests/test_api.py
with
27 additions
and
16 deletions
arkindex/ponos/api.py
+
2
−
0
View file @
894e8e5b
...
...
@@ -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
,)
...
...
This diff is collapsed.
Click to expand it.
arkindex/ponos/tests/test_api.py
+
25
−
16
View file @
894e8e5b
...
...
@@ -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
(),
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment