コード例 #1
0
    def test_not_equal_on_not_equal_attribute_names(self):
        """
        Test that the inequality operator returns False when comparing two
        GetAttributeList response payloads with different data.
        """
        a = get_attribute_list.GetAttributeListResponsePayload(
            self.uid, self.attribute_names)
        b = get_attribute_list.GetAttributeListResponsePayload(
            self.uid, list())

        self.assertTrue(a != b)
        self.assertTrue(b != a)
コード例 #2
0
    def test_equal_on_not_equal_unique_identifier(self):
        """
        Test that the equality operator returns False when comparing two
        GetAttributeList response payloads with different IDs.
        """
        a = get_attribute_list.GetAttributeListResponsePayload(
            self.unique_identifier, self.attribute_names)
        b = get_attribute_list.GetAttributeListResponsePayload(
            'invalid', self.attribute_names)

        self.assertFalse(a == b)
        self.assertFalse(b == a)
コード例 #3
0
    def test_equal_on_equal(self):
        """
        Test that the equality operator returns True when comparing two
        GetAttributeList response payloads with the same data.
        """
        a = get_attribute_list.GetAttributeListResponsePayload(
            self.unique_identifier, self.attribute_names)
        b = get_attribute_list.GetAttributeListResponsePayload(
            self.unique_identifier, self.attribute_names)

        self.assertTrue(a == b)
        self.assertTrue(b == a)
コード例 #4
0
    def test_not_equal_on_equal(self):
        """
        Test that the inequality operator returns False when comparing
        two GetAttributeList response payloads with the same internal data.
        """
        a = get_attribute_list.GetAttributeListResponsePayload(
            self.unique_identifier, self.attribute_names)
        b = get_attribute_list.GetAttributeListResponsePayload(
            self.unique_identifier, self.attribute_names)

        self.assertFalse(a != b)
        self.assertFalse(b != a)
コード例 #5
0
    def test_not_equal_on_not_equal_attribute_names(self):
        """
        Test that the inequality operator returns True when comparing two
        GetAttributeList response payloads with different attribute names.
        """
        a = get_attribute_list.GetAttributeListResponsePayload(
            self.unique_identifier, self.attribute_names)
        b = get_attribute_list.GetAttributeListResponsePayload(
            self.unique_identifier, None)

        self.assertTrue(a != b)
        self.assertTrue(b != a)
コード例 #6
0
    def test_equal_with_mixed_attribute_names(self):
        """
        Test that the equality operator returns True when comparing two
        GetAttributeList response payload with the same attribute_name sets
        but with different attribute name orderings.
        """
        a = get_attribute_list.GetAttributeListResponsePayload(
            self.unique_identifier, self.attribute_names)
        self.attribute_names.reverse()
        b = get_attribute_list.GetAttributeListResponsePayload(
            self.unique_identifier, self.attribute_names)

        self.assertTrue(a == b)
        self.assertTrue(b == a)
コード例 #7
0
    def test_not_equal_on_not_equal_attribute_name(self):
        """
        Test that the inequality operator returns False when comparing two
        GetAttributeList response payloads with different data.
        """
        alt_names = copy.deepcopy(self.attribute_names)
        alt_names[0] = 'Operation Policy Name'
        a = get_attribute_list.GetAttributeListResponsePayload(
            self.uid, self.attribute_names)
        b = get_attribute_list.GetAttributeListResponsePayload(
            self.uid, alt_names)

        self.assertTrue(a != b)
        self.assertTrue(b != a)
コード例 #8
0
    def test_attribute_names_with_duplicates(self):
        """
        Test that duplicate attribute names are silently removed when setting
        the attribute_names attribute of a GetAttributeList response payload.
        """
        payload = get_attribute_list.GetAttributeListResponsePayload()

        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)
コード例 #9
0
 def test_init_with_args(self):
     """
     Test that a GetAttributeList response payload can be constructed with
     valid values.
     """
     get_attribute_list.GetAttributeListResponsePayload(
         self.uid, self.attribute_names)
コード例 #10
0
    def test_attribute_names(self):
        """
        Test that the attribute_names attribute of a GetAttributeList response
        payload can be properly set and retrieved.
        """
        payload = get_attribute_list.GetAttributeListResponsePayload()

        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)
コード例 #11
0
 def test_init_with_args(self):
     """
     Test that a GetAttributeList response payload can be constructed with a
     valid value.
     """
     get_attribute_list.GetAttributeListResponsePayload(
         'test-unique-identifier',
         ['test-attribute-name-1', 'test-attribute-name-2'])
コード例 #12
0
    def test_read_with_no_attribute_names(self):
        """
        Test that a GetAttributeList response payload without attribute name
        data can be read from a data stream.
        """
        payload = get_attribute_list.GetAttributeListResponsePayload()
        payload.read(self.encoding_with_uid_without_names)

        self.assertEqual(self.uid, payload.uid)
        self.assertEqual(list(), payload.attribute_names)
コード例 #13
0
 def test_read_with_no_uid(self):
     """
     Test that an InvalidKmipEncoding error gets raised when attempting to
     read a GetAttributeList response encoding with no ID data.
     """
     payload = get_attribute_list.GetAttributeListResponsePayload()
     self.assertRaisesRegexp(exceptions.InvalidKmipEncoding,
                             "expected uid encoding not found",
                             payload.read,
                             self.encoding_without_uid_with_names)
コード例 #14
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 GetAttributeList response payload.
     """
     payload = get_attribute_list.GetAttributeListResponsePayload()
     args = (payload, 'attribute_names', 0)
     self.assertRaisesRegexp(TypeError,
                             "attribute_names must be a list of strings",
                             setattr, *args)
コード例 #15
0
 def test_str_with_no_content(self):
     """
     Test that str can be applied to a GetAttributeList response payload
     with no ID or attribute names.
     """
     payload = get_attribute_list.GetAttributeListResponsePayload(
         None, None)
     expected = str({'unique_identifier': None, 'attribute_names': list()})
     observed = str(payload)
     self.assertEqual(expected, observed)
コード例 #16
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
     GetAttributeList response payload.
     """
     payload = get_attribute_list.GetAttributeListResponsePayload()
     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)
コード例 #17
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 GetAttributeList response
     payload.
     """
     payload = get_attribute_list.GetAttributeListResponsePayload()
     args = (payload, 'unique_identifier', 0)
     self.assertRaisesRegexp(TypeError,
                             "unique identifier must be a string", setattr,
                             *args)
コード例 #18
0
    def test_write_with_no_content(self):
        """
        Test that a GetAttributeList response payload with no ID or attribute
        names can be written to a data stream.
        """
        payload = get_attribute_list.GetAttributeListResponsePayload()
        stream = utils.BytearrayStream()
        payload.write(stream)

        self.assertEqual(len(self.empty_encoding), len(stream))
        self.assertEqual(str(self.empty_encoding), str(stream))
コード例 #19
0
 def test_repr(self):
     """
     Test that repr can be applied to a GetAttributeList response payload.
     """
     payload = get_attribute_list.GetAttributeListResponsePayload(
         self.uid, self.attribute_names)
     args = "uid={0}, attribute_names={1}".format(payload.uid,
                                                  payload.attribute_names)
     expected = "GetAttributeListResponsePayload({0})".format(args)
     observed = repr(payload)
     self.assertEqual(expected, observed)
コード例 #20
0
 def test_str(self):
     """
     Test that str can be applied to a GetAttributeList response payload.
     """
     payload = get_attribute_list.GetAttributeListResponsePayload(self.uid)
     expected = str({
         'uid': payload.uid,
         'attribute_names': payload.attribute_names
     })
     observed = str(payload)
     self.assertEqual(expected, observed)
コード例 #21
0
    def test_not_equal_on_type_mismatch(self):
        """
        Test that the equality operator returns True when comparing a
        GetAttributeList response payload to a non-GetAttributeList response
        payload.
        """
        a = get_attribute_list.GetAttributeListResponsePayload(
            self.unique_identifier, self.attribute_names)
        b = "invalid"

        self.assertTrue(a != b)
        self.assertTrue(b != a)
コード例 #22
0
    def test_write_with_no_attribute_names(self):
        """
        Test that a GetAttributeList response payload with no attribute name
        data can be written to a data stream.
        """
        payload = get_attribute_list.GetAttributeListResponsePayload(self.uid)
        stream = utils.BytearrayStream()
        payload.write(stream)

        self.assertEqual(len(self.encoding_with_uid_without_names),
                         len(stream))
        self.assertEqual(self.encoding_with_uid_without_names, stream)
コード例 #23
0
    def test_equal_on_type_mismatch(self):
        """
        Test that the equality operator returns False when comparing a
        GetAttributeList response payload to a non-GetAttributeList response
        payload.
        """
        a = get_attribute_list.GetAttributeListResponsePayload(
            self.uid, self.attribute_names)
        b = 'invalid'

        self.assertFalse(a == b)
        self.assertFalse(b == a)
コード例 #24
0
    def test_write(self):
        """
        Test that a GetAttributeList response payload can be written to a data
        stream.
        """
        payload = get_attribute_list.GetAttributeListResponsePayload(
            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))
コード例 #25
0
 def test_str(self):
     """
     Test that str can be applied to a GetAttributeList response payload.
     """
     payload = get_attribute_list.GetAttributeListResponsePayload(
         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)
コード例 #26
0
    def test_write_with_no_attribute_names(self):
        """
        Test that a GetAttributeList response payload with no attribute names
        can be written to a data stream.
        """
        payload = get_attribute_list.GetAttributeListResponsePayload(
            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))
コード例 #27
0
    def test_process_get_attribute_list_batch_item(self):
        uid = '00000000-1111-2222-3333-444444444444'
        names = ['Cryptographic Algorithm', 'Cryptographic Length']
        payload = get_attribute_list.GetAttributeListResponsePayload(
            unique_identifier=uid, attribute_names=names)
        batch_item = ResponseBatchItem(
            operation=Operation(OperationEnum.GET_ATTRIBUTE_LIST),
            response_payload=payload)
        result = self.client._process_get_attribute_list_batch_item(batch_item)

        self.assertIsInstance(result, GetAttributeListResult)
        self.assertEqual(uid, result.uid)
        self.assertEqual(names, result.names)
コード例 #28
0
 def test_repr(self):
     """
     Test that repr can be applied to a GetAttributeList response payload.
     """
     payload = get_attribute_list.GetAttributeListResponsePayload(
         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 = "GetAttributeListResponsePayload({0}, {1})".format(
         unique_identifier, attribute_names)
     observed = repr(payload)
     self.assertEqual(expected, observed)
コード例 #29
0
    def test_read_with_no_content(self):
        """
        Test that a GetAttributeList response payload with no ID or attribute
        names can be read from a data stream.
        """
        payload = get_attribute_list.GetAttributeListResponsePayload()

        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)
コード例 #30
0
    def test_unique_identifier(self):
        """
        Test that the unique_identifier attribute of a GetAttributeList
        response payload can be properly set and retrieved.
        """
        payload = get_attribute_list.GetAttributeListResponsePayload()

        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)