Commit 87f14b72 authored by André Anjos's avatar André Anjos 💬

Merge branch '527_implement_experiment_reset_api' into 'master'

Implement experiment reset api

Closes #537

See merge request !306
parents f838466e 3102f73c
Pipeline #33168 passed with stages
in 23 minutes and 32 seconds
This diff is collapsed.
......@@ -30,83 +30,76 @@ from . import api
urlpatterns = [
url(
r'^$',
api.ListExperimentsView.as_view(),
name='all'
),
url(r"^$", api.ListExperimentsView.as_view(), name="all"),
# Sharing
url(
r'^(?P<author_name>\w+)/(?P<toolchain_author_name>\w+)/(?P<toolchain_name>[-\w]+)/(?P<version>\d+)/(?P<name>[-\w]+)/share/$',
r"^(?P<author_name>\w+)/(?P<toolchain_author_name>\w+)/(?P<toolchain_name>[-\w]+)/(?P<version>\d+)/(?P<name>[-\w]+)/share/$",
api.ShareExperimentView.as_view(),
name='share'
name="share",
),
url(
r'^(?P<author_name>\w+)/(?P<toolchain_name>[-\w]+)/(?P<version>\d+)/(?P<name>[-\w]+)/share/$',
r"^(?P<author_name>\w+)/(?P<toolchain_name>[-\w]+)/(?P<version>\d+)/(?P<name>[-\w]+)/share/$",
api.ShareExperimentView.as_view(),
{ 'toolchain_author_name': None },
name='share'
{"toolchain_author_name": None},
name="share",
),
# Start
url(
r'^(?P<author_name>\w+)/(?P<toolchain_author_name>\w+)/(?P<toolchain_name>[-\w]+)/(?P<version>\d+)/(?P<name>[-\w]+)/start/$',
r"^(?P<author_name>\w+)/(?P<toolchain_author_name>\w+)/(?P<toolchain_name>[-\w]+)/(?P<version>\d+)/(?P<name>[-\w]+)/start/$",
api.StartExperimentView.as_view(),
name='start'
name="start",
),
url(
r'^(?P<author_name>\w+)/(?P<toolchain_name>[-\w]+)/(?P<version>\d+)/(?P<name>[-\w]+)/start/$',
r"^(?P<author_name>\w+)/(?P<toolchain_name>[-\w]+)/(?P<version>\d+)/(?P<name>[-\w]+)/start/$",
api.StartExperimentView.as_view(),
{ 'toolchain_author_name': None },
name='start'
{"toolchain_author_name": None},
name="start",
),
# Cancelling
url(
r'^(?P<author_name>\w+)/(?P<toolchain_author_name>\w+)/(?P<toolchain_name>[-\w]+)/(?P<version>\d+)/(?P<name>[-\w]+)/cancel/$',
r"^(?P<author_name>\w+)/(?P<toolchain_author_name>\w+)/(?P<toolchain_name>[-\w]+)/(?P<version>\d+)/(?P<name>[-\w]+)/cancel/$",
api.CancelExperimentView.as_view(),
name='cancel'
name="cancel",
),
url(
r'^(?P<author_name>\w+)/(?P<toolchain_name>[-\w]+)/(?P<version>\d+)/(?P<name>[-\w]+)/cancel/$',
r"^(?P<author_name>\w+)/(?P<toolchain_name>[-\w]+)/(?P<version>\d+)/(?P<name>[-\w]+)/cancel/$",
api.CancelExperimentView.as_view(),
{ 'toolchain_author_name': None },
name='cancel'
{"toolchain_author_name": None},
name="cancel",
),
# Reseting
url(
r"^(?P<author_name>\w+)/(?P<toolchain_author_name>\w+)/(?P<toolchain_name>[-\w]+)/(?P<version>\d+)/(?P<name>[-\w]+)/reset/$",
api.ResetExperimentView.as_view(),
name="reset",
),
url(
r"^(?P<author_name>\w+)/(?P<toolchain_name>[-\w]+)/(?P<version>\d+)/(?P<name>[-\w]+)/reset/$",
api.ResetExperimentView.as_view(),
{"toolchain_author_name": None},
name="reset",
),
# Attestations
url(
r'^(?P<attestation_number>\d+)/',
r"^(?P<attestation_number>\d+)/",
api.RetrieveExperimentResultsFromAttestationView.as_view(),
name='attestations'
name="attestations",
),
# Experiments
url(
r'^(?P<author_name>\w+)/$',
r"^(?P<author_name>\w+)/$",
api.ListCreateExperimentsView.as_view(),
name='list_create'
name="list_create",
),
url(
r'^(?P<author_name>\w+)/(?P<toolchain_author_name>\w+)/(?P<toolchain_name>[-\w]+)/(?P<version>\d+)/(?P<name>[-\w]+)/$',
r"^(?P<author_name>\w+)/(?P<toolchain_author_name>\w+)/(?P<toolchain_name>[-\w]+)/(?P<version>\d+)/(?P<name>[-\w]+)/$",
api.RetrieveUpdateDestroyExperimentView.as_view(),
name='object'
name="object",
),
url(
r'^(?P<author_name>\w+)/(?P<toolchain_name>[-\w]+)/(?P<version>\d+)/(?P<name>[-\w]+)/$',
r"^(?P<author_name>\w+)/(?P<toolchain_name>[-\w]+)/(?P<version>\d+)/(?P<name>[-\w]+)/$",
api.RetrieveUpdateDestroyExperimentView.as_view(),
{ 'toolchain_author_name': None },
name='object'
{"toolchain_author_name": None},
name="object",
),
]
......@@ -35,28 +35,28 @@ from django.conf import settings
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from ..dataformats.models import DataFormat
from ..algorithms.models import Algorithm
from ..toolchains.models import Toolchain
from ..team.models import Team
from ...dataformats.models import DataFormat
from ...algorithms.models import Algorithm
from ...toolchains.models import Toolchain
from ...team.models import Team
from ..backend.models import Environment
from ..backend.models import Queue
from ...backend.models import Environment
from ...backend.models import Queue
from ..attestations.models import Attestation
from ..databases.models import Database
from ...attestations.models import Attestation
from ...databases.models import Database
from ..common.testutils import BaseTestCase
from ..common.testutils import ( # noqa test runner will call it, tearDownModule
from ...common.testutils import BaseTestCase
from ...common.testutils import ( # noqa test runner will call it, tearDownModule
tearDownModule,
)
from .models import Experiment
from .models import CachedFile
from .models import Block
from .models import Result
from ..models import Experiment
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()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment