|
62 | 62 | from projects.tags.models import Tag |
63 | 63 | from segments.models import Segment |
64 | 64 | from tests.types import ( |
| 65 | + EnableFeaturesFixture, |
65 | 66 | WithEnvironmentPermissionsCallable, |
66 | 67 | WithProjectPermissionsCallable, |
67 | 68 | ) |
@@ -3593,14 +3594,15 @@ def test_list_features__value_search_boolean__returns_matching( |
3593 | 3594 |
|
3594 | 3595 |
|
3595 | 3596 | def test_list_features__with_code_references__returns_counts( |
3596 | | - staff_client: APIClient, |
3597 | | - project: Project, |
| 3597 | + enable_features: EnableFeaturesFixture, |
3598 | 3598 | feature: Feature, |
| 3599 | + project: Project, |
| 3600 | + staff_client: APIClient, |
3599 | 3601 | with_project_permissions: WithProjectPermissionsCallable, |
3600 | | - environment: Environment, |
3601 | 3602 | ) -> None: |
3602 | 3603 | # Given |
3603 | 3604 | with_project_permissions([VIEW_PROJECT]) # type: ignore[call-arg] |
| 3605 | + enable_features("code_references_ui_stats") |
3604 | 3606 | with freeze_time("2099-01-01T10:00:00-0300"): |
3605 | 3607 | FeatureFlagCodeReferencesScan.objects.create( |
3606 | 3608 | project=project, |
@@ -3678,26 +3680,64 @@ def test_list_features__with_code_references__returns_counts( |
3678 | 3680 | ] |
3679 | 3681 |
|
3680 | 3682 |
|
3681 | | -def test_FeatureViewSet_list__no_scans__returns_empty_code_references_counts( |
3682 | | - staff_client: APIClient, |
| 3683 | +@pytest.mark.usefixtures("feature") |
| 3684 | +def test_list_features__without_code_references__returns_empty_counts( |
| 3685 | + enable_features: EnableFeaturesFixture, |
| 3686 | + environment: Environment, |
3683 | 3687 | project: Project, |
3684 | | - feature: Feature, |
| 3688 | + staff_client: APIClient, |
| 3689 | + with_project_permissions: WithProjectPermissionsCallable, |
| 3690 | +) -> None: |
| 3691 | + # Given |
| 3692 | + with_project_permissions([VIEW_PROJECT]) # type: ignore[call-arg] |
| 3693 | + enable_features("code_references_ui_stats") |
| 3694 | + |
| 3695 | + # When |
| 3696 | + response = staff_client.get( |
| 3697 | + f"/api/v1/projects/{project.id}/features/?environment={environment.id}" |
| 3698 | + ) |
| 3699 | + |
| 3700 | + # Then |
| 3701 | + assert response.status_code == 200 |
| 3702 | + results = response.json()["results"] |
| 3703 | + assert len(results) == 1 |
| 3704 | + assert results[0]["code_references_counts"] == [] |
| 3705 | + |
| 3706 | + |
| 3707 | +# TODO: Delete this after https://github.com/flagsmith/flagsmith/issues/6832 is resolved |
| 3708 | +def test_list_features__code_references_ui_stats_disabled__returns_empty_counts( |
| 3709 | + enable_features: EnableFeaturesFixture, |
3685 | 3710 | environment: Environment, |
| 3711 | + feature: Feature, |
| 3712 | + project: Project, |
| 3713 | + staff_client: APIClient, |
3686 | 3714 | with_project_permissions: WithProjectPermissionsCallable, |
3687 | 3715 | ) -> None: |
3688 | | - # Given - project has no code reference scans |
| 3716 | + # Given |
3689 | 3717 | with_project_permissions([VIEW_PROJECT]) # type: ignore[call-arg] |
| 3718 | + enable_features() # code_references_ui_stats not enabled |
| 3719 | + FeatureFlagCodeReferencesScan.objects.create( |
| 3720 | + project=project, |
| 3721 | + repository_url="https://github.flagsmith.com/backend/", |
| 3722 | + revision="rev-1", |
| 3723 | + code_references=[ |
| 3724 | + { |
| 3725 | + "feature_name": feature.name, |
| 3726 | + "file_path": "path/to/file.py", |
| 3727 | + "line_number": 42, |
| 3728 | + }, |
| 3729 | + ], |
| 3730 | + ) |
3690 | 3731 |
|
3691 | 3732 | # When |
3692 | 3733 | response = staff_client.get( |
3693 | 3734 | f"/api/v1/projects/{project.id}/features/?environment={environment.id}" |
3694 | 3735 | ) |
3695 | 3736 |
|
3696 | | - # Then - response should include code_references_counts as empty list |
| 3737 | + # Then |
3697 | 3738 | assert response.status_code == 200 |
3698 | 3739 | results = response.json()["results"] |
3699 | 3740 | assert len(results) == 1 |
3700 | | - assert "code_references_counts" in results[0] |
3701 | 3741 | assert results[0]["code_references_counts"] == [] |
3702 | 3742 |
|
3703 | 3743 |
|
|
0 commit comments