Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove spurious assertions about Content-Length header value. #275

Merged
merged 1 commit into from
Oct 21, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 55 additions & 101 deletions gcloud/datastore/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,13 @@ def test__request_w_200(self):
])
http = conn._http = Http({'status': '200'}, 'CONTENT')
self.assertEqual(conn._request(DATASET_ID, METHOD, DATA), 'CONTENT')
expected_called_with = {
'uri': URI,
'method': 'POST',
'headers': {
'Content-Type': 'application/x-protobuf',
'Content-Length': '4',
'User-Agent': conn.USER_AGENT,
},
'body': DATA,
}
self.assertEqual(http._called_with, expected_called_with)
self.assertEqual(http._called_with['uri'], URI)
self.assertEqual(http._called_with['method'], 'POST')
self.assertEqual(http._called_with['headers']['Content-Type'],
'application/x-protobuf')
self.assertEqual(http._called_with['headers']['User-Agent'],
conn.USER_AGENT)
self.assertEqual(http._called_with['body'], DATA)

def test__request_not_200(self):
DATASET_ID = 'DATASET'
Expand All @@ -89,7 +85,7 @@ def test__rpc(self):
class ReqPB(object):

def SerializeToString(self):
return b'REQPB'
return REQPB

class RspPB(object):

Expand All @@ -100,6 +96,7 @@ def __init__(self, pb):
def FromString(cls, pb):
return cls(pb)

REQPB = b'REQPB'
DATASET_ID = 'DATASET'
METHOD = 'METHOD'
conn = self._makeOne()
Expand All @@ -115,17 +112,13 @@ def FromString(cls, pb):
response = conn._rpc(DATASET_ID, METHOD, ReqPB(), RspPB)
self.assertTrue(isinstance(response, RspPB))
self.assertEqual(response._pb, 'CONTENT')
expected_called_with = {
'uri': URI,
'method': 'POST',
'headers': {
'Content-Type': 'application/x-protobuf',
'Content-Length': '5',
'User-Agent': conn.USER_AGENT,
},
'body': b'REQPB',
}
self.assertEqual(http._called_with, expected_called_with)
self.assertEqual(http._called_with['uri'], URI)
self.assertEqual(http._called_with['method'], 'POST')
self.assertEqual(http._called_with['headers']['Content-Type'],
'application/x-protobuf')
self.assertEqual(http._called_with['headers']['User-Agent'],
conn.USER_AGENT)
self.assertEqual(http._called_with['body'], REQPB)

def test_build_api_url_w_default_base_version(self):
DATASET_ID = 'DATASET'
Expand Down Expand Up @@ -226,12 +219,9 @@ def test_begin_transaction_default_serialize(self):
cw = http._called_with
self.assertEqual(cw['uri'], URI)
self.assertEqual(cw['method'], 'POST')
expected_headers = {
'Content-Type': 'application/x-protobuf',
'Content-Length': '2',
'User-Agent': conn.USER_AGENT,
}
self.assertEqual(cw['headers'], expected_headers)
self.assertEqual(cw['headers']['Content-Type'],
'application/x-protobuf')
self.assertEqual(cw['headers']['User-Agent'], conn.USER_AGENT)
rq_class = datastore_pb.BeginTransactionRequest
request = rq_class()
request.ParseFromString(cw['body'])
Expand All @@ -258,12 +248,9 @@ def test_begin_transaction_explicit_serialize(self):
cw = http._called_with
self.assertEqual(cw['uri'], URI)
self.assertEqual(cw['method'], 'POST')
expected_headers = {
'Content-Type': 'application/x-protobuf',
'Content-Length': '2',
'User-Agent': conn.USER_AGENT,
}
self.assertEqual(cw['headers'], expected_headers)
self.assertEqual(cw['headers']['Content-Type'],
'application/x-protobuf')
self.assertEqual(cw['headers']['User-Agent'], conn.USER_AGENT)
rq_class = datastore_pb.BeginTransactionRequest
request = rq_class()
request.ParseFromString(cw['body'])
Expand Down Expand Up @@ -312,12 +299,9 @@ def id(self):
cw = http._called_with
self.assertEqual(cw['uri'], URI)
self.assertEqual(cw['method'], 'POST')
expected_headers = {
'Content-Type': 'application/x-protobuf',
'Content-Length': '6',
'User-Agent': conn.USER_AGENT,
}
self.assertEqual(cw['headers'], expected_headers)
self.assertEqual(cw['headers']['Content-Type'],
'application/x-protobuf')
self.assertEqual(cw['headers']['User-Agent'], conn.USER_AGENT)
rq_class = datastore_pb.RollbackRequest
request = rq_class()
request.ParseFromString(cw['body'])
Expand Down Expand Up @@ -349,12 +333,9 @@ def test_run_query_wo_namespace_empty_result(self):
cw = http._called_with
self.assertEqual(cw['uri'], URI)
self.assertEqual(cw['method'], 'POST')
expected_headers = {
'Content-Type': 'application/x-protobuf',
'Content-Length': '14',
'User-Agent': conn.USER_AGENT,
}
self.assertEqual(cw['headers'], expected_headers)
self.assertEqual(cw['headers']['Content-Type'],
'application/x-protobuf')
self.assertEqual(cw['headers']['User-Agent'], conn.USER_AGENT)
rq_class = datastore_pb.RunQueryRequest
request = rq_class()
request.ParseFromString(cw['body'])
Expand Down Expand Up @@ -388,12 +369,9 @@ def test_run_query_w_namespace_nonempty_result(self):
cw = http._called_with
self.assertEqual(cw['uri'], URI)
self.assertEqual(cw['method'], 'POST')
expected_headers = {
'Content-Type': 'application/x-protobuf',
'Content-Length': '16',
'User-Agent': conn.USER_AGENT,
}
self.assertEqual(cw['headers'], expected_headers)
self.assertEqual(cw['headers']['Content-Type'],
'application/x-protobuf')
self.assertEqual(cw['headers']['User-Agent'], conn.USER_AGENT)
rq_class = datastore_pb.RunQueryRequest
request = rq_class()
request.ParseFromString(cw['body'])
Expand Down Expand Up @@ -423,12 +401,9 @@ def test_lookup_single_key_empty_response(self):
cw = http._called_with
self.assertEqual(cw['uri'], URI)
self.assertEqual(cw['method'], 'POST')
expected_headers = {
'Content-Type': 'application/x-protobuf',
'Content-Length': '26',
'User-Agent': conn.USER_AGENT,
}
self.assertEqual(cw['headers'], expected_headers)
self.assertEqual(cw['headers']['Content-Type'],
'application/x-protobuf')
self.assertEqual(cw['headers']['User-Agent'], conn.USER_AGENT)
rq_class = datastore_pb.LookupRequest
request = rq_class()
request.ParseFromString(cw['body'])
Expand Down Expand Up @@ -464,12 +439,9 @@ def test_lookup_single_key_nonempty_response(self):
cw = http._called_with
self.assertEqual(cw['uri'], URI)
self.assertEqual(cw['method'], 'POST')
expected_headers = {
'Content-Type': 'application/x-protobuf',
'Content-Length': '26',
'User-Agent': conn.USER_AGENT,
}
self.assertEqual(cw['headers'], expected_headers)
self.assertEqual(cw['headers']['Content-Type'],
'application/x-protobuf')
self.assertEqual(cw['headers']['User-Agent'], conn.USER_AGENT)
rq_class = datastore_pb.LookupRequest
request = rq_class()
request.ParseFromString(cw['body'])
Expand Down Expand Up @@ -502,12 +474,9 @@ def test_lookup_multiple_keys_empty_response(self):
cw = http._called_with
self.assertEqual(cw['uri'], URI)
self.assertEqual(cw['method'], 'POST')
expected_headers = {
'Content-Type': 'application/x-protobuf',
'Content-Length': '52',
'User-Agent': conn.USER_AGENT,
}
self.assertEqual(cw['headers'], expected_headers)
self.assertEqual(cw['headers']['Content-Type'],
'application/x-protobuf')
self.assertEqual(cw['headers']['User-Agent'], conn.USER_AGENT)
rq_class = datastore_pb.LookupRequest
request = rq_class()
request.ParseFromString(cw['body'])
Expand Down Expand Up @@ -547,12 +516,9 @@ def test_commit_wo_transaction(self):
cw = http._called_with
self.assertEqual(cw['uri'], URI)
self.assertEqual(cw['method'], 'POST')
expected_headers = {
'Content-Type': 'application/x-protobuf',
'Content-Length': '47',
'User-Agent': conn.USER_AGENT,
}
self.assertEqual(cw['headers'], expected_headers)
self.assertEqual(cw['headers']['Content-Type'],
'application/x-protobuf')
self.assertEqual(cw['headers']['User-Agent'], conn.USER_AGENT)
rq_class = datastore_pb.CommitRequest
request = rq_class()
request.ParseFromString(cw['body'])
Expand Down Expand Up @@ -595,12 +561,9 @@ def id(self):
cw = http._called_with
self.assertEqual(cw['uri'], URI)
self.assertEqual(cw['method'], 'POST')
expected_headers = {
'Content-Type': 'application/x-protobuf',
'Content-Length': '53',
'User-Agent': conn.USER_AGENT,
}
self.assertEqual(cw['headers'], expected_headers)
self.assertEqual(cw['headers']['Content-Type'],
'application/x-protobuf')
self.assertEqual(cw['headers']['User-Agent'], conn.USER_AGENT)
rq_class = datastore_pb.CommitRequest
request = rq_class()
request.ParseFromString(cw['body'])
Expand Down Expand Up @@ -632,12 +595,9 @@ def test_save_entity_wo_transaction_w_upsert(self):
cw = http._called_with
self.assertEqual(cw['uri'], URI)
self.assertEqual(cw['method'], 'POST')
expected_headers = {
'Content-Type': 'application/x-protobuf',
'Content-Length': '47',
'User-Agent': conn.USER_AGENT,
}
self.assertEqual(cw['headers'], expected_headers)
self.assertEqual(cw['headers']['Content-Type'],
'application/x-protobuf')
self.assertEqual(cw['headers']['User-Agent'], conn.USER_AGENT)
rq_class = datastore_pb.CommitRequest
request = rq_class()
request.ParseFromString(cw['body'])
Expand Down Expand Up @@ -685,12 +645,9 @@ def test_save_entity_wo_transaction_w_auto_id(self):
cw = http._called_with
self.assertEqual(cw['uri'], URI)
self.assertEqual(cw['method'], 'POST')
expected_headers = {
'Content-Type': 'application/x-protobuf',
'Content-Length': '44',
'User-Agent': conn.USER_AGENT,
}
self.assertEqual(cw['headers'], expected_headers)
self.assertEqual(cw['headers']['Content-Type'],
'application/x-protobuf')
self.assertEqual(cw['headers']['User-Agent'], conn.USER_AGENT)
rq_class = datastore_pb.CommitRequest
request = rq_class()
request.ParseFromString(cw['body'])
Expand Down Expand Up @@ -782,12 +739,9 @@ def test_delete_entities_wo_transaction(self):
cw = http._called_with
self.assertEqual(cw['uri'], URI)
self.assertEqual(cw['method'], 'POST')
expected_headers = {
'Content-Type': 'application/x-protobuf',
'Content-Length': '30',
'User-Agent': conn.USER_AGENT,
}
self.assertEqual(cw['headers'], expected_headers)
self.assertEqual(cw['headers']['Content-Type'],
'application/x-protobuf')
self.assertEqual(cw['headers']['User-Agent'], conn.USER_AGENT)
rq_class = datastore_pb.CommitRequest
request = rq_class()
request.ParseFromString(cw['body'])
Expand Down