Beispiel #1
0
    def test_not_equal_on_not_equal_unique_identifier(self):
        """
        Test that the inequality operator returns True when comparing two
        Archive response payloads with different unique identifiers.
        """
        a = payloads.ArchiveResponsePayload(unique_identifier='a')
        b = payloads.ArchiveResponsePayload(unique_identifier='b')

        self.assertTrue(a != b)
        self.assertTrue(b != a)
Beispiel #2
0
    def test_init(self):
        """
        Test that an Archive response payload can be constructed with no
        arguments.
        """
        payload = payloads.ArchiveResponsePayload()

        self.assertEqual(None, payload.unique_identifier)
Beispiel #3
0
    def test_not_equal_on_equal(self):
        """
        Test that the inequality operator returns False when comparing two
        Archive response payloads with the same data.
        """
        a = payloads.ArchiveResponsePayload()
        b = payloads.ArchiveResponsePayload()

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

        a = payloads.ArchiveResponsePayload(
            unique_identifier='49a1ca88-6bea-4fb2-b450-7e58802c3038')
        b = payloads.ArchiveResponsePayload(
            unique_identifier='49a1ca88-6bea-4fb2-b450-7e58802c3038')

        self.assertFalse(a != b)
        self.assertFalse(b != a)
Beispiel #4
0
    def test_not_equal_on_type_mismatch(self):
        """
        Test that the inequality operator returns True when comparing two
        Archive response payloads with different types.
        """
        a = payloads.ArchiveResponsePayload()
        b = 'invalid'

        self.assertTrue(a != b)
        self.assertTrue(b != a)
Beispiel #5
0
    def test_init_with_args(self):
        """
        Test that an Archive response payload can be constructed with valid
        values.
        """
        payload = payloads.ArchiveResponsePayload(
            unique_identifier='00000000-1111-2222-3333-444444444444')

        self.assertEqual('00000000-1111-2222-3333-444444444444',
                         payload.unique_identifier)
Beispiel #6
0
    def test_write_empty(self):
        """
        Test that an empty Archive response payload can be written to a data
        stream.
        """
        payload = payloads.ArchiveResponsePayload()
        stream = utils.BytearrayStream()
        payload.write(stream)

        self.assertEqual(len(self.empty_encoding), len(stream))
        self.assertEqual(str(self.empty_encoding), str(stream))
Beispiel #7
0
    def test_write(self):
        """
        Test that an Archive response payload can be written to a data stream.
        """
        payload = payloads.ArchiveResponsePayload(
            unique_identifier='f613dba1-b557-489a-87c5-3c0ecd4294e3')
        stream = utils.BytearrayStream()
        payload.write(stream)

        self.assertEqual(len(self.full_encoding), len(stream))
        self.assertEqual(str(self.full_encoding), str(stream))
Beispiel #8
0
    def test_str(self):
        """
        Test that str can be applied to a Archive response payload
        """
        payload = payloads.ArchiveResponsePayload(
            unique_identifier='49a1ca88-6bea-4fb2-b450-7e58802c3038')

        expected = str(
            {'unique_identifier': '49a1ca88-6bea-4fb2-b450-7e58802c3038'})
        observed = str(payload)

        self.assertEqual(expected, observed)
Beispiel #9
0
    def test_repr(self):
        """
        Test that repr can be applied to a Archive response payload.
        """
        payload = payloads.ArchiveResponsePayload(
            unique_identifier='49a1ca88-6bea-4fb2-b450-7e58802c3038')
        expected = (
            "ArchiveResponsePayload("
            "unique_identifier='49a1ca88-6bea-4fb2-b450-7e58802c3038')")
        observed = repr(payload)

        self.assertEqual(expected, observed)
Beispiel #10
0
    def test_read_empty(self):
        """
        Test that an Archive response payload can be read from an empty data
        stream.
        """
        payload = payloads.ArchiveResponsePayload()

        self.assertEqual(None, payload.unique_identifier)

        payload.read(self.empty_encoding)

        self.assertEqual(None, payload.unique_identifier)
Beispiel #11
0
    def test_read(self):
        """
        Test that an Archive response payload can be read from a data stream.
        """
        payload = payloads.ArchiveResponsePayload()

        self.assertEqual(None, payload.unique_identifier)

        payload.read(self.full_encoding)

        self.assertEqual('f613dba1-b557-489a-87c5-3c0ecd4294e3',
                         payload.unique_identifier)
Beispiel #12
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 an Archive response payload.
        """
        kwargs = {'unique_identifier': 0}
        self.assertRaisesRegex(TypeError,
                               "Unique identifier must be a string.",
                               payloads.ArchiveResponsePayload, **kwargs)

        payload = payloads.ArchiveResponsePayload()
        args = (payload, 'unique_identifier', 0)
        self.assertRaisesRegex(TypeError,
                               "Unique identifier must be a string.", setattr,
                               *args)