From 4af96866574ae4bb2329184b570e1254e331cb86 Mon Sep 17 00:00:00 2001 From: Matthew Elwell Date: Wed, 6 Nov 2024 11:54:09 +0000 Subject: [PATCH] Make clone_feature_states_async write only --- api/environments/serializers.py | 1 + .../environments/test_clone_environment.py | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/api/environments/serializers.py b/api/environments/serializers.py index 36d2bea5ee3a..508eac9fbc9d 100644 --- a/api/environments/serializers.py +++ b/api/environments/serializers.py @@ -134,6 +134,7 @@ class CloneEnvironmentSerializer(EnvironmentSerializerLight): help_text="If True, the environment will be created immediately, but the feature states " "will be created asynchronously. Environment will have `is_creating: true` until " "this process is completed.", + write_only=True, ) class Meta: diff --git a/api/tests/integration/environments/test_clone_environment.py b/api/tests/integration/environments/test_clone_environment.py index b239a4947131..5d43422936f5 100644 --- a/api/tests/integration/environments/test_clone_environment.py +++ b/api/tests/integration/environments/test_clone_environment.py @@ -17,7 +17,11 @@ [lazy_fixture("admin_master_api_key_client"), lazy_fixture("admin_client")], ) def test_clone_environment_clones_feature_states_with_value( - client, project, environment, environment_api_key, feature + client: APIClient, + project: int, + environment: int, + environment_api_key: str, + feature: int, ): # Firstly, let's update feature state value of the source environment # fetch the feature state id to update @@ -43,11 +47,14 @@ def test_clone_environment_clones_feature_states_with_value( # Now, clone the environment env_name = "Cloned env" url = reverse("api-v1:environments:environment-clone", args=[environment_api_key]) - res = client.post(url, {"name": env_name}) + res = client.post(url, {"name": env_name, "clone_feature_states_async": False}) # Then, check that the clone was successful assert res.status_code == status.HTTP_200_OK + # And check that the write only field wasn't returned + assert "clone_feature_states_async" not in res.json() + # Now, fetch the feature states of the source environment source_env_feature_states = get_env_feature_states_list_with_api( client, {"environment": environment} @@ -58,7 +65,7 @@ def test_clone_environment_clones_feature_states_with_value( client, {"environment": res.json()["id"]} ) - # Finaly, compare the responses + # Finally, compare the responses assert source_env_feature_states["count"] == 1 assert ( source_env_feature_states["results"][0]["id"]