Skip to content

Commit d13eeb6

Browse files
authored
Merge pull request #164 from Flagsmith/feat/local-only-feature-ids
feat: add `Project.server_key_only_feature_ids`
2 parents def16e3 + 7636e22 commit d13eeb6

File tree

5 files changed

+61
-0
lines changed

5 files changed

+61
-0
lines changed

flag_engine/api/schemas.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ class DjangoProjectSchema(BaseProjectSchema):
130130
segments = DjangoRelatedManagerField(
131131
fields.Nested(DjangoSegmentSchema), required=False, dump_only=True
132132
)
133+
server_key_only_feature_ids = fields.List(
134+
fields.Int(), required=False, dump_only=True
135+
)
133136

134137

135138
class DjangoEnvironmentSchema(BaseEnvironmentSchema):

flag_engine/projects/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ class ProjectModel:
1313
hide_disabled_flags: bool
1414
segments: typing.List[SegmentModel] = field(default_factory=list)
1515
enable_realtime_updates: bool = False
16+
server_key_only_feature_ids: typing.List[int] = field(default_factory=list)

flag_engine/projects/schemas.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class BaseProjectSchema(Schema):
1616

1717
class ProjectSchema(LoadToModelMixin, BaseProjectSchema):
1818
segments = fields.List(fields.Nested(SegmentSchema), required=False)
19+
server_key_only_feature_ids = fields.List(fields.Int(), required=False)
1920

2021
class Meta:
2122
unknown = EXCLUDE

tests/unit/api/test_document_builders.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
DjangoFeature,
1515
DjangoFeatureState,
1616
DjangoIdentity,
17+
DjangoProject,
1718
)
1819

1920

@@ -82,6 +83,25 @@ def test_build_environment_document(
8283
assert environment_document["webhook_config"]["secret"] == django_webhook.secret
8384

8485

86+
def test_build_environment_document__project_has_server_key_only_feature_ids__return_expected(
87+
django_environment: DjangoEnvironment,
88+
django_project: DjangoProject,
89+
django_enabled_feature_state: DjangoFeatureState,
90+
) -> None:
91+
# Given
92+
expected_server_key_only_feature_ids = [django_enabled_feature_state.feature.id]
93+
django_project.server_key_only_feature_ids = expected_server_key_only_feature_ids
94+
95+
# When
96+
environment_document = build_environment_document(django_environment)
97+
98+
# Then
99+
assert (
100+
environment_document["project"]["server_key_only_feature_ids"]
101+
== expected_server_key_only_feature_ids
102+
)
103+
104+
85105
def test_build_environment_api_key_document(django_environment_api_key):
86106
# When
87107
api_key_document = build_environment_api_key_document(django_environment_api_key)

tests/unit/environments/test_environments_builders.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,42 @@ def test_build_environment_model_with_name():
8383
assert environment_model.name == environment_name
8484

8585

86+
def test_build_environment_model__project_has_server_key_only_feature_ids__return_expected() -> (
87+
None
88+
):
89+
# Given
90+
expected_server_key_only_feature_ids = [1]
91+
environment_name = "some_environment"
92+
environment_dict = {
93+
"id": 1,
94+
"api_key": "api-key",
95+
"name": environment_name,
96+
"project": {
97+
"id": 1,
98+
"name": "test project",
99+
"organisation": {
100+
"id": 1,
101+
"name": "Test org",
102+
"stop_serving_flags": False,
103+
"persist_trait_data": True,
104+
"feature_analytics": True,
105+
},
106+
"hide_disabled_flags": False,
107+
"server_key_only_feature_ids": expected_server_key_only_feature_ids,
108+
},
109+
"feature_states": [],
110+
}
111+
112+
# When
113+
environment_model = build_environment_model(environment_dict)
114+
115+
# Then
116+
assert (
117+
environment_model.project.server_key_only_feature_ids
118+
== expected_server_key_only_feature_ids
119+
)
120+
121+
86122
def test_get_flags_for_environment_returns_feature_states_for_environment_dictionary():
87123
# Given
88124
# some variables for use later

0 commit comments

Comments
 (0)