コード例 #1
0
    def test_view_builder_list(self):
        view_builder = views_types.ViewBuilder()

        now = timeutils.utcnow().isoformat()
        raw_group_types = []
        for i in range(0, 10):
            raw_group_types.append(
                dict(
                    name='new_type',
                    description='new_type_desc',
                    is_public=True,
                    deleted=False,
                    created_at=now,
                    updated_at=now,
                    group_specs={},
                    deleted_at=None,
                    id=42 + i
                )
            )

        request = fakes.HTTPRequest.blank("/v3",
                                          version=GROUP_TYPE_MICRO_VERSION)
        output = view_builder.index(request, raw_group_types)

        self.assertIn('group_types', output)
        for i in range(0, 10):
            expected_group_type = dict(
                name='new_type',
                description='new_type_desc',
                is_public=True,
                id=42 + i
            )
            self.assertDictEqual(expected_group_type,
                                 output['group_types'][i])
コード例 #2
0
    def test_view_builder_show_admin(self):
        view_builder = views_types.ViewBuilder()

        now = timeutils.utcnow().isoformat()
        raw_group_type = dict(
            name='new_type',
            description='new_type_desc',
            is_public=True,
            deleted=False,
            created_at=now,
            updated_at=now,
            group_specs={},
            deleted_at=None,
            id=42,
        )

        request = fakes.HTTPRequest.blank("/v3", use_admin_context=True,
                                          version=GROUP_TYPE_MICRO_VERSION)
        output = view_builder.show(request, raw_group_type)

        self.assertIn('group_type', output)
        expected_group_type = dict(
            name='new_type',
            description='new_type_desc',
            is_public=True,
            group_specs={},
            id=42,
        )
        self.assertDictEqual(expected_group_type, output['group_type'])
コード例 #3
0
    def test_view_builder_show_pass_all_policy(self):
        with mock.patch.object(common,
                               'validate_policy',
                               side_effect=[True, True]):
            view_builder = views_types.ViewBuilder()
            now = timeutils.utcnow().isoformat()
            raw_group_type = dict(
                name='new_type',
                description='new_type_desc',
                is_public=True,
                deleted=False,
                created_at=now,
                updated_at=now,
                group_specs={},
                deleted_at=None,
                id=42,
            )

            request = fakes.HTTPRequest.blank("/v3",
                                              version=GROUP_TYPE_MICRO_VERSION)
            output = view_builder.show(request, raw_group_type)

            self.assertIn('group_type', output)
            expected_group_type = dict(
                name='new_type',
                description='new_type_desc',
                group_specs={},
                is_public=True,
                id=42,
            )
            self.assertDictEqual(expected_group_type, output['group_type'])
コード例 #4
0
    def __test_view_builder_show_qos_specs_id_policy(self):
        with mock.patch.object(context.RequestContext,
                               'authorize',
                               side_effect=[False, True]):
            view_builder = views_types.ViewBuilder()
            now = timeutils.utcnow().isoformat()
            raw_group_type = dict(
                name='new_type',
                description='new_type_desc',
                is_public=True,
                deleted=False,
                created_at=now,
                updated_at=now,
                deleted_at=None,
                id=42,
            )

            request = fakes.HTTPRequest.blank("/v3", version=mv.GROUP_TYPE)
            output = view_builder.show(request, raw_group_type)

            self.assertIn('group_type', output)
            expected_group_type = dict(
                name='new_type',
                description='new_type_desc',
                is_public=True,
                id=42,
            )
            self.assertDictEqual(expected_group_type, output['group_type'])