Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
beat.web
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
54
Issues
54
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
beat
beat.web
Commits
57b98b86
Commit
57b98b86
authored
Sep 09, 2019
by
Samuel GAIST
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[experiments][api] Implement experiment reset end point
parent
589a77ce
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
98 additions
and
2 deletions
+98
-2
beat/web/experiments/api.py
beat/web/experiments/api.py
+35
-1
beat/web/experiments/tests.py
beat/web/experiments/tests.py
+63
-1
No files found.
beat/web/experiments/api.py
View file @
57b98b86
...
...
@@ -42,7 +42,7 @@ from rest_framework import generics
from
rest_framework
import
serializers
from
rest_framework.views
import
APIView
from
rest_framework.reverse
import
reverse
from
rest_framework.e
rror
s
import
ParseError
from
rest_framework.e
xception
s
import
ParseError
import
beat.core.hash
import
beat.core.algorithm
...
...
@@ -681,6 +681,40 @@ class CancelExperimentView(APIView):
# ----------------------------------------------------------
class ResetExperimentView(APIView):
"""
Reset an experiment
"""
permission_classes = [permissions.IsAuthenticated]
def post(
self, request, author_name, toolchain_author_name, toolchain_name, version, name
):
if toolchain_author_name is None:
toolchain_author_name = author_name
# Retrieve the experiment
experiment = get_object_or_404(
Experiment,
author__username=author_name,
toolchain__author__username=toolchain_author_name,
toolchain__name=toolchain_name,
toolchain__version=version,
name=name,
)
self.check_object_permissions(request, experiment)
experiment.reset()
return Response(status=200)
# ----------------------------------------------------------
class RetrieveExperimentResultsFromAttestationView(
CommonContextMixin, generics.RetrieveAPIView
):
...
...
beat/web/experiments/tests.py
View file @
57b98b86
...
...
@@ -56,7 +56,7 @@ from .models import CachedFile
from
.models
import
Block
from
.models
import
Result
TEST_PWD
=
"1234"
TEST_PWD
=
"1234"
# nosec
HASHES
=
{
"addition1"
:
"ff59a471cec5c17b45d1dfa5aff3ed897ee2d7ed87de205365b372be1c726c87"
,
...
...
@@ -1095,6 +1095,68 @@ class ExperimentStartingAPI(ExperimentTestBase):
# ----------------------------------------------------------
class
ExperimentResetingAPI
(
ExperimentTestBase
):
def
setUp
(
self
):
super
(
ExperimentResetingAPI
,
self
).
setUp
()
self
.
login_johndoe
()
url
=
reverse
(
"api_experiments:list_create"
,
args
=
[
"johndoe"
])
response
=
self
.
client
.
post
(
url
,
json
.
dumps
(
{
"toolchain"
:
"johndoe/toolchain1/1"
,
"declaration"
:
ExperimentTestBase
.
DECLARATION1
,
"name"
:
"pending"
,
}
),
content_type
=
"application/json"
,
)
self
.
checkResponse
(
response
,
201
,
content_type
=
"application/json"
)
self
.
client
.
logout
()
self
.
url
=
reverse
(
"api_experiments:reset"
,
args
=
[
"johndoe"
,
"johndoe"
,
"toolchain1"
,
1
,
"pending"
],
)
def
test_no_access_for_anonymous_user
(
self
):
response
=
self
.
client
.
post
(
self
.
url
)
self
.
checkResponse
(
response
,
403
)
def
test_no_access_for_other_user
(
self
):
self
.
login_jackdoe
()
response
=
self
.
client
.
post
(
self
.
url
)
self
.
checkResponse
(
response
,
403
)
def
test_reset_experiment
(
self
):
self
.
login_johndoe
()
experiments
=
Experiment
.
objects
.
all
()
self
.
assertEqual
(
experiments
.
count
(),
1
)
experiment
=
experiments
[
0
]
experiment
.
status
=
Experiment
.
DONE
experiment
.
start_date
=
datetime
.
now
()
experiment
.
end_date
=
datetime
.
now
()
experiment
.
save
()
response
=
self
.
client
.
post
(
self
.
url
)
self
.
checkResponse
(
response
,
200
)
experiment
.
refresh_from_db
()
self
.
assertTrue
(
experiment
.
creation_date
is
not
None
)
self
.
assertTrue
(
experiment
.
start_date
is
None
)
self
.
assertTrue
(
experiment
.
end_date
is
None
)
self
.
assertEqual
(
experiment
.
status
,
Experiment
.
PENDING
)
# ----------------------------------------------------------
class
ResultsAPI
(
ExperimentTestBase
):
def
setUp
(
self
):
super
(
ResultsAPI
,
self
).
setUp
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment