11import os
2- import re
32from datetime import datetime , timedelta
4- from tempfile import NamedTemporaryFile
53
64import boto3
75import pytest
@@ -179,36 +177,25 @@ def test_create_db_objects_creates_dedicated_performance_service_with_limits_and
179177
180178
181179@mock_aws
182- def test_function_test_fixtures_saves_to_disk_and_ssm (notify_api , os_environ , mocker ):
180+ def test_function_test_fixtures_uploads_to_ssm (notify_api , os_environ , mocker ):
183181 mocker .patch (
184182 "app.functional_tests_fixtures._create_db_objects" ,
185- return_value = ({"FOO" : "BAR" , "BAZ " : "WAZ " }, {}),
183+ return_value = ({"FOO" : "BAR" , "PASSWORD " : "super-secret" , "TOKEN" : "abc123 " }, {}),
186184 )
187185
188- with NamedTemporaryFile () as temp_file :
189- temp_file_name = temp_file .name
190-
191- os .environ ["FUNCTIONAL_TEST_ENV_FILE" ] = temp_file_name
192- os .environ ["SSM_UPLOAD_PATH" ] = "/test/ssm/environment"
193- # AWS are changing from AWS_DEFAULT_REGION to AWS_REGION for v2 clients. Set both for now.
194- os .environ ["AWS_REGION" ] = "eu-west-1"
195- os .environ ["AWS_DEFAULT_REGION" ] = "eu-west-1"
196-
197- apply_fixtures ()
186+ os .environ ["SSM_UPLOAD_PATH" ] = "/test/ssm/environment"
187+ # AWS are changing from AWS_DEFAULT_REGION to AWS_REGION for v2 clients. Set both for now.
188+ os .environ ["AWS_REGION" ] = "eu-west-1"
189+ os .environ ["AWS_DEFAULT_REGION" ] = "eu-west-1"
198190
199- variables = {}
200- full_file = ""
201- with open (temp_file_name ) as f :
202- full_file = f .read ()
203- for line in full_file .splitlines ():
204- match = re .match (r"export (?P<key>[A-Z0-9_]+)='(?P<value>[^']+)'" , line )
205- variables [match ["key" ]] = match ["value" ]
206- assert variables == {"FOO" : "BAR" , "BAZ" : "WAZ" }
191+ apply_fixtures ()
207192
208- # test that the SSM parameter was created and contains the same as the file
209- ssm = boto3 .client ("ssm" )
210- response = ssm .get_parameter (Name = "/test/ssm/environment" , WithDecryption = True )
211- assert response ["Parameter" ]["Value" ] == full_file
193+ # test that the SSM parameter was created and contains full content
194+ ssm = boto3 .client ("ssm" )
195+ response = ssm .get_parameter (Name = "/test/ssm/environment" , WithDecryption = True )
196+ assert "export FOO='BAR'" in response ["Parameter" ]["Value" ]
197+ assert "export PASSWORD='super-secret'" in response ["Parameter" ]["Value" ]
198+ assert "export TOKEN='abc123'" in response ["Parameter" ]["Value" ]
212199
213200
214201def test_function_test_fixtures_raises_clear_error_when_ssm_upload_fails (notify_api , os_environ , mocker ):
@@ -219,7 +206,6 @@ def test_function_test_fixtures_raises_clear_error_when_ssm_upload_fails(notify_
219206 ssm_client .put_parameter .side_effect = Exception ("Parameter value too large" )
220207 mocker .patch ("app.functional_tests_fixtures.boto3.client" , return_value = ssm_client )
221208
222- os .environ ["FUNCTIONAL_TEST_ENV_FILE" ] = ""
223209 os .environ ["SSM_UPLOAD_PATH" ] = "/test/ssm/environment"
224210
225211 with pytest .raises (Exception ) as exc :
@@ -246,7 +232,6 @@ def test_function_test_fixtures_uploads_performance_env_to_separate_ssm_path(not
246232 ssm_client .put_parameter .return_value = {"ResponseMetadata" : {"HTTPStatusCode" : 200 }}
247233 mocker .patch ("app.functional_tests_fixtures.boto3.client" , return_value = ssm_client )
248234
249- os .environ ["FUNCTIONAL_TEST_ENV_FILE" ] = ""
250235 os .environ ["SSM_UPLOAD_PATH" ] = "/test/ssm/functional-environment"
251236 os .environ ["PERFORMANCE_SSM_UPLOAD_PATH" ] = "/test/ssm/performance-environment"
252237
0 commit comments