Ejemplo n.º 1
0
    def test_not_equal_on_not_equal_attribute_names(self):
        """
        Test that the inequality operator returns True when comparing two
        GetAttributes request payloads with different attribute names.
        """
        a = payloads.GetAttributesRequestPayload(self.unique_identifier,
                                                 self.attribute_names)
        b = payloads.GetAttributesRequestPayload(self.unique_identifier, None)

        self.assertTrue(a != b)
        self.assertTrue(b != a)
Ejemplo n.º 2
0
    def test_equal_on_not_equal_unique_identifier(self):
        """
        Test that the equality operator returns False when comparing two
        GetAttributes request payloads with different IDs.
        """
        a = payloads.GetAttributesRequestPayload(self.unique_identifier,
                                                 self.attribute_names)
        b = payloads.GetAttributesRequestPayload('invalid',
                                                 self.attribute_names)

        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
        GetAttributes request payloads with the same data.
        """
        a = payloads.GetAttributesRequestPayload(self.unique_identifier,
                                                 self.attribute_names)
        b = payloads.GetAttributesRequestPayload(self.unique_identifier,
                                                 self.attribute_names)

        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 GetAttributes request payloads with the same internal data.
        """
        a = payloads.GetAttributesRequestPayload(self.unique_identifier,
                                                 self.attribute_names)
        b = payloads.GetAttributesRequestPayload(self.unique_identifier,
                                                 self.attribute_names)

        self.assertFalse(a != b)
        self.assertFalse(b != a)
Ejemplo n.º 5
0
    def test_equal_with_mixed_attribute_names(self):
        """
        Test that the equality operator returns True when comparing two
        GetAttributes request payload with the same attribute_name sets
        but with different attribute name orderings.
        """
        a = payloads.GetAttributesRequestPayload(self.unique_identifier,
                                                 self.attribute_names)
        self.attribute_names.reverse()
        b = payloads.GetAttributesRequestPayload(self.unique_identifier,
                                                 self.attribute_names)

        self.assertTrue(a == b)
        self.assertTrue(b == a)
Ejemplo n.º 6
0
    def test_attribute_names(self):
        """
        Test that the attribute_names attribute of a GetAttributes request
        payload can be properly set and retrieved.
        """
        payload = payloads.GetAttributesRequestPayload()

        self.assertEqual(list(), payload.attribute_names)
        self.assertEqual(list(), payload._attribute_names)

        payload.attribute_names = [
            'test-attribute-name-1', 'test-attribute-name-2'
        ]

        self.assertEqual(2, len(payload.attribute_names))
        self.assertEqual(2, len(payload._attribute_names))
        self.assertIn('test-attribute-name-1', payload.attribute_names)
        self.assertIn('test-attribute-name-2', payload.attribute_names)
        self.assertIn(
            primitives.TextString(value='test-attribute-name-1',
                                  tag=enums.Tags.ATTRIBUTE_NAME),
            payload._attribute_names)
        self.assertIn(
            primitives.TextString(value='test-attribute-name-2',
                                  tag=enums.Tags.ATTRIBUTE_NAME),
            payload._attribute_names)
Ejemplo n.º 7
0
    def test_attribute_names_with_duplicates(self):
        """
        Test that duplicate attribute names are silently removed when setting
        the attribute_names attribute of a GetAttributes request payload.
        """
        payload = payloads.GetAttributesRequestPayload()

        self.assertEqual(list(), payload.attribute_names)
        self.assertEqual(list(), payload._attribute_names)

        payload.attribute_names = [
            'test-attribute-name-1', 'test-attribute-name-1',
            'test-attribute-name-2'
        ]

        self.assertEqual(2, len(payload.attribute_names))
        self.assertEqual(2, len(payload._attribute_names))
        self.assertIn('test-attribute-name-1', payload.attribute_names)
        self.assertIn('test-attribute-name-2', payload.attribute_names)
        self.assertIn(
            primitives.TextString(value='test-attribute-name-1',
                                  tag=enums.Tags.ATTRIBUTE_NAME),
            payload._attribute_names)
        self.assertIn(
            primitives.TextString(value='test-attribute-name-2',
                                  tag=enums.Tags.ATTRIBUTE_NAME),
            payload._attribute_names)
Ejemplo n.º 8
0
 def test_init_with_args(self):
     """
     Test that a GetAttributes request payload can be constructed with a
     valid value.
     """
     payloads.GetAttributesRequestPayload(
         'test-unique-identifier',
         ['test-attribute-name-1', 'test-attribute-name-2'])
Ejemplo n.º 9
0
 def test_unique_identifier_with_invalid_value(self):
     """
     Test that a TypeError is raised when an invalid ID is used to set
     the unique_identifier attribute of a GetAttributes request payload.
     """
     payload = payloads.GetAttributesRequestPayload()
     args = (payload, 'unique_identifier', 0)
     self.assertRaisesRegex(TypeError, "unique identifier must be a string",
                            setattr, *args)
Ejemplo n.º 10
0
 def test_str_with_no_content(self):
     """
     Test that str can be applied to a GetAttributes request payload with
     no ID or attribute names.
     """
     payload = payloads.GetAttributesRequestPayload(None, None)
     expected = str({'unique_identifier': None, 'attribute_names': list()})
     observed = str(payload)
     self.assertEqual(expected, observed)
Ejemplo n.º 11
0
 def test_attribute_names_with_invalid_value(self):
     """
     Test that a TypeError is raised when an invalid list is used to set
     the attribute_names attribute of a GetAttributes request payload.
     """
     payload = payloads.GetAttributesRequestPayload()
     args = (payload, 'attribute_names', 0)
     self.assertRaisesRegex(TypeError,
                            "attribute_names must be a list of strings",
                            setattr, *args)
Ejemplo n.º 12
0
    def test_write_with_no_content(self):
        """
        Test that a GetAttributes request payload with no ID or attribute
        names can be written to a data stream.
        """
        payload = payloads.GetAttributesRequestPayload()
        stream = utils.BytearrayStream()
        payload.write(stream)

        self.assertEqual(len(self.empty_encoding), len(stream))
        self.assertEqual(str(self.empty_encoding), str(stream))
Ejemplo n.º 13
0
 def test_attribute_names_with_invalid_attribute_name(self):
     """
     Test that a TypeError is raised when an invalid attribute name is
     included in the list used to set the attribute_names attribute of a
     GetAttributes request payload.
     """
     payload = payloads.GetAttributesRequestPayload()
     args = (payload, 'attribute_names', ['test-attribute-name-1', 0])
     self.assertRaisesRegex(
         TypeError, "attribute_names must be a list of strings; "
         "item 2 has type {0}".format(type(0)), setattr, *args)
Ejemplo n.º 14
0
 def test_str(self):
     """
     Test that str can be applied to a GetAttributes request payload.
     """
     payload = payloads.GetAttributesRequestPayload(self.unique_identifier,
                                                    self.attribute_names)
     expected = str({
         'unique_identifier': self.unique_identifier,
         'attribute_names': self.attribute_names
     })
     observed = str(payload)
     self.assertEqual(expected, observed)
Ejemplo n.º 15
0
    def test_write_with_no_attribute_names(self):
        """
        Test that a GetAttributes request payload with no attribute names
        can be written to a data stream.
        """
        payload = payloads.GetAttributesRequestPayload(self.unique_identifier,
                                                       None)
        stream = utils.BytearrayStream()
        payload.write(stream)

        self.assertEqual(len(self.encoding_sans_attribute_names), len(stream))
        self.assertEqual(str(self.encoding_sans_attribute_names), str(stream))
Ejemplo n.º 16
0
    def test_write(self):
        """
        Test that a GetAttributes request payload can be written to a data
        stream.
        """
        payload = payloads.GetAttributesRequestPayload(self.unique_identifier,
                                                       self.attribute_names)
        stream = utils.BytearrayStream()
        payload.write(stream)

        self.assertEqual(len(self.full_encoding), len(stream))
        self.assertEqual(str(self.full_encoding), str(stream))
Ejemplo n.º 17
0
    def test_not_equal_on_type_mismatch(self):
        """
        Test that the equality operator returns True when comparing a
        GetAttributes request payload to a non-GetAttributes request
        payload.
        """
        a = payloads.GetAttributesRequestPayload(self.unique_identifier,
                                                 self.attribute_names)
        b = "invalid"

        self.assertTrue(a != b)
        self.assertTrue(b != a)
Ejemplo n.º 18
0
 def test_repr_with_no_content(self):
     """
     Test that repr can be applied to a GetAttributes request payload with
     no ID or attribute names.
     """
     payload = payloads.GetAttributesRequestPayload(None, None)
     unique_identifier = "unique_identifier={0}".format(
         payload.unique_identifier)
     attribute_names = "attribute_names={0}".format(payload.attribute_names)
     expected = "GetAttributesRequestPayload({0}, {1})".format(
         unique_identifier, attribute_names)
     observed = repr(payload)
     self.assertEqual(expected, observed)
Ejemplo n.º 19
0
    def test_read_with_no_content(self):
        """
        Test that a GetAttributes request payload with no ID or attribute
        names can be read from a data stream.
        """
        payload = payloads.GetAttributesRequestPayload()

        self.assertEqual(None, payload._unique_identifier)
        self.assertEqual(list(), payload._attribute_names)

        payload.read(self.empty_encoding)

        self.assertEqual(None, payload.unique_identifier)
        self.assertEqual(None, payload._unique_identifier)
        self.assertEqual(list(), payload.attribute_names)
        self.assertEqual(list(), payload._attribute_names)
Ejemplo n.º 20
0
    def test_unique_identifier(self):
        """
        Test that the unique_identifier attribute of a GetAttributes request
        payload can be properly set and retrieved.
        """
        payload = payloads.GetAttributesRequestPayload()

        self.assertIsNone(payload.unique_identifier)
        self.assertIsNone(payload._unique_identifier)

        payload.unique_identifier = 'test-unique-identifier'

        self.assertEqual('test-unique-identifier', payload.unique_identifier)
        self.assertEqual(
            primitives.TextString(value='test-unique-identifier',
                                  tag=enums.Tags.UNIQUE_IDENTIFIER),
            payload._unique_identifier)
Ejemplo n.º 21
0
    def test_read_with_no_attribute_names(self):
        """
        Test that a GetAttributes request payload with no attribute names
        can be read from a data stream.
        """
        payload = payloads.GetAttributesRequestPayload()

        self.assertEqual(None, payload._unique_identifier)
        self.assertEqual(list(), payload._attribute_names)

        payload.read(self.encoding_sans_attribute_names)

        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(list(), payload.attribute_names)
        self.assertEqual(list(), payload._attribute_names)
Ejemplo n.º 22
0
    def test_read_with_no_unique_identifier(self):
        """
        Test that a GetAttributes request payload with no ID can be read
        from a data stream.
        """
        payload = payloads.GetAttributesRequestPayload()

        self.assertEqual(None, payload._unique_identifier)
        self.assertEqual(list(), payload._attribute_names)

        payload.read(self.encoding_sans_unique_identifier)

        self.assertEqual(None, payload.unique_identifier)
        self.assertEqual(None, payload._unique_identifier)
        self.assertEqual(set(self.attribute_names),
                         set(payload.attribute_names))
        for attribute_name in self.attribute_names:
            self.assertIn(
                primitives.TextString(value=attribute_name,
                                      tag=enums.Tags.ATTRIBUTE_NAME),
                payload._attribute_names)
Ejemplo n.º 23
0
    def test_read(self):
        """
        Test that a GetAttributes request payload can be read from a data
        stream.
        """
        payload = payloads.GetAttributesRequestPayload()

        self.assertEqual(None, payload._unique_identifier)
        self.assertEqual(list(), payload._attribute_names)

        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(set(self.attribute_names),
                         set(payload.attribute_names))
        for attribute_name in self.attribute_names:
            self.assertIn(
                primitives.TextString(value=attribute_name,
                                      tag=enums.Tags.ATTRIBUTE_NAME),
                payload._attribute_names)
Ejemplo n.º 24
0
 def _create_get_attributes_payload(self):
     return payloads.GetAttributesRequestPayload()
Ejemplo n.º 25
0
 def test_init(self):
     """
     Test that a GetAttributes request payload can be constructed with
     no arguments.
     """
     payloads.GetAttributesRequestPayload()