@@ -31,6 +31,9 @@ def _make_one(self, *args, **kw):
31
31
return self ._get_target_class ()(* args , ** kw )
32
32
33
33
def test__rpc (self ):
34
+ from google .cloud import _http as connection_module
35
+ from google .cloud .datastore ._http import _CLIENT_INFO
36
+
34
37
class ReqPB (object ):
35
38
36
39
def SerializeToString (self ):
@@ -56,17 +59,24 @@ def FromString(cls, pb):
56
59
self .assertIsInstance (response , RspPB )
57
60
self .assertEqual (response ._pb , 'CONTENT' )
58
61
called_with = http ._called_with
62
+ self .assertEqual (len (called_with ), 4 )
59
63
self .assertEqual (called_with ['uri' ], URI )
60
64
self .assertEqual (called_with ['method' ], 'POST' )
61
- self .assertEqual (called_with ['headers' ]['Content-Type' ],
62
- 'application/x-protobuf' )
63
- self .assertEqual (called_with ['headers' ]['User-Agent' ],
64
- conn .USER_AGENT )
65
+ expected_headers = {
66
+ 'Content-Type' : 'application/x-protobuf' ,
67
+ 'User-Agent' : conn .USER_AGENT ,
68
+ 'Content-Length' : '5' ,
69
+ connection_module .CLIENT_INFO_HEADER : _CLIENT_INFO ,
70
+ }
71
+ self .assertEqual (called_with ['headers' ], expected_headers )
65
72
self .assertEqual (called_with ['body' ], REQPB )
66
73
self .assertEqual (conn .build_kwargs ,
67
74
[{'method' : METHOD , 'project' : PROJECT }])
68
75
69
76
def test__request_w_200 (self ):
77
+ from google .cloud import _http as connection_module
78
+ from google .cloud .datastore ._http import _CLIENT_INFO
79
+
70
80
PROJECT = 'PROJECT'
71
81
METHOD = 'METHOD'
72
82
DATA = b'DATA'
@@ -77,12 +87,16 @@ def test__request_w_200(self):
77
87
self .assertEqual (datastore_api ._request (PROJECT , METHOD , DATA ),
78
88
'CONTENT' )
79
89
called_with = http ._called_with
90
+ self .assertEqual (len (called_with ), 4 )
80
91
self .assertEqual (called_with ['uri' ], URI )
81
92
self .assertEqual (called_with ['method' ], 'POST' )
82
- self .assertEqual (called_with ['headers' ]['Content-Type' ],
83
- 'application/x-protobuf' )
84
- self .assertEqual (called_with ['headers' ]['User-Agent' ],
85
- conn .USER_AGENT )
93
+ expected_headers = {
94
+ 'Content-Type' : 'application/x-protobuf' ,
95
+ 'User-Agent' : conn .USER_AGENT ,
96
+ 'Content-Length' : '4' ,
97
+ connection_module .CLIENT_INFO_HEADER : _CLIENT_INFO ,
98
+ }
99
+ self .assertEqual (called_with ['headers' ], expected_headers )
86
100
self .assertEqual (called_with ['body' ], DATA )
87
101
self .assertEqual (conn .build_kwargs ,
88
102
[{'method' : METHOD , 'project' : PROJECT }])
@@ -386,12 +400,18 @@ def _make_one(self, client, use_grpc=False):
386
400
return self ._get_target_class ()(client )
387
401
388
402
def _verifyProtobufCall (self , called_with , URI , conn ):
403
+ from google .cloud import _http as connection_module
404
+ from google .cloud .datastore ._http import _CLIENT_INFO
405
+
389
406
self .assertEqual (called_with ['uri' ], URI )
390
407
self .assertEqual (called_with ['method' ], 'POST' )
391
- self .assertEqual (called_with ['headers' ]['Content-Type' ],
392
- 'application/x-protobuf' )
393
- self .assertEqual (called_with ['headers' ]['User-Agent' ],
394
- conn .USER_AGENT )
408
+ expected_headers = {
409
+ 'Content-Type' : 'application/x-protobuf' ,
410
+ 'User-Agent' : conn .USER_AGENT ,
411
+ 'Content-Length' : str (len (called_with ['body' ])),
412
+ connection_module .CLIENT_INFO_HEADER : _CLIENT_INFO ,
413
+ }
414
+ self .assertEqual (called_with ['headers' ], expected_headers )
395
415
396
416
def test_default_url (self ):
397
417
klass = self ._get_target_class ()
@@ -681,6 +701,9 @@ def test_lookup_multiple_keys_w_missing(self):
681
701
def test_lookup_multiple_keys_w_deferred (self ):
682
702
from google .cloud .grpc .datastore .v1 import datastore_pb2
683
703
704
+ from google .cloud import _http as connection_module
705
+ from google .cloud .datastore ._http import _CLIENT_INFO
706
+
684
707
PROJECT = 'PROJECT'
685
708
key_pb1 = self ._make_key_pb (PROJECT )
686
709
key_pb2 = self ._make_key_pb (PROJECT , id_ = 2345 )
@@ -704,9 +727,13 @@ def test_lookup_multiple_keys_w_deferred(self):
704
727
self ._verifyProtobufCall (cw , URI , conn )
705
728
self .assertEqual (cw ['uri' ], URI )
706
729
self .assertEqual (cw ['method' ], 'POST' )
707
- self .assertEqual (cw ['headers' ]['Content-Type' ],
708
- 'application/x-protobuf' )
709
- self .assertEqual (cw ['headers' ]['User-Agent' ], conn .USER_AGENT )
730
+ expected_headers = {
731
+ 'Content-Type' : 'application/x-protobuf' ,
732
+ 'User-Agent' : conn .USER_AGENT ,
733
+ 'Content-Length' : '48' ,
734
+ connection_module .CLIENT_INFO_HEADER : _CLIENT_INFO ,
735
+ }
736
+ self .assertEqual (cw ['headers' ], expected_headers )
710
737
rq_class = datastore_pb2 .LookupRequest
711
738
request = rq_class ()
712
739
request .ParseFromString (cw ['body' ])
0 commit comments