def test_headers_dict_update(self):
     headers = {
         "user-agent": "test-0.0.1",
         "content-type": "application/json",
         "notAReal": "heaDer",
     }
     hdict = HeadersDict()
     hdict.update(headers)
     for key in headers.keys():
         assert headers[key] == hdict[key]
    def sign(self, request: PreparedRequest,
             credentials: Optional[Credentials]) -> PreparedRequest:
        if credentials is None:
            raise CredentialsException("Failed to resolve credentials")
        alg = AwsSigningAlgorithm(self.algorithm)
        sig_type = AwsSignatureType(self.signature_type)

        credential_provider = AwsCredentialsProvider.new_static(
            credentials.access_key_id,
            credentials.secret_access_key,
            credentials.session_token,
        )

        config = AwsSigningConfig(
            algorithm=alg,
            signature_type=sig_type,
            credentials_provider=credential_provider,
            region=self.region,
            service=self.service_name,
            signed_body_value=AwsSignedBodyValue.EMPTY_SHA256,
            signed_body_header_type=AwsSignedBodyHeaderType.NONE,
        )
        crt_request = _convert_request(request)
        signed_request = aws_sign_request(crt_request, config).result()
        request.headers = HeadersDict(dict(signed_request.headers))

        return request
 def test_minimal_request(self):
     req = Request(endpoint="https://aws.amazon.com")
     assert req.endpoint == "https://aws.amazon.com"
     assert req.path == "/"
     assert req.method == "GET"
     assert req.headers == HeadersDict()
     assert req.body is None
     assert req.params == {}
 def test_request_preparation(self):
     req = Request(
         endpoint="https://aws.amazon.com",
         path="/transcribe",
         method="hEaD",
         headers={"User-Agent": "test-transcribe-0.0.1"},
         body="Test body",
         params={"test": "value"},
     )
     prep = req.prepare()
     assert prep.endpoint == "https://aws.amazon.com"
     assert prep.path == "/transcribe"
     assert prep.uri == "https://aws.amazon.com/transcribe?test=value"
     assert prep.method == "HEAD"
     assert prep.headers == HeadersDict({"User-Agent": "test-transcribe-0.0.1"})
     assert prep.body.read() == BytesIO(b"Test body").read()
     assert prep.query == "test=value"
 def test_header_dict_assignment(self):
     hdict = HeadersDict()
     hdict["test"] = "header"
     assert hdict["test"] == "header"
 def test_header_dict_creation(self):
     hdict = HeadersDict({"test": "header"})
     assert hdict["test"] == "header"
 def test_headers_dict_validation(self, key, value, expected_key, expected_value):
     hdict = HeadersDict()
     hdict[key] = value
     assert hdict[expected_key] == expected_value
 def __init__(self, status_code: int = 500, headers: Optional[Dict] = None):
     self.status_code = status_code
     if headers is None:
         headers = {}
     self.headers = HeadersDict(headers)