Include invalid/rejected experiments in serialization fixes #142
This commit is contained in:
Родитель
94b4e44a8c
Коммит
e1451ddd32
|
@ -8,8 +8,8 @@ from django.db import models
|
|||
class ExperimentManager(models.Manager):
|
||||
|
||||
def started(self):
|
||||
return self.get_queryset().filter(status__in=(
|
||||
Experiment.EXPERIMENT_STARTED, Experiment.EXPERIMENT_COMPLETE))
|
||||
return self.get_queryset().exclude(
|
||||
status=Experiment.EXPERIMENT_NOT_STARTED)
|
||||
|
||||
|
||||
class Experiment(models.Model):
|
||||
|
@ -93,10 +93,7 @@ class Experiment(models.Model):
|
|||
):
|
||||
self.end_date = datetime.datetime.now()
|
||||
|
||||
elif (
|
||||
old_state.status == self.EXPERIMENT_NOT_STARTED and
|
||||
new_state.status == self.EXPERIMENT_REJECTED
|
||||
):
|
||||
elif new_state.status == self.EXPERIMENT_REJECTED:
|
||||
pass
|
||||
|
||||
elif new_state.status == self.EXPERIMENT_INVALID:
|
||||
|
|
|
@ -114,9 +114,8 @@ class TestExperimentModel(TestCase):
|
|||
experiment.status = experiment.EXPERIMENT_STARTED
|
||||
experiment.save()
|
||||
|
||||
with self.assertRaises(ValidationError):
|
||||
experiment.status = experiment.EXPERIMENT_REJECTED
|
||||
experiment.save()
|
||||
experiment.status = experiment.EXPERIMENT_REJECTED
|
||||
experiment.save()
|
||||
|
||||
def test_setting_status_from_complete_to_rejected(self):
|
||||
experiment = ExperimentFactory.create()
|
||||
|
@ -126,18 +125,16 @@ class TestExperimentModel(TestCase):
|
|||
experiment.status = experiment.EXPERIMENT_COMPLETE
|
||||
experiment.save()
|
||||
|
||||
with self.assertRaises(ValidationError):
|
||||
experiment.status = experiment.EXPERIMENT_REJECTED
|
||||
experiment.save()
|
||||
experiment.status = experiment.EXPERIMENT_REJECTED
|
||||
experiment.save()
|
||||
|
||||
def test_setting_status_from_invalid_to_rejected(self):
|
||||
experiment = ExperimentFactory.create()
|
||||
experiment.status = experiment.EXPERIMENT_INVALID
|
||||
experiment.save()
|
||||
|
||||
with self.assertRaises(ValidationError):
|
||||
experiment.status = experiment.EXPERIMENT_REJECTED
|
||||
experiment.save()
|
||||
experiment.status = experiment.EXPERIMENT_REJECTED
|
||||
experiment.save()
|
||||
|
||||
def test_setting_status_from_not_started_to_invalid(self):
|
||||
experiment = ExperimentFactory.create()
|
||||
|
|
|
@ -21,13 +21,6 @@ class TestExperimentListView(TestCase):
|
|||
for i in range(2):
|
||||
ExperimentFactory.create_with_variants(project=project)
|
||||
|
||||
# rejected experiments should be excluded
|
||||
for i in range(2):
|
||||
experiment = ExperimentFactory.create_with_variants(
|
||||
project=project)
|
||||
experiment.status = experiment.EXPERIMENT_REJECTED
|
||||
experiment.save()
|
||||
|
||||
# started experiments should be included
|
||||
for i in range(3):
|
||||
experiment = ExperimentFactory.create_with_variants(
|
||||
|
@ -48,6 +41,28 @@ class TestExperimentListView(TestCase):
|
|||
|
||||
started_experiments.append(experiment)
|
||||
|
||||
# invalid experiments should be included
|
||||
experiment = ExperimentFactory.create_with_variants(
|
||||
project=project)
|
||||
experiment.status = experiment.EXPERIMENT_STARTED
|
||||
experiment.save()
|
||||
|
||||
experiment.status = experiment.EXPERIMENT_INVALID
|
||||
experiment.save()
|
||||
|
||||
started_experiments.append(experiment)
|
||||
|
||||
# rejected experiments should be included
|
||||
experiment = ExperimentFactory.create_with_variants(
|
||||
project=project)
|
||||
experiment.status = experiment.EXPERIMENT_STARTED
|
||||
experiment.save()
|
||||
|
||||
experiment.status = experiment.EXPERIMENT_REJECTED
|
||||
experiment.save()
|
||||
|
||||
started_experiments.append(experiment)
|
||||
|
||||
response = self.client.get(
|
||||
reverse('experiments-list', kwargs={'project_slug': project.slug}))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
|
Загрузка…
Ссылка в новой задаче