def test_comparison_on_different_unique_identifiers(self): """ Test that the equality/inequality operators return False/True when comparing two SetAttribute response payloads with different unique identifiers. """ a = payloads.SetAttributeResponsePayload(unique_identifier="1") b = payloads.SetAttributeResponsePayload(unique_identifier="2") self.assertFalse(a == b) self.assertFalse(b == a) self.assertTrue(a != b) self.assertTrue(b != a)
def test_str(self): """ Test that str can be applied to a SetAttribute response payload. """ payload = payloads.SetAttributeResponsePayload( unique_identifier="b4faee10-aa2a-4446-8ad4-0881f3422959") s = str({"unique_identifier": "b4faee10-aa2a-4446-8ad4-0881f3422959"}) self.assertEqual(s, str(payload))
def test_repr(self): """ Test that repr can be applied to a SetAttribute response payload. """ payload = payloads.SetAttributeResponsePayload( unique_identifier="b4faee10-aa2a-4446-8ad4-0881f3422959") args = ["unique_identifier='b4faee10-aa2a-4446-8ad4-0881f3422959'"] self.assertEqual( "SetAttributeResponsePayload({})".format(", ".join(args)), repr(payload))
def test_read_invalid_kmip_version(self): """ Test that a VersionNotSupported error is raised when an unsupported version of KMIP is used to decode the SetAttribute response payload. """ payload = payloads.SetAttributeResponsePayload() args = (self.empty_encoding, ) kwargs = {"kmip_version": enums.KMIPVersion.KMIP_1_0} self.assertRaisesRegex( exceptions.VersionNotSupported, "KMIP 1.0 does not support the SetAttribute operation.", payload.read, *args, **kwargs)
def test_read_no_unique_identifier(self): """ Test that an InvalidKmipEncoding error is raised when an invalid encoding containing no encoded unique identifier is used to decode a SetAttribute response payload. """ payload = payloads.SetAttributeResponsePayload() args = (self.empty_encoding, ) self.assertRaisesRegex( exceptions.InvalidKmipEncoding, "The SetAttribute response payload encoding is missing the " "unique identifier field.", payload.read, *args)
def test_read(self): """ Test that a SetAttribute response payload can be read from a buffer. """ payload = payloads.SetAttributeResponsePayload() self.assertIsNone(payload.unique_identifier) payload.read(self.full_encoding) self.assertEqual("b4faee10-aa2a-4446-8ad4-0881f3422959", payload.unique_identifier)
def test_comparison_on_type_mismatch(self): """ Test that the equality/inequality operators return False/True when comparining a SetAttribute response payload against a different type. """ a = payloads.SetAttributeResponsePayload() b = "invalid" self.assertFalse(a == b) self.assertFalse(b == a) self.assertTrue(a != b) self.assertTrue(b != a)
def test_comparison(self): """ Test that the equality/inequality operators return True/False when comparing two SetAttribute response payloads with the same data. """ a = payloads.SetAttributeResponsePayload() b = payloads.SetAttributeResponsePayload() self.assertTrue(a == b) self.assertTrue(b == a) self.assertFalse(a != b) self.assertFalse(b != a) a = payloads.SetAttributeResponsePayload( unique_identifier="b4faee10-aa2a-4446-8ad4-0881f3422959") b = payloads.SetAttributeResponsePayload( unique_identifier="b4faee10-aa2a-4446-8ad4-0881f3422959") self.assertTrue(a == b) self.assertTrue(b == a) self.assertFalse(a != b) self.assertFalse(b != a)
def test_write_invalid_kmip_version(self): """ Test that a VersionNotSupported error is raised when an unsupported version of KMIP is used to encode the SetAttribute response payload. """ payload = payloads.SetAttributeResponsePayload() args = (utils.BytearrayStream(), ) kwargs = {"kmip_version": enums.KMIPVersion.KMIP_1_0} self.assertRaisesRegex( exceptions.VersionNotSupported, "KMIP 1.0 does not support the SetAttribute operation.", payload.write, *args, **kwargs)
def test_write_no_unique_identifier(self): """ Test that an InvalidField error is raised when attempting to write a SetAttribute response payload to a buffer with no unique identifier field specified. """ payload = payloads.SetAttributeResponsePayload() args = (utils.BytearrayStream(), ) self.assertRaisesRegex( exceptions.InvalidField, "The SetAttribute response payload is missing the unique " "identifier field.", payload.write, *args)
def test_write(self): """ Test that a SetAttribute response payload can be written to a buffer. """ payload = payloads.SetAttributeResponsePayload( unique_identifier="b4faee10-aa2a-4446-8ad4-0881f3422959") buffer = utils.BytearrayStream() payload.write(buffer) self.assertEqual(len(self.full_encoding), len(buffer)) self.assertEqual(str(self.full_encoding), str(buffer))
def test_invalid_unique_identifier(self): """ Test that a TypeError is raised when an invalid value is used to set the unique identifier of a SetAttribute response payload. """ kwargs = {"unique_identifier": 0} self.assertRaisesRegex(TypeError, "The unique identifier must be a string.", payloads.SetAttributeResponsePayload, **kwargs) args = (payloads.SetAttributeResponsePayload(), "unique_identifier", 0) self.assertRaisesRegex(TypeError, "The unique identifier must be a string.", setattr, *args)
def _create_set_attribute_payload(self): return payloads.SetAttributeResponsePayload()