Only validate metadata from the client that we know should exist

- it's allowed that other metadata may be picked up when sending a
  request
pull/2370/head
Craig Tiller 10 years ago
parent f87a0984ab
commit 9f85fa0043
  1. 5
      src/python/src/grpc/_adapter/_low_test.py
  2. 9
      src/python/src/grpc/_links/_transmission_test.py
  3. 11
      src/python/src/grpc/framework/interfaces/links/test_cases.py

@ -129,7 +129,10 @@ class InsecureServerInsecureClient(unittest.TestCase):
self.assertIsInstance(request_event.call, _low.Call) self.assertIsInstance(request_event.call, _low.Call)
self.assertIs(server_request_tag, request_event.tag) self.assertIs(server_request_tag, request_event.tag)
self.assertEquals(1, len(request_event.results)) self.assertEquals(1, len(request_event.results))
self.assertEquals(dict(client_initial_metadata), dict(request_event.results[0].initial_metadata)) got_initial_metadata = dict(request_event.results[0].initial_metadata)
self.assertEquals(
dict(client_initial_metadata),
dict((x, got_initial_metadata[x]) for x in zip(*client_initial_metadata)[0]))
self.assertEquals(METHOD, request_event.call_details.method) self.assertEquals(METHOD, request_event.call_details.method)
self.assertEquals(HOST, request_event.call_details.host) self.assertEquals(HOST, request_event.call_details.host)
self.assertLess(abs(DEADLINE - request_event.call_details.deadline), DEADLINE_TOLERANCE) self.assertLess(abs(DEADLINE - request_event.call_details.deadline), DEADLINE_TOLERANCE)

@ -93,8 +93,13 @@ class TransmissionTest(test_cases.TransmissionTest, unittest.TestCase):
def create_service_completion(self): def create_service_completion(self):
return _intermediary_low.Code.OK, 'An exuberant test "details" message!' return _intermediary_low.Code.OK, 'An exuberant test "details" message!'
def assertMetadataEqual(self, original_metadata, transmitted_metadata): def assertMetadataTransmitted(self, original_metadata, transmitted_metadata):
self.assertSequenceEqual(original_metadata, transmitted_metadata) # we need to filter out any additional metadata added in transmitted_metadata
# since implementations are allowed to add to what is sent (in any position)
keys, _ = zip(*original_metadata)
self.assertSequenceEqual(
original_metadata,
(x for x in transmitted_metadata if x[0] in keys))
class RoundTripTest(unittest.TestCase): class RoundTripTest(unittest.TestCase):

@ -161,8 +161,8 @@ class TransmissionTest(object):
raise NotImplementedError() raise NotImplementedError()
@abc.abstractmethod @abc.abstractmethod
def assertMetadataEqual(self, original_metadata, transmitted_metadata): def assertMetadataTransmitted(self, original_metadata, transmitted_metadata):
"""Asserts that two metadata objects are equal. """Asserts that transmitted_metadata contains original_metadata.
Args: Args:
original_metadata: A metadata object used in this test. original_metadata: A metadata object used in this test.
@ -170,7 +170,8 @@ class TransmissionTest(object):
through the system under test. through the system under test.
Raises: Raises:
AssertionError: if the two metadata objects are not equal. AssertionError: if the transmitted_metadata object does not contain
original_metadata.
""" """
raise NotImplementedError() raise NotImplementedError()
@ -239,7 +240,7 @@ class TransmissionTest(object):
self.assertFalse(initial_metadata_seen) self.assertFalse(initial_metadata_seen)
self.assertFalse(seen_payloads) self.assertFalse(seen_payloads)
self.assertFalse(terminal_metadata_seen) self.assertFalse(terminal_metadata_seen)
self.assertMetadataEqual(initial_metadata, ticket.initial_metadata) self.assertMetadataTransmitted(initial_metadata, ticket.initial_metadata)
initial_metadata_seen = True initial_metadata_seen = True
if ticket.payload is not None: if ticket.payload is not None:
@ -248,7 +249,7 @@ class TransmissionTest(object):
if ticket.terminal_metadata is not None: if ticket.terminal_metadata is not None:
self.assertFalse(terminal_metadata_seen) self.assertFalse(terminal_metadata_seen)
self.assertMetadataEqual(terminal_metadata, ticket.terminal_metadata) self.assertMetadataTransmitted(terminal_metadata, ticket.terminal_metadata)
terminal_metadata_seen = True terminal_metadata_seen = True
self.assertSequenceEqual(payloads, seen_payloads) self.assertSequenceEqual(payloads, seen_payloads)

Loading…
Cancel
Save