Skip to content

Commit

Permalink
PR feedback and add some unit tests for utils
Browse files Browse the repository at this point in the history
Signed-off-by: Tanner Lewis <[email protected]>
  • Loading branch information
lewijacn committed Sep 20, 2024
1 parent 352f23b commit 5c01347
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export class KafkaYaml {
}

export class ClientOptions {
user_agent_extra?: string | null;
user_agent_extra?: string;
}

export class ServicesYaml {
Expand Down

0 comments on commit 5c01347

Please sign in to comment.