From 5c0134766f405db58f0255839181adc8ef89e511 Mon Sep 17 00:00:00 2001 From: Tanner Lewis Date: Fri, 20 Sep 2024 14:39:27 -0500 Subject: [PATCH] PR feedback and add some unit tests for utils Signed-off-by: Tanner Lewis --- .../lib/console_link/tests/test_utils.py | 24 +++++++++++++++++++ .../lib/migration-services-yaml.ts | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 TrafficCapture/dockerSolution/src/main/docker/migrationConsole/lib/console_link/tests/test_utils.py diff --git a/TrafficCapture/dockerSolution/src/main/docker/migrationConsole/lib/console_link/tests/test_utils.py b/TrafficCapture/dockerSolution/src/main/docker/migrationConsole/lib/console_link/tests/test_utils.py new file mode 100644 index 000000000..40102d8dc --- /dev/null +++ b/TrafficCapture/dockerSolution/src/main/docker/migrationConsole/lib/console_link/tests/test_utils.py @@ -0,0 +1,24 @@ +from console_link.models.utils import append_user_agent_header_for_requests, create_boto3_client +import requests.utils + +USER_AGENT_EXTRA = "test-user-agent-v1.0" + + +def test_append_user_agent_header_for_requests_no_headers(): + expected_headers = {"User-Agent": f"{requests.utils.default_user_agent()} {USER_AGENT_EXTRA}"} + result_headers = append_user_agent_header_for_requests(headers=None, user_agent_extra=USER_AGENT_EXTRA) + assert result_headers == expected_headers + +def test_append_user_agent_header_for_requests_existing_headers(): + existing_headers = {"Accept": "/*", "Host": "macosx"} + expected_headers = dict(existing_headers) + expected_headers["User-Agent"] = f"{requests.utils.default_user_agent()} {USER_AGENT_EXTRA}" + result_headers = append_user_agent_header_for_requests(headers=existing_headers, user_agent_extra=USER_AGENT_EXTRA) + assert result_headers == expected_headers + +def test_append_user_agent_header_for_requests_existing_headers_with_user_agent(): + existing_headers = {"Accept": "/*", "Host": "macosx", "User-Agent": "pyclient"} + expected_headers = dict(existing_headers) + expected_headers["User-Agent"] = f"pyclient {USER_AGENT_EXTRA}" + result_headers = append_user_agent_header_for_requests(headers=existing_headers, user_agent_extra=USER_AGENT_EXTRA) + assert result_headers == expected_headers diff --git a/deployment/cdk/opensearch-service-migration/lib/migration-services-yaml.ts b/deployment/cdk/opensearch-service-migration/lib/migration-services-yaml.ts index 68fb25cc3..a2677b67c 100644 --- a/deployment/cdk/opensearch-service-migration/lib/migration-services-yaml.ts +++ b/deployment/cdk/opensearch-service-migration/lib/migration-services-yaml.ts @@ -124,7 +124,7 @@ export class KafkaYaml { } export class ClientOptions { - user_agent_extra?: string | null; + user_agent_extra?: string; } export class ServicesYaml {