3
3
"""
4
4
import base64
5
5
import json
6
+ from datetime import datetime
7
+ from uuid import UUID
8
+
6
9
import urllib3
7
10
from unittest import mock
8
11
from unittest .mock import patch
13
16
from botocore .exceptions import BotoCoreError
14
17
15
18
import pytest
19
+ from freezegun import freeze_time
16
20
17
21
from pynamodb .connection import Connection
18
22
from pynamodb .connection .base import MetaTable
@@ -1515,11 +1519,13 @@ def test_connection__botocore_config():
1515
1519
assert c .client ._client_config .max_pool_connections == 20
1516
1520
1517
1521
1518
- @mock . patch ( 'botocore.httpsession.URLLib3Session.send' )
1519
- def test_connection_make_api_call___extra_headers (send_mock ):
1522
+ @freeze_time ( )
1523
+ def test_connection_make_api_call___extra_headers (mocker ):
1520
1524
good_response = mock .Mock (spec = AWSResponse , status_code = 200 , headers = {}, text = '{}' , content = b'{}' )
1525
+ send_mock = mocker .patch ('botocore.httpsession.URLLib3Session.send' , return_value = good_response )
1521
1526
1522
- send_mock .return_value = good_response
1527
+ # return constant UUID
1528
+ mocker .patch ('uuid.uuid4' , return_value = UUID ('01FC4BDB-B223-4B86-88F4-DEE79B77F275' ))
1523
1529
1524
1530
c = Connection (extra_headers = {'foo' : 'bar' }, max_retry_attempts = 0 )
1525
1531
c ._make_api_call (
@@ -1529,7 +1535,18 @@ def test_connection_make_api_call___extra_headers(send_mock):
1529
1535
1530
1536
assert send_mock .call_count == 1
1531
1537
request = send_mock .call_args [0 ][0 ]
1532
- assert request .headers .get ('foo' ).decode () == 'bar'
1538
+ assert request .headers ['foo' ] == 'bar'
1539
+
1540
+ c = Connection (extra_headers = {'foo' : 'baz' }, max_retry_attempts = 0 )
1541
+ c ._make_api_call (
1542
+ 'DescribeTable' ,
1543
+ {'TableName' : 'MyTable' },
1544
+ )
1545
+
1546
+ assert send_mock .call_count == 2
1547
+ request2 = send_mock .call_args [0 ][0 ]
1548
+ # all headers, including signatures, and except 'foo', should match
1549
+ assert {** request .headers , 'foo' : '' } == {** request2 .headers , 'foo' : '' }
1533
1550
1534
1551
1535
1552
@mock .patch ('botocore.httpsession.URLLib3Session.send' )
0 commit comments