Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sentry-FLAGSMITH-API-4FZ): fix PATCH for segments #4029

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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