Make Experiment status validation optional fixes #248

This commit is contained in:
Jared Kerim 2017-11-20 16:52:41 -05:00 коммит произвёл Jared Kerim
Родитель 9cb3e72abd
Коммит 33e880e16c
2 изменённых файлов: 21 добавлений и 6 удалений

Просмотреть файл

@ -132,11 +132,12 @@ class Experiment(models.Model):
).format(
old_status=old_status, new_status=new_status)})
def clean(self):
self.clean_status()
def clean(self, validate=False):
if validate:
self.clean_status()
def save(self, *args, **kwargs):
self.clean()
def save(self, validate=False, *args, **kwargs):
self.clean(validate=validate)
return super().save(*args, **kwargs)
@property

Просмотреть файл

@ -1,6 +1,7 @@
from django.core.exceptions import ValidationError
from django.test import TestCase
from experimenter.projects.tests.factories import ProjectFactory
from experimenter.experiments.models import (
Experiment, ExperimentVariant)
from experimenter.experiments.tests.factories import (
@ -48,12 +49,25 @@ class TestExperimentModel(TestCase):
experiment.status = experiment.STATUS_PENDING
experiment.save()
def test_experiment_change_status_to_unexpected_status_raises(self):
def test_experiment_status_validation_raises_if_enabled(self):
experiment = ExperimentFactory.create_with_variants()
experiment.status = experiment.STATUS_ACCEPTED
with self.assertRaises(ValidationError):
experiment.save()
experiment.save(validate=True)
def test_experiment_status_validation_should_not_raise_if_disabled(self):
experiment = ExperimentFactory.create_with_variants()
experiment.status = experiment.STATUS_ACCEPTED
experiment.save()
def test_experiment_status_validation_should_not_raise_for_new_exp(self):
project = ProjectFactory.create()
experiment = ExperimentFactory.build(project=project)
experiment.status = experiment.STATUS_ACCEPTED
experiment.save(validate=True)
def test_experiment_with_created_status_is_not_readonly(self):
experiment = ExperimentFactory.create_with_variants()