Beispiel #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 = get_attributes.GetAttributesRequestPayload(self.uid,
                                                       self.attribute_names)
        b = get_attributes.GetAttributesRequestPayload(self.uid, None)

        self.assertTrue(a != b)
        self.assertTrue(b != a)
Beispiel #2
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 = get_attributes.GetAttributesRequestPayload(self.uid,
                                                       self.attribute_names)
        b = get_attributes.GetAttributesRequestPayload(self.uid,
                                                       self.attribute_names)

        self.assertTrue(a == b)
        self.assertTrue(b == a)
Beispiel #3
0
    def test_equal_on_not_equal_uid(self):
        """
        Test that the equality operator returns False when comparing two
        GetAttributes request payloads with different IDs.
        """
        a = get_attributes.GetAttributesRequestPayload(self.uid,
                                                       self.attribute_names)
        b = get_attributes.GetAttributesRequestPayload('invalid',
                                                       self.attribute_names)

        self.assertFalse(a == b)
        self.assertFalse(b == a)
Beispiel #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 = get_attributes.GetAttributesRequestPayload(self.uid,
                                                       self.attribute_names)
        b = get_attributes.GetAttributesRequestPayload(self.uid,
                                                       self.attribute_names)

        self.assertFalse(a != b)
        self.assertFalse(b != a)
Beispiel #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 = get_attributes.GetAttributesRequestPayload(self.uid,
                                                       self.attribute_names)
        self.attribute_names.reverse()
        b = get_attributes.GetAttributesRequestPayload(self.uid,
                                                       self.attribute_names)

        self.assertTrue(a == b)
        self.assertTrue(b == a)
Beispiel #6
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 = get_attributes.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)
Beispiel #7
0
    def test_attribute_names(self):
        """
        Test that the attribute_names attribute of a GetAttributes request
        payload can be properly set and retrieved.
        """
        payload = get_attributes.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)
Beispiel #8
0
    def test_not_equal_on_not_equal_unique_identifier(self):
        """
        Test that the inequality operator returns True when comparing two
        GetAttributes request payloads with different IDs.
        """
        a = get_attributes.GetAttributesRequestPayload(
            self.unique_identifier,
            self.attribute_names
        )
        b = get_attributes.GetAttributesRequestPayload(
            'invalid',
            self.attribute_names
        )

        self.assertTrue(a != b)
        self.assertTrue(b != a)
Beispiel #9
0
    def test_equal_on_not_equal_attribute_names(self):
        """
        Test that the equality operator returns False when comparing two
        GetAttributes request payloads with different attribute names.
        """
        a = get_attributes.GetAttributesRequestPayload(
            self.unique_identifier,
            self.attribute_names
        )
        b = get_attributes.GetAttributesRequestPayload(
            self.unique_identifier,
            None
        )

        self.assertFalse(a == b)
        self.assertFalse(b == a)
Beispiel #10
0
 def test_init_with_args(self):
     """
     Test that a GetAttributes request payload can be constructed with a
     valid value.
     """
     get_attributes.GetAttributesRequestPayload(
         'test-uid', ['test-attribute-name-1', 'test-attribute-name-2'])
Beispiel #11
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 = get_attributes.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
            )
Beispiel #12
0
    def test_read(self):
        """
        Test that a GetAttributes request payload can be read from a data
        stream.
        """
        payload = get_attributes.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
            )
Beispiel #13
0
 def test_uid_with_invalid_value(self):
     """
     Test that a TypeError is raised when an invalid ID is used to set
     the uid attribute of a GetAttributes request payload.
     """
     payload = get_attributes.GetAttributesRequestPayload()
     args = (payload, 'uid', 0)
     self.assertRaisesRegexp(TypeError, "uid must be a string", setattr,
                             *args)
Beispiel #14
0
 def _build_get_attributes_batch_item(self,
                                      uuid=None,
                                      attribute_names=None):
     operation = Operation(OperationEnum.GET_ATTRIBUTES)
     payload = get_attributes.GetAttributesRequestPayload(
         uuid, attribute_names)
     batch_item = messages.RequestBatchItem(operation=operation,
                                            request_payload=payload)
     return batch_item
Beispiel #15
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 = get_attributes.GetAttributesRequestPayload(None, None)
     expected = str({'uid': None, 'attribute_names': list()})
     observed = str(payload)
     self.assertEqual(expected, observed)
Beispiel #16
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 = get_attributes.GetAttributesRequestPayload()
     args = (payload, 'attribute_names', 0)
     self.assertRaisesRegexp(TypeError,
                             "attribute_names must be a list of strings",
                             setattr, *args)
Beispiel #17
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 = get_attributes.GetAttributesRequestPayload()
     args = (payload, 'attribute_names', ['test-attribute-name-1', 0])
     self.assertRaisesRegexp(
         TypeError, "attribute_names must be a list of strings; "
         "item 2 has type {0}".format(type(0)), setattr, *args)
Beispiel #18
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 = get_attributes.GetAttributesRequestPayload()
        stream = utils.BytearrayStream()
        payload.write(stream)

        self.assertEqual(len(self.empty_encoding), len(stream))
        self.assertEqual(str(self.empty_encoding), str(stream))
Beispiel #19
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 = get_attributes.GetAttributesRequestPayload(self.uid, 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))
Beispiel #20
0
    def test_write(self):
        """
        Test that a GetAttributes request payload can be written to a data
        stream.
        """
        payload = get_attributes.GetAttributesRequestPayload(
            self.uid, 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))
Beispiel #21
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 = get_attributes.GetAttributesRequestPayload(self.uid,
                                                       self.attribute_names)
        b = "invalid"

        self.assertTrue(a != b)
        self.assertTrue(b != a)
Beispiel #22
0
 def test_str(self):
     """
     Test that str can be applied to a GetAttributes request payload.
     """
     payload = get_attributes.GetAttributesRequestPayload(
         self.uid, self.attribute_names)
     expected = str({
         'uid': self.uid,
         'attribute_names': self.attribute_names
     })
     observed = str(payload)
     self.assertEqual(expected, observed)
Beispiel #23
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 = get_attributes.GetAttributesRequestPayload(None, None)
     uid = "uid={0}".format(payload.uid)
     attribute_names = "attribute_names={0}".format(payload.attribute_names)
     expected = "GetAttributesRequestPayload({0}, {1})".format(
         uid, attribute_names)
     observed = repr(payload)
     self.assertEqual(expected, observed)
Beispiel #24
0
    def test_equal_on_type_mismatch(self):
        """
        Test that the equality operator returns False when comparing a
        GetAttributes request payload to a non-GetAttributes request
        payload.
        """
        a = get_attributes.GetAttributesRequestPayload(
            self.unique_identifier,
            self.attribute_names
        )
        b = "invalid"

        self.assertFalse(a == b)
        self.assertFalse(b == a)
Beispiel #25
0
 def test_str_with_no_attribute_names(self):
     """
     Test that str can be applied to a GetAttributes request payload with
     no attribute names.
     """
     payload = get_attributes.GetAttributesRequestPayload(
         self.unique_identifier,
         None
     )
     expected = str({
         'unique_identifier': self.unique_identifier,
         'attribute_names': list()
     })
     observed = str(payload)
     self.assertEqual(expected, observed)
Beispiel #26
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 = get_attributes.GetAttributesRequestPayload()

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

        payload.read(self.empty_encoding)

        self.assertEqual(None, payload.uid)
        self.assertEqual(None, payload._uid)
        self.assertEqual(list(), payload.attribute_names)
        self.assertEqual(list(), payload._attribute_names)
Beispiel #27
0
    def test_uid(self):
        """
        Test that the uid attribute of a GetAttributes request payload can
        be properly set and retrieved.
        """
        payload = get_attributes.GetAttributesRequestPayload()

        self.assertIsNone(payload.uid)
        self.assertIsNone(payload._uid)

        payload.uid = 'test-uid'

        self.assertEqual('test-uid', payload.uid)
        self.assertEqual(
            primitives.TextString(value='test-uid',
                                  tag=enums.Tags.UNIQUE_IDENTIFIER),
            payload._uid)
Beispiel #28
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 = get_attributes.GetAttributesRequestPayload()

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

        payload.read(self.encoding_sans_attribute_names)

        self.assertEqual(self.uid, payload.uid)
        self.assertEqual(
            primitives.TextString(value=self.uid,
                                  tag=enums.Tags.UNIQUE_IDENTIFIER),
            payload._uid)
        self.assertEqual(list(), payload.attribute_names)
        self.assertEqual(list(), payload._attribute_names)
Beispiel #29
0
    def test_write_with_no_unique_identifier(self):
        """
        Test that a GetAttributes request payload with no ID can be written
        to a data stream.
        """
        payload = get_attributes.GetAttributesRequestPayload(
            None,
            self.attribute_names
        )
        stream = utils.BytearrayStream()
        payload.write(stream)

        self.assertEqual(
            len(self.encoding_sans_unique_identifier),
            len(stream)
        )
        self.assertEqual(
            str(self.encoding_sans_unique_identifier),
            str(stream)
        )
Beispiel #30
0
 def test_repr(self):
     """
     Test that repr can be applied to a GetAttributes request payload.
     """
     payload = get_attributes.GetAttributesRequestPayload(
         self.unique_identifier,
         self.attribute_names
     )
     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)