Skip to content

Commit

Permalink
[minor]
Browse files Browse the repository at this point in the history
  • Loading branch information
gagantrivedi committed Jul 20, 2023
1 parent bc0d997 commit 8c7d571
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
10 changes: 6 additions & 4 deletions api/features/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def to_internal_value(self, data):
data["initial_value"] = str(data["initial_value"])
return super(ListCreateFeatureSerializer, self).to_internal_value(data)

def create(self, validated_data):
def create(self, validated_data: dict) -> Feature:
project = self.context["project"]
self.validate_project_features_limit(project)

Expand All @@ -137,7 +137,9 @@ def create(self, validated_data):
def validate_project_features_limit(self, project: Project) -> None:
if project.features.count() >= settings.MAX_FEATURES_ALLOWED:
raise serializers.ValidationError(
{"project": "The Project has reached the maximum allowed features."}
{
"project": "The Project has reached the maximum allowed features limit."
}
)

def validate_multivariate_options(self, multivariate_options):
Expand Down Expand Up @@ -440,7 +442,7 @@ def _get_save_kwargs(self, field_name):
kwargs["environment"] = self.context.get("environment")
return kwargs

def create(self, validated_data):
def create(self, validated_data: dict) -> FeatureState:
environment = validated_data["environment"]
self.validate_environment_segment_override_limit(environment)
return super().create(validated_data)
Expand All @@ -454,6 +456,6 @@ def validate_environment_segment_override_limit(
):
raise serializers.ValidationError(
{
"environment": "The environment has reached the maximum allowed segments overrides."
"environment": "The environment has reached the maximum allowed segments overrides limit."
}
)
1 change: 1 addition & 0 deletions api/features/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,7 @@ def create_segment_override(
):
environment = get_object_or_404(Environment, api_key=environment_api_key)
feature = get_object_or_404(Feature, project=environment.project, pk=feature_pk)

serializer = CreateSegmentOverrideFeatureStateSerializer(
data=request.data, context={"environment": environment, "feature": feature}
)
Expand Down
4 changes: 3 additions & 1 deletion api/segments/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ def create(self, validated_data):
def validate_project_segment_limit(self, project: Project) -> None:
if project.segments.count() >= settings.MAX_SEGMENTS_ALLOWED:
raise ValidationError(
{"project": "The project has reached the maximum allowed segments."}
{
"project": "The project has reached the maximum allowed segments limit."
}
)

def update(self, instance, validated_data):
Expand Down
4 changes: 2 additions & 2 deletions api/tests/unit/features/test_unit_features_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ def test_create_segment_override_reaching_max_limit(
assert response.status_code == status.HTTP_400_BAD_REQUEST
assert (
response.json()["environment"]
== "The environment has reached the maximum allowed segments overrides."
== "The environment has reached the maximum allowed segments overrides limit."
)
assert environment.feature_segments.count() == 1

Expand All @@ -834,5 +834,5 @@ def test_create_feature_reaching_max_limit(client, project, settings):
assert response.status_code == status.HTTP_400_BAD_REQUEST
assert (
response.json()["project"]
== "The Project has reached the maximum allowed features."
== "The Project has reached the maximum allowed features limit."
)
3 changes: 2 additions & 1 deletion api/tests/unit/segments/test_unit_segments_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ def test_create_segments_reaching_max_limit(project, client, settings):
res = client.post(url, data=json.dumps(data), content_type="application/json")
assert res.status_code == status.HTTP_400_BAD_REQUEST
assert (
res.json()["project"] == "The project has reached the maximum allowed segments."
res.json()["project"]
== "The project has reached the maximum allowed segments limit."
)
assert project.segments.count() == 1

Expand Down

0 comments on commit 8c7d571

Please sign in to comment.