Ejemplo n.º 1
0
    def test_comparison(self):
        """
        Test that the equality/inequality operators return True/False when
        comparing two ModifyAttribute response payloads with the same data.
        """
        a = payloads.ModifyAttributeResponsePayload()
        b = payloads.ModifyAttributeResponsePayload()

        self.assertTrue(a == b)
        self.assertTrue(b == a)
        self.assertFalse(a != b)
        self.assertFalse(b != a)

        a = payloads.ModifyAttributeResponsePayload(
            unique_identifier="b4faee10-aa2a-4446-8ad4-0881f3422959",
            attribute=objects.Attribute(
                attribute_name=objects.Attribute.AttributeName("x-attribute1"),
                attribute_value=primitives.TextString(
                    value="ModifiedValue1", tag=enums.Tags.ATTRIBUTE_VALUE)))
        b = payloads.ModifyAttributeResponsePayload(
            unique_identifier="b4faee10-aa2a-4446-8ad4-0881f3422959",
            attribute=objects.Attribute(
                attribute_name=objects.Attribute.AttributeName("x-attribute1"),
                attribute_value=primitives.TextString(
                    value="ModifiedValue1", tag=enums.Tags.ATTRIBUTE_VALUE)))

        self.assertTrue(a == b)
        self.assertTrue(b == a)
        self.assertFalse(a != b)
        self.assertFalse(b != a)
Ejemplo n.º 2
0
    def test_comparison_on_different_unique_identifiers(self):
        """
        Test that the equality/inequality operators return False/True when
        comparing two ModifyAttribute response payloads with different unique
        identifiers.
        """
        a = payloads.ModifyAttributeResponsePayload(unique_identifier="1")
        b = payloads.ModifyAttributeResponsePayload(unique_identifier="2")

        self.assertFalse(a == b)
        self.assertFalse(b == a)
        self.assertTrue(a != b)
        self.assertTrue(b != a)
Ejemplo n.º 3
0
 def test_str(self):
     """
     Test that str can be applied to a ModifyAttribute response payload.
     """
     payload = payloads.ModifyAttributeResponsePayload(
         unique_identifier="b4faee10-aa2a-4446-8ad4-0881f3422959")
     s = str({
         "unique_identifier": "b4faee10-aa2a-4446-8ad4-0881f3422959",
         "attribute": None
     })
     self.assertEqual(s, str(payload))
Ejemplo n.º 4
0
    def test_comparison_on_different_attributes(self):
        """
        Test that the equality/inequality operators return False/True when
        comparing two ModifyAttribute response payloads with different
        attributes.
        """
        a = payloads.ModifyAttributeResponsePayload(
            attribute=objects.Attribute(
                attribute_name=objects.Attribute.AttributeName("x-attribute1"),
                attribute_value=primitives.TextString(
                    value="ModifiedValue1", tag=enums.Tags.ATTRIBUTE_VALUE)))
        b = payloads.ModifyAttributeResponsePayload(
            attribute=objects.Attribute(
                attribute_name=objects.Attribute.AttributeName("x-attribute2"),
                attribute_value=primitives.TextString(
                    value="ModifiedValue2", tag=enums.Tags.ATTRIBUTE_VALUE)))

        self.assertFalse(a == b)
        self.assertFalse(b == a)
        self.assertTrue(a != b)
        self.assertTrue(b != a)
Ejemplo n.º 5
0
 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 ModifyAttribute response payload.
     """
     payload = payloads.ModifyAttributeResponsePayload()
     args = (self.empty_encoding, )
     self.assertRaisesRegex(
         exceptions.InvalidKmipEncoding,
         "The ModifyAttribute response payload encoding is missing the "
         "unique identifier field.", payload.read, *args)
Ejemplo n.º 6
0
 def test_read_no_attribute(self):
     """
     Test that an InvalidKmipEncoding error is raised when an invalid
     encoding containing no encoded attribute is used to decode a
     ModifyAttribute response payload.
     """
     payload = payloads.ModifyAttributeResponsePayload()
     args = (self.full_encoding_kmip_2_0, )
     self.assertRaisesRegex(
         exceptions.InvalidKmipEncoding,
         "The ModifyAttribute response payload encoding is missing the "
         "attribute field.", payload.read, *args)
Ejemplo n.º 7
0
    def test_comparison_on_type_mismatch(self):
        """
        Test that the equality/inequality operators return False/True when
        comparining a ModifyAttribute response payload against a different
        type.
        """
        a = payloads.ModifyAttributeResponsePayload()
        b = "invalid"

        self.assertFalse(a == b)
        self.assertFalse(b == a)
        self.assertTrue(a != b)
        self.assertTrue(b != a)
Ejemplo n.º 8
0
    def test_write_no_unique_identifier(self):
        """
        Test that an InvalidField error is raised when attempting to write
        a ModifyAttribute response payload to a buffer with no unique
        identifier field specified.
        """
        payload = payloads.ModifyAttributeResponsePayload()

        args = (utils.BytearrayStream(), )
        self.assertRaisesRegex(
            exceptions.InvalidField,
            "The ModifyAttribute response payload is missing the unique "
            "identifier field.", payload.write, *args)
Ejemplo n.º 9
0
    def test_write_kmip_2_0(self):
        """
        Test that a ModifyAttribute response payload can be written to a
        buffer with KMIP 2.0 fields.
        """
        payload = payloads.ModifyAttributeResponsePayload(
            unique_identifier="b4faee10-aa2a-4446-8ad4-0881f3422959")

        buffer = utils.BytearrayStream()
        payload.write(buffer, kmip_version=enums.KMIPVersion.KMIP_2_0)

        self.assertEqual(len(self.full_encoding_kmip_2_0), len(buffer))
        self.assertEqual(str(self.full_encoding_kmip_2_0), str(buffer))
Ejemplo n.º 10
0
    def test_repr(self):
        """
        Test that repr can be applied to a ModifyAttribute response payload.
        """
        payload = payloads.ModifyAttributeResponsePayload(
            unique_identifier="b4faee10-aa2a-4446-8ad4-0881f3422959")

        args = [
            "unique_identifier='b4faee10-aa2a-4446-8ad4-0881f3422959'",
            "attribute=None"
        ]
        self.assertEqual(
            "ModifyAttributeResponsePayload({})".format(", ".join(args)),
            repr(payload))
Ejemplo n.º 11
0
    def test_read_kmip_2_0(self):
        """
        Test that a ModifyAttribute response payload can be read from a buffer.
        """
        payload = payloads.ModifyAttributeResponsePayload()

        self.assertIsNone(payload.unique_identifier)
        self.assertIsNone(payload.attribute)

        payload.read(self.full_encoding_kmip_2_0,
                     kmip_version=enums.KMIPVersion.KMIP_2_0)

        self.assertEqual("b4faee10-aa2a-4446-8ad4-0881f3422959",
                         payload.unique_identifier)
        self.assertIsNone(payload.attribute)
Ejemplo n.º 12
0
    def test_invalid_attribute(self):
        """
        Test that a TypeError is raised when an invalid value is used to set
        the attribute of a ModifyAttribute response payload.
        """
        kwargs = {"attribute": "invalid"}
        self.assertRaisesRegex(TypeError,
                               "The attribute must be an Attribute object.",
                               payloads.ModifyAttributeResponsePayload,
                               **kwargs)

        args = (payloads.ModifyAttributeResponsePayload(), "attribute",
                "invalid")
        self.assertRaisesRegex(TypeError,
                               "The attribute must be an Attribute object.",
                               setattr, *args)
Ejemplo n.º 13
0
    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 ModifyAttribute response payload.
        """
        kwargs = {"unique_identifier": 0}
        self.assertRaisesRegex(TypeError,
                               "The unique identifier must be a string.",
                               payloads.ModifyAttributeResponsePayload,
                               **kwargs)

        args = (payloads.ModifyAttributeResponsePayload(), "unique_identifier",
                0)
        self.assertRaisesRegex(TypeError,
                               "The unique identifier must be a string.",
                               setattr, *args)
Ejemplo n.º 14
0
    def test_write(self):
        """
        Test that a ModifyAttribute response payload can be written to a
        buffer.
        """
        payload = payloads.ModifyAttributeResponsePayload(
            unique_identifier="b4faee10-aa2a-4446-8ad4-0881f3422959",
            attribute=objects.Attribute(
                attribute_name=objects.Attribute.AttributeName("x-attribute1"),
                attribute_value=primitives.TextString(
                    value="ModifiedValue1", tag=enums.Tags.ATTRIBUTE_VALUE)))

        buffer = utils.BytearrayStream()
        payload.write(buffer)

        self.assertEqual(len(self.full_encoding), len(buffer))
        self.assertEqual(str(self.full_encoding), str(buffer))
Ejemplo n.º 15
0
    def test_read(self):
        """
        Test that a ModifyAttribute response payload can be read from a buffer.
        """
        payload = payloads.ModifyAttributeResponsePayload()

        self.assertIsNone(payload.unique_identifier)
        self.assertIsNone(payload.attribute)

        payload.read(self.full_encoding)

        self.assertEqual("b4faee10-aa2a-4446-8ad4-0881f3422959",
                         payload.unique_identifier)
        self.assertEqual(
            objects.Attribute(
                attribute_name=objects.Attribute.AttributeName("x-attribute1"),
                attribute_value=primitives.TextString(
                    value="ModifiedValue1", tag=enums.Tags.ATTRIBUTE_VALUE)),
            payload.attribute)
Ejemplo n.º 16
0
 def _create_modify_attribute_payload(self):
     return payloads.ModifyAttributeResponsePayload()