Skip to content

Commit

Permalink
fix(sentry-FLAGSMITH-API-4FZ): fix PATCH for segments
Browse files Browse the repository at this point in the history
  • Loading branch information
gagantrivedi committed May 27, 2024
1 parent c896c50 commit 13d44fd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
4 changes: 3 additions & 1 deletion api/segments/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ def validate(self, attrs):
return attrs

def get_project(self, validated_data: dict = None) -> Project:
return validated_data.get("project")
return validated_data.get("project") or Project.objects.get(
id=self.context["view"].kwargs["project_pk"]
)

def create(self, validated_data):
project = validated_data["project"]
Expand Down
23 changes: 23 additions & 0 deletions api/tests/unit/segments/test_unit_segments_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,29 @@ def test_audit_log_created_when_segment_updated(project, segment, client):
)


@pytest.mark.parametrize(
"client",
[lazy_fixture("admin_master_api_key_client"), lazy_fixture("admin_client")],
)
def test_can_patch_segment(project, segment, client):
# Given
segment = Segment.objects.create(name="Test segment", project=project)
url = reverse(
"api-v1:projects:project-segments-detail",
args=[project.id, segment.id],
)
data = {
"name": "New segment name",
"rules": [{"type": "ALL", "rules": [], "conditions": []}],
}

# When
res = client.patch(url, data=json.dumps(data), content_type="application/json")

# Then
assert res.status_code == status.HTTP_200_OK


@pytest.mark.parametrize(
"client",
[lazy_fixture("admin_master_api_key_client"), lazy_fixture("admin_client")],
Expand Down

0 comments on commit 13d44fd

Please sign in to comment.