|
1 | 1 | from typing import TYPE_CHECKING |
2 | 2 |
|
| 3 | +import pytest |
3 | 4 | from django.urls import reverse |
4 | 5 | from flag_engine.segments.constants import EQUAL |
5 | 6 | from rest_framework import status |
|
17 | 18 | FeatureStateValue, |
18 | 19 | ) |
19 | 20 | from features.multivariate.models import MultivariateFeatureOption |
| 21 | +from features.versioning.tasks import enable_v2_versioning |
20 | 22 | from projects.models import Project |
21 | 23 | from segments.models import Condition, Segment, SegmentRule |
22 | 24 |
|
|
26 | 28 | from organisations.models import Organisation |
27 | 29 |
|
28 | 30 |
|
| 31 | +@pytest.mark.parametrize( |
| 32 | + "use_v2_feature_versioning, total_queries", [(True, 16), (False, 15)] |
| 33 | +) |
29 | 34 | def test_get_environment_document( |
30 | 35 | organisation_one: "Organisation", |
31 | 36 | organisation_two: "Organisation", |
32 | 37 | organisation_one_project_one: "Project", |
33 | 38 | django_assert_num_queries: "DjangoAssertNumQueries", |
| 39 | + use_v2_feature_versioning: bool, |
| 40 | + total_queries: int, |
34 | 41 | ) -> None: |
35 | 42 | # Given |
36 | 43 | project = organisation_one_project_one |
37 | 44 | project2 = Project.objects.create( |
38 | 45 | name="standin_project", organisation=organisation_two |
39 | 46 | ) |
40 | 47 |
|
41 | | - environment = Environment.objects.create(name="Test Environment", project=project) |
| 48 | + environment = Environment.objects.create( |
| 49 | + name="Test Environment", |
| 50 | + project=project, |
| 51 | + ) |
| 52 | + if use_v2_feature_versioning: |
| 53 | + enable_v2_versioning(environment.id) |
| 54 | + |
42 | 55 | api_key = EnvironmentAPIKey.objects.create(environment=environment) |
43 | 56 | client = APIClient() |
44 | 57 | client.credentials(HTTP_X_ENVIRONMENT_KEY=api_key.key) |
@@ -126,7 +139,7 @@ def test_get_environment_document( |
126 | 139 | url = reverse("api-v1:environment-document") |
127 | 140 |
|
128 | 141 | # When |
129 | | - with django_assert_num_queries(15): |
| 142 | + with django_assert_num_queries(total_queries): |
130 | 143 | response = client.get(url) |
131 | 144 |
|
132 | 145 | # Then |
|
0 commit comments