Ejemplo n.º 1
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)
Ejemplo n.º 2
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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
    def test_validate_on_invalid_application_namespace(self):
        """
        Test that a TypeError exception is raised when an invalid
        ApplicationNamespace value is used to construct an
        ApplicationSpecificInformation object.
        """
        application_namespace = "invalid"
        application_data = ApplicationData()
        args = [application_namespace, application_data]

        self.assertRaisesRegexp(TypeError, "invalid application namespace",
                                ApplicationSpecificInformation, *args)
Ejemplo n.º 8
0
    def _test_init(self, value):
        if (isinstance(value, str)) or (value is None):
            application_data = ApplicationData(value)

            if value is None:
                value = ''

            msg = "expected {0}, observed {1}".format(value,
                                                      application_data.value)
            self.assertEqual(value, application_data.value, msg)
        else:
            self.assertRaises(TypeError, ApplicationData, value)
Ejemplo n.º 9
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)
Ejemplo n.º 10
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)
Ejemplo n.º 11
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)
Ejemplo n.º 12
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)
Ejemplo n.º 14
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)