def test_not_equal_on_not_equal_attributes_types(self): """ Test that the inequality operator returns False when comparing two GetAttributes response payloads with different data. """ a = payloads.GetAttributesResponsePayload(self.unique_identifier, None) b = payloads.GetAttributesResponsePayload(self.unique_identifier, self.attributes) self.assertTrue(a != b) self.assertTrue(b != a)
def test_not_equal_on_not_equal_unique_identifier(self): """ Test that the inequality operator returns True when comparing two GetAttributes request payloads with different data. """ a = payloads.GetAttributesResponsePayload(self.unique_identifier, self.attributes) b = payloads.GetAttributesResponsePayload('invalid', self.attributes) self.assertTrue(a != b) self.assertTrue(b != a)
def test_not_equal_on_equal(self): """ Test that the inequality operator returns False when comparing two GetAttributes response payloads with the same internal data. """ a = payloads.GetAttributesResponsePayload(self.unique_identifier, self.attributes) b = payloads.GetAttributesResponsePayload(self.unique_identifier, self.attributes) self.assertFalse(a != b) self.assertFalse(b != a)
def test_equal_on_equal(self): """ Test that the equality operator returns True when comparing two GetAttributes response payloads with the same data. """ a = payloads.GetAttributesResponsePayload(self.unique_identifier, self.attributes) b = payloads.GetAttributesResponsePayload(self.unique_identifier, self.attributes) self.assertTrue(a == b) self.assertTrue(b == a)
def test_equal_on_not_equal_attributes_count(self): """ Test that the equality operator returns False when comparing two GetAttributes response payloads with different data. """ a = payloads.GetAttributesResponsePayload(self.unique_identifier, self.attributes) b = payloads.GetAttributesResponsePayload(self.unique_identifier, list()) self.assertFalse(a == b) self.assertFalse(b == a)
def test_equal_on_not_equal_attributes(self): """ Test that the equality operator returns False when comparing two GetAttributes response payloads with different data. """ a = payloads.GetAttributesResponsePayload(self.unique_identifier, self.attributes) reversed_attributes = copy.deepcopy(self.attributes) reversed_attributes.reverse() b = payloads.GetAttributesResponsePayload(self.unique_identifier, reversed_attributes) self.assertFalse(a == b) self.assertFalse(b == a)
def test_init_with_args(self): """ Test that a GetAttributes response payload can be constructed with a valid value. """ payloads.GetAttributesResponsePayload( 'test-unique-identifier', [objects.Attribute(), objects.Attribute()])
def test_unique_identifier_with_invalid_value(self): """ Test that a TypeError is raised when an invalid ID is used to set the unique_identifier attribute of a GetAttributes response payload. """ payload = payloads.GetAttributesResponsePayload() args = (payload, 'unique_identifier', 0) self.assertRaisesRegex(TypeError, "unique identifier must be a string", setattr, *args)
def test_attributes_with_invalid_value(self): """ Test that a TypeError is raised when an invalid list is used to set the attributes attribute of a GetAttributes response payload. """ payload = payloads.GetAttributesResponsePayload() args = (payload, 'attributes', 0) self.assertRaisesRegex( TypeError, "attributes must be a list of attribute objects", setattr, *args)
def test_attributes_with_invalid_attribute(self): """ Test that a TypeError is raised when an invalid attribute is included in the list used to set the attributes attribute of a GetAttributes response payload. """ payload = payloads.GetAttributesResponsePayload() args = (payload, 'attributes', [objects.Attribute(), 0]) self.assertRaisesRegex( TypeError, "attributes must be a list of attribute objects; " "item 2 has type {0}".format(type(0)), setattr, *args)
def test_str(self): """ Test that str can be applied to a GetAttributes response payload. """ payload = payloads.GetAttributesResponsePayload( self.unique_identifier, self.attributes) expected = str({ 'unique_identifier': self.unique_identifier, 'attributes': self.attributes }) observed = str(payload) self.assertEqual(expected, observed)
def test_write_with_no_attribute_names(self): """ Test that a GetAttributes response payload with no attribute name data can be written to a data stream. """ payload = payloads.GetAttributesResponsePayload( self.unique_identifier, None) stream = utils.BytearrayStream() payload.write(stream) self.assertEqual(len(self.encoding_sans_attributes), len(stream)) self.assertEqual(str(self.encoding_sans_attributes), str(stream))
def test_write(self): """ Test that a GetAttributes response payload can be written to a data stream. """ payload = payloads.GetAttributesResponsePayload( self.unique_identifier, self.attributes) stream = utils.BytearrayStream() payload.write(stream) self.assertEqual(len(self.full_encoding), len(stream)) self.assertEqual(str(self.full_encoding), str(stream))
def test_equal_on_type_mismatch(self): """ Test that the equality operator returns False when comparing a GetAttributes response payload to a non-GetAttributes response payload. """ a = payloads.GetAttributesResponsePayload(self.unique_identifier, self.attributes) b = 'invalid' self.assertFalse(a == b) self.assertFalse(b == a)
def test_not_equal_on_type_mismatch(self): """ Test that the inequality operator returns True when comparing a GetAttributes response payload to a non-GetAttributes response payload. """ a = payloads.GetAttributesResponsePayload(self.unique_identifier, self.attributes) b = "invalid" self.assertTrue(a != b) self.assertTrue(b != a)
def test_repr(self): """ Test that repr can be applied to a GetAttributes response payload. """ payload = payloads.GetAttributesResponsePayload( self.unique_identifier, self.attributes) unique_identifier = "unique_identifier={0}".format( payload.unique_identifier) payload_attributes = "attributes={0}".format(payload.attributes) expected = "GetAttributesResponsePayload({0}, {1})".format( unique_identifier, payload_attributes) observed = repr(payload) self.assertEqual(expected, observed)
def test_write_with_no_unique_identifier(self): """ Test that a GetAttributes request payload with no ID can be written to a data stream. """ payload = payloads.GetAttributesResponsePayload(None, self.attributes) stream = utils.BytearrayStream() args = (stream, ) self.assertRaisesRegex( exceptions.InvalidField, "The GetAttributes response unique identifier is required.", payload.write, *args)
def test_read_with_no_unique_identifier(self): """ Test that an InvalidKmipEncoding error gets raised when attempting to read a GetAttributes response encoding with no ID data. """ payload = payloads.GetAttributesResponsePayload() self.assertEqual(None, payload._unique_identifier) self.assertEqual(list(), payload._attributes) args = (self.encoding_sans_unique_identifier, ) self.assertRaisesRegex( exceptions.InvalidKmipEncoding, "expected GetAttributes response unique identifier not found", payload.read, *args)
def test_attributes(self): """ Test that the attributes attribute of a GetAttributes response payload can be properly set and retrieved. """ payload = payloads.GetAttributesResponsePayload() self.assertEqual(list(), payload.attributes) self.assertEqual(list(), payload._attributes) payload.attributes = [objects.Attribute(), objects.Attribute()] self.assertEqual(2, len(payload.attributes)) self.assertEqual(2, len(payload._attributes)) for attribute in payload._attributes: self.assertIsInstance(attribute, objects.Attribute)
def test_process_get_attributes_batch_item(self): uuid = '00000000-1111-2222-3333-444444444444' attributes = [] payload = payloads.GetAttributesResponsePayload( unique_identifier=uuid, attributes=attributes ) batch_item = ResponseBatchItem( operation=Operation(OperationEnum.GET_ATTRIBUTES), response_payload=payload ) result = self.client._process_get_attributes_batch_item(batch_item) self.assertIsInstance(result, GetAttributesResult) self.assertEqual(uuid, result.uuid) self.assertEqual(attributes, result.attributes)
def test_unique_identifier(self): """ Test that the unique_identifier attribute of a GetAttributes response payload can be properly set and retrieved. """ payload = payloads.GetAttributesResponsePayload() self.assertIsNone(payload.unique_identifier) self.assertIsNone(payload._unique_identifier) payload.unique_identifier = 'test-unique-identifier' self.assertEqual('test-unique-identifier', payload.unique_identifier) self.assertEqual( primitives.TextString(value='test-unique-identifier', tag=enums.Tags.UNIQUE_IDENTIFIER), payload._unique_identifier)
def test_read_with_no_attributes(self): """ Test that a GetAttributes response payload without attribute name data can be read from a data stream. """ payload = payloads.GetAttributesResponsePayload() self.assertEqual(None, payload._unique_identifier) self.assertEqual(list(), payload._attributes) payload.read(self.encoding_sans_attributes) self.assertEqual(self.unique_identifier, payload.unique_identifier) self.assertEqual( primitives.TextString(value=self.unique_identifier, tag=enums.Tags.UNIQUE_IDENTIFIER), payload._unique_identifier) self.assertEqual(list(), payload.attributes) self.assertEqual(list(), payload._attributes)
def test_read(self): """ Test that a GetAttributes response payload can be read from a data stream. """ payload = payloads.GetAttributesResponsePayload() self.assertEqual(None, payload._unique_identifier) self.assertEqual(list(), payload._attributes) payload.read(self.full_encoding) self.assertEqual(self.unique_identifier, payload.unique_identifier) self.assertEqual( primitives.TextString(value=self.unique_identifier, tag=enums.Tags.UNIQUE_IDENTIFIER), payload._unique_identifier) self.assertEqual(len(self.attributes), len(payload.attributes)) for attribute in self.attributes: self.assertIn(attribute, payload._attributes)
def _create_get_attributes_payload(self): return payloads.GetAttributesResponsePayload()
def test_init(self): """ Test that a GetAttributes response payload can be constructed. """ payloads.GetAttributesResponsePayload()