Example #1
0
    def test_equal_on_not_equal_namespace(self):
        """
        Test that the equality operator returns False when comparing two
        ApplicationSpecificInformation objects with different data.
        """
        a = ApplicationSpecificInformation(
            application_namespace=ApplicationNamespace('test_namespace_1'),
            application_data=ApplicationData('test_data'))
        b = ApplicationSpecificInformation(
            application_namespace=ApplicationNamespace('test_namespace_2'),
            application_data=ApplicationData('test_data'))

        self.assertFalse(a == b)
        self.assertFalse(b == a)
Example #2
0
    def test_not_equal_on_not_equal_data(self):
        """
        Test that the inequality operator returns True when comparing two
        ApplicationSpecificInformation objects with different data.
        """
        a = ApplicationSpecificInformation(
            application_namespace=ApplicationNamespace('test_namespace'),
            application_data=ApplicationData('test_data_1'))
        b = ApplicationSpecificInformation(
            application_namespace=ApplicationNamespace('test_namespace'),
            application_data=ApplicationData('test_data_2'))

        self.assertTrue(a != b)
        self.assertTrue(b != a)
Example #3
0
    def test_equal_on_equal(self):
        """
        Test that the equality operator returns True when comparing two
        ApplicationSpecificInformation objects with the same data.
        """
        a = ApplicationSpecificInformation(
            application_namespace=ApplicationNamespace('test_namespace'),
            application_data=ApplicationData('test_data'))
        b = ApplicationSpecificInformation(
            application_namespace=ApplicationNamespace('test_namespace'),
            application_data=ApplicationData('test_data'))

        self.assertTrue(a == b)
        self.assertTrue(b == a)
Example #4
0
    def test_not_equal_on_equal(self):
        """
        Test that the inequality operator returns False when comparing
        two ApplicationSpecificInformation objects with the same internal
        data.
        """
        a = ApplicationSpecificInformation(
            application_namespace=ApplicationNamespace('test_namespace'),
            application_data=ApplicationData('test_data'))
        b = ApplicationSpecificInformation(
            application_namespace=ApplicationNamespace('test_namespace'),
            application_data=ApplicationData('test_data'))

        self.assertFalse(a != b)
        self.assertFalse(b != a)
Example #5
0
 def test_init_with_args(self):
     """
     Test that an ApplicationSpecificInformation object can be constructed
     with valid values.
     """
     application_namespace = ApplicationNamespace("namespace")
     application_data = ApplicationData("data")
     self._test_init(application_namespace, application_data)
Example #6
0
 def test_read_with_args(self):
     """
     Test that an ApplicationSpecificInformation object with data can be
     read from a data stream.
     """
     application_namespace = ApplicationNamespace("ssl")
     application_data = ApplicationData("www.example.com")
     self._test_read(self.encoding, application_namespace, application_data)
Example #7
0
    def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0):
        """
        Read the data encoding the QueryResponsePayload object and decode it
        into its constituent parts.

        Args:
            istream (Stream): A data stream containing encoded object data,
                supporting a read method; usually a BytearrayStream object.
            kmip_version (KMIPVersion): An enumeration defining the KMIP
                version with which the object will be decoded. Optional,
                defaults to KMIP 1.0.
        """
        super(QueryResponsePayload, self).read(istream,
                                               kmip_version=kmip_version)
        tstream = BytearrayStream(istream.read(self.length))

        while (self.is_tag_next(enums.Tags.OPERATION, tstream)):
            operation = Operation()
            operation.read(tstream, kmip_version=kmip_version)
            self.operations.append(operation)

        while (self.is_tag_next(enums.Tags.OBJECT_TYPE, tstream)):
            object_type = ObjectType()
            object_type.read(tstream, kmip_version=kmip_version)
            self.object_types.append(object_type)

        if self.is_tag_next(enums.Tags.VENDOR_IDENTIFICATION, tstream):
            self.vendor_identification = VendorIdentification()
            self.vendor_identification.read(tstream, kmip_version=kmip_version)

        if self.is_tag_next(enums.Tags.SERVER_INFORMATION, tstream):
            self.server_information = ServerInformation()
            self.server_information.read(tstream, kmip_version=kmip_version)

        while (self.is_tag_next(enums.Tags.APPLICATION_NAMESPACE, tstream)):
            application_namespace = ApplicationNamespace()
            application_namespace.read(tstream, kmip_version=kmip_version)
            self.application_namespaces.append(application_namespace)

        while (self.is_tag_next(enums.Tags.EXTENSION_INFORMATION, tstream)):
            extension_information = ExtensionInformation()
            extension_information.read(tstream, kmip_version=kmip_version)
            self.extension_information.append(extension_information)

        self.is_oversized(tstream)
        self.validate()
Example #8
0
    def read(self, istream):
        """
        Read the data encoding the QueryResponsePayload object and decode it
        into its constituent parts.

        Args:
            istream (Stream): A data stream containing encoded object data,
                supporting a read method; usually a BytearrayStream object.
        """
        super(QueryResponsePayload, self).read(istream)
        tstream = BytearrayStream(istream.read(self.length))

        while(self.is_tag_next(Tags.OPERATION, tstream)):
            operation = Operation()
            operation.read(tstream)
            self.operations.append(operation)

        while(self.is_tag_next(Tags.OBJECT_TYPE, tstream)):
            object_type = ObjectType()
            object_type.read(tstream)
            self.object_types.append(object_type)

        if self.is_tag_next(Tags.VENDOR_IDENTIFICATION, tstream):
            self.vendor_identification = VendorIdentification()
            self.vendor_identification.read(tstream)

        if self.is_tag_next(Tags.SERVER_INFORMATION, tstream):
            self.server_information = ServerInformation()
            self.server_information.read(tstream)

        while(self.is_tag_next(Tags.APPLICATION_NAMESPACE, tstream)):
            application_namespace = ApplicationNamespace()
            application_namespace.read(tstream)
            self.application_namespaces.append(application_namespace)

        while(self.is_tag_next(Tags.EXTENSION_INFORMATION, tstream)):
            extension_information = ExtensionInformation()
            extension_information.read(tstream)
            self.extension_information.append(extension_information)

        self.is_oversized(tstream)
        self.validate()
    def test_validate_on_invalid_application_data(self):
        """
        Test that a TypeError exception is raised when an invalid
        ApplicationData value is used to construct an
        ApplicationSpecificInformation object.
        """
        application_namespace = ApplicationNamespace()
        application_data = "invalid"
        args = [application_namespace, application_data]

        self.assertRaisesRegexp(TypeError, "invalid application data",
                                ApplicationSpecificInformation, *args)
Example #10
0
    def _test_init(self, value):
        if (isinstance(value, str)) or (value is None):
            application_namespace = ApplicationNamespace(value)

            if value is None:
                value = ''

            msg = "expected {0}, observed {1}".format(
                value, application_namespace.value)
            self.assertEqual(value, application_namespace.value, msg)
        else:
            self.assertRaises(TypeError, ApplicationNamespace, value)
Example #11
0
    def test_not_equal_on_type_mismatch(self):
        """
        Test that the equality operator returns True when comparing a
        ApplicationSpecificInformation object to a
        non-ApplicationSpecificInformation object.
        """
        a = ApplicationSpecificInformation(
            application_namespace=ApplicationNamespace('test_namespace'),
            application_data=ApplicationData('test_data'))
        b = "invalid"

        self.assertTrue(a != b)
        self.assertTrue(b != a)
Example #12
0
    def test_repr(self):
        """
        Test that an ApplicationSpecificInformation object can be represented
        using repr correctly.
        """
        application_specific_info = ApplicationSpecificInformation(
            application_namespace=ApplicationNamespace("ssl"),
            application_data=ApplicationData("www.example.com"))
        s = repr(application_specific_info)

        self.assertEqual(
            "ApplicationSpecificInformation("
            "application_namespace=ApplicationNamespace(value='ssl'), "
            "application_data=ApplicationData(value='www.example.com'))", s)
Example #13
0
    def test_str(self):
        """
        Test that an ApplicationSpecificInformation object can be turned into
        a string correctly.
        """
        application_specific_info = ApplicationSpecificInformation(
            application_namespace=ApplicationNamespace("ssl"),
            application_data=ApplicationData("www.example.com"))
        s = str(application_specific_info)

        self.assertEqual(
            str({
                'application_namespace': 'ssl',
                'application_data': 'www.example.com'
            }), s)
Example #14
0
    def _test_create(self, application_namespace, application_data):
        application_specific_info = ApplicationSpecificInformation.create(
            application_namespace, application_data)

        self.assertIsInstance(
            application_specific_info, ApplicationSpecificInformation)

        expected = ApplicationNamespace(application_namespace)
        observed = application_specific_info.application_namespace

        msg = "expected {0}, observed {1}".format(expected, observed)
        self.assertEqual(expected, observed, msg)

        expected = ApplicationData(application_data)
        observed = application_specific_info.application_data

        msg = "expected {0}, observed {1}".format(expected, observed)
        self.assertEqual(expected, observed, msg)
    def _test_init(self, application_namespace, application_data):
        application_specific_information = ApplicationSpecificInformation(
            application_namespace=application_namespace,
            application_data=application_data)

        if application_namespace is None:
            self.assertEqual(
                ApplicationNamespace(),
                application_specific_information.application_namespace)
        else:
            self.assertEqual(
                application_namespace,
                application_specific_information.application_namespace)

        if application_data is None:
            self.assertEqual(ApplicationData(),
                             application_specific_information.application_data)
        else:
            self.assertEqual(application_data,
                             application_specific_information.application_data)
Example #16
0
    def _test_read(self, stream, application_namespace, application_data):
        application_specific_information = ApplicationSpecificInformation()
        application_specific_information.read(stream)

        if application_namespace is None:
            application_namespace = ApplicationNamespace()
        if application_data is None:
            application_data = ApplicationData()

        msg = "application namespace encoding mismatch"
        msg += "; expected {0}, observed {1}".format(
            application_namespace,
            application_specific_information.application_namespace)
        self.assertEqual(
            application_namespace,
            application_specific_information.application_namespace, msg)

        msg = "application data encoding mismatch"
        msg += "; expected {0}, observed {1}".format(
            application_data,
            application_specific_information.application_data)
        self.assertEqual(
            application_data,
            application_specific_information.application_data, msg)