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 = get_attributes.GetAttributesResponsePayload( self.uid, self.attributes) b = get_attributes.GetAttributesResponsePayload(self.uid, list()) self.assertFalse(a == b) self.assertFalse(b == a)
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 = get_attributes.GetAttributesResponsePayload(self.uid, None) b = get_attributes.GetAttributesResponsePayload( self.uid, self.attributes) self.assertTrue(a != b) self.assertTrue(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 = get_attributes.GetAttributesResponsePayload( self.uid, self.attributes) b = get_attributes.GetAttributesResponsePayload( self.uid, 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 = get_attributes.GetAttributesResponsePayload( self.uid, self.attributes) b = get_attributes.GetAttributesResponsePayload( self.uid, self.attributes) self.assertFalse(a != b) self.assertFalse(b != a)
def test_not_equal_on_not_equal_uid(self): """ Test that the inequality operator returns True when comparing two GetAttributes request payloads with different data. """ a = get_attributes.GetAttributesResponsePayload( self.uid, self.attributes) b = get_attributes.GetAttributesResponsePayload( 'invalid', self.attributes) self.assertTrue(a != b) self.assertTrue(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 = get_attributes.GetAttributesResponsePayload( self.uid, self.attributes) reversed_attributes = copy.deepcopy(self.attributes) reversed_attributes.reverse() b = get_attributes.GetAttributesResponsePayload( self.uid, reversed_attributes) self.assertFalse(a == b) self.assertFalse(b == a)
def test_read(self): """ Test that a GetAttributes response payload can be read from a data stream. """ payload = get_attributes.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 test_not_equal_on_not_equal_attributes_count(self): """ Test that the inequality operator returns False when comparing two GetAttributes response payloads with different data. """ a = get_attributes.GetAttributesResponsePayload( self.unique_identifier, self.attributes ) b = get_attributes.GetAttributesResponsePayload( self.unique_identifier, list() ) self.assertTrue(a != b) self.assertTrue(b != a)
def test_equal_on_not_equal_attributes_types(self): """ Test that the equality operator returns False when comparing two GetAttributes response payloads with different data. """ a = get_attributes.GetAttributesResponsePayload( self.unique_identifier, None ) b = get_attributes.GetAttributesResponsePayload( self.unique_identifier, self.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. """ get_attributes.GetAttributesResponsePayload( 'test-uid', [objects.Attribute(), objects.Attribute()])
def test_uid_with_invalid_value(self): """ Test that a TypeError is raised when an invalid ID is used to set the uid attribute of a GetAttributes response payload. """ payload = get_attributes.GetAttributesResponsePayload() args = (payload, 'uid', 0) self.assertRaisesRegexp(TypeError, "uid must be a string", setattr, *args)
def test_str(self): """ Test that str can be applied to a GetAttributes response payload. """ payload = get_attributes.GetAttributesResponsePayload( self.uid, self.attributes) expected = str({'uid': self.uid, 'attributes': self.attributes}) observed = str(payload) self.assertEqual(expected, observed)
def test_not_equal_on_not_equal_attributes(self): """ Test that the inequality operator returns False when comparing two GetAttributes response payloads with different data. """ a = get_attributes.GetAttributesResponsePayload( self.unique_identifier, self.attributes ) reversed_attributes = copy.deepcopy(self.attributes) reversed_attributes.reverse() b = get_attributes.GetAttributesResponsePayload( self.unique_identifier, reversed_attributes ) self.assertTrue(a != b) self.assertTrue(b != a)
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 = get_attributes.GetAttributesResponsePayload() args = (payload, 'attributes', 0) self.assertRaisesRegexp( TypeError, "attributes must be a list of attribute objects", setattr, *args)
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 = get_attributes.GetAttributesResponsePayload(self.uid, 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_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 = get_attributes.GetAttributesResponsePayload() args = (payload, 'attributes', [objects.Attribute(), 0]) self.assertRaisesRegexp( TypeError, "attributes must be a list of attribute objects; " "item 2 has type {0}".format(type(0)), setattr, *args)
def test_repr(self): """ Test that repr can be applied to a GetAttributes response payload. """ payload = get_attributes.GetAttributesResponsePayload( self.uid, self.attributes) uid = "uid={0}".format(payload.uid) payload_attributes = "attributes={0}".format(payload.attributes) expected = "GetAttributesResponsePayload({0}, {1})".format( uid, payload_attributes) observed = repr(payload) self.assertEqual(expected, observed)
def test_write(self): """ Test that a GetAttributes response payload can be written to a data stream. """ payload = get_attributes.GetAttributesResponsePayload( self.uid, 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 = get_attributes.GetAttributesResponsePayload( self.uid, 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 = get_attributes.GetAttributesResponsePayload( self.uid, self.attributes) b = "invalid" self.assertTrue(a != b) self.assertTrue(b != a)
def test_process_get_attributes_batch_item(self): uuid = '00000000-1111-2222-3333-444444444444' attributes = [] payload = get_attributes.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_write_with_no_uid(self): """ Test that a GetAttributes request payload with no ID can be written to a data stream. """ payload = get_attributes.GetAttributesResponsePayload( None, self.attributes) stream = utils.BytearrayStream() args = (stream, ) self.assertRaisesRegexp(exceptions.InvalidField, "The GetAttributes response uid is required.", payload.write, *args)
def test_read_with_no_uid(self): """ Test that an InvalidKmipEncoding error gets raised when attempting to read a GetAttributes response encoding with no ID data. """ payload = get_attributes.GetAttributesResponsePayload() self.assertEqual(None, payload._uid) self.assertEqual(list(), payload._attributes) args = (self.encoding_sans_uid, ) self.assertRaisesRegexp( exceptions.InvalidKmipEncoding, "expected GetAttributes response uid 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 = get_attributes.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_uid(self): """ Test that the uid attribute of a GetAttributes response payload can be properly set and retrieved. """ payload = get_attributes.GetAttributesResponsePayload() self.assertIsNone(payload.uid) self.assertIsNone(payload._uid) payload.uid = 'test-uid' self.assertEqual('test-uid', payload.uid) self.assertEqual( primitives.TextString(value='test-uid', tag=enums.Tags.UNIQUE_IDENTIFIER), payload._uid)
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 = get_attributes.GetAttributesResponsePayload() self.assertEqual(None, payload._uid) self.assertEqual(list(), payload._attributes) payload.read(self.encoding_sans_attributes) self.assertEqual(self.uid, payload.uid) self.assertEqual( primitives.TextString(value=self.uid, tag=enums.Tags.UNIQUE_IDENTIFIER), payload._uid) self.assertEqual(list(), payload.attributes) self.assertEqual(list(), payload._attributes)
def _create_get_attributes_payload(self): return get_attributes.GetAttributesResponsePayload()
def test_init(self): """ Test that a GetAttributes response payload can be constructed. """ get_attributes.GetAttributesResponsePayload()