fixes #5542 fix(nimbus): Allow .0001 population_percent to be valid in ReadyForReview serializer (#5945)

Because:
* 0.0001 is a valid value that users can save, but the "Ready for review" validation errors show this to be an error

This commit:
* Adds a custom population_percent validation method to check for a min value rather than rely on min_value
This commit is contained in:
Lauren Zugai 2021-07-14 10:02:52 -05:00 коммит произвёл GitHub
Родитель 0f50ef4bba
Коммит 96bdeed3f1
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 22 добавлений и 1 удалений

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

@ -560,7 +560,12 @@ class NimbusReadyForReviewSerializer(serializers.ModelSerializer):
proposed_duration = serializers.IntegerField(required=True, min_value=1)
proposed_enrollment = serializers.IntegerField(required=True, min_value=1)
population_percent = serializers.DecimalField(
7, 4, min_value=0.0001, max_value=100.0, required=True
7,
4,
min_value=0.00009,
max_value=100.0,
required=True,
error_messages={"min_value": NimbusConstants.ERROR_POPULATION_PERCENT_MIN},
)
total_enrolled_clients = serializers.IntegerField(required=True, min_value=1)
firefox_min_version = serializers.ChoiceField(

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

@ -418,6 +418,7 @@ Optional - We believe this outcome will <describe impact> on <core metric>
ERROR_REQUIRED_FEATURE_CONFIG = (
"You must select a feature configuration from the drop down."
)
ERROR_POPULATION_PERCENT_MIN = "Ensure this value is greater than or equal to 0.0001."
# Analysis can be computed starting the week after enrollment
# completion for "week 1" of the experiment. However, an extra

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

@ -1608,6 +1608,21 @@ class TestNimbusReadyForReviewSerializer(TestCase):
"Ensure this value is greater than or equal to 0.0001.",
)
def test_valid_experiment_minimum_population_percent(self):
experiment = NimbusExperimentFactory.create_with_lifecycle(
NimbusExperimentFactory.Lifecycles.CREATED,
population_percent=0.0001,
)
serializer = NimbusReadyForReviewSerializer(
experiment,
data=NimbusReadyForReviewSerializer(
experiment,
context={"user": self.user},
).data,
context={"user": self.user},
)
self.assertTrue(serializer.is_valid())
def test_invalid_experiment_treatment_branch_requires_description(self):
experiment = NimbusExperimentFactory.create_with_lifecycle(
NimbusExperimentFactory.Lifecycles.CREATED,