Skip to content

Commit

Permalink
fix: cannot create new segments due to segment validation (#4886)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewelwell authored Dec 4, 2024
1 parent 4e1abda commit 05ab7cf
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 32 deletions.
39 changes: 9 additions & 30 deletions api/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ hubspot-api-client = "^8.2.1"
djangorestframework-dataclasses = "^1.3.1"
pyotp = "^2.9.0"
flagsmith-task-processor = { git = "https://github.com/Flagsmith/flagsmith-task-processor", tag = "v1.0.2" }
flagsmith-common = { git = "https://github.com/Flagsmith/flagsmith-common", tag = "v1.4.0" }
flagsmith-common = { git = "https://github.com/Flagsmith/flagsmith-common", tag = "v1.4.2" }
tzdata = "^2024.1"
djangorestframework-simplejwt = "^5.3.1"

Expand All @@ -196,7 +196,7 @@ flagsmith-ldap = { git = "https://github.com/flagsmith/flagsmith-ldap", tag = "v
optional = true

[tool.poetry.group.workflows.dependencies]
workflows-logic = { git = "https://github.com/flagsmith/flagsmith-workflows", tag = "v2.7.2" }
workflows-logic = { git = "https://github.com/flagsmith/flagsmith-workflows", tag = "v2.7.4" }

[tool.poetry.group.dev.dependencies]
django-test-migrations = "~1.2.0"
Expand Down
38 changes: 38 additions & 0 deletions api/tests/unit/segments/test_unit_segments_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,44 @@ def test_create_segments_reaching_max_limit(project, client, settings):
assert project.segments.count() == 1


def test_segments_limit_ignores_old_segment_versions(
project: Project,
segment: Segment,
staff_client: APIClient,
with_project_permissions: WithProjectPermissionsCallable,
) -> None:
# Given
with_project_permissions([MANAGE_SEGMENTS])

# let's reduce the max segments allowed to 2
project.max_segments_allowed = 2
project.save()

# and create some older versions for the segment fixture
segment.deep_clone()
assert Segment.objects.filter(version_of_id=segment.id).count() == 3
assert Segment.live_objects.count() == 1

url = reverse("api-v1:projects:project-segments-list", args=[project.id])
data = {
"name": "New segment name",
"project": project.id,
"rules": [
{
"type": "ALL",
"rules": [],
"conditions": [{"operator": EQUAL, "property": "test-property"}],
}
],
}

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

# Then
assert res.status_code == status.HTTP_201_CREATED


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

0 comments on commit 05ab7cf

Please sign in to comment.