当前位置: 首页>>代码示例>>Python>>正文


Python shared.create_profile函数代码示例

本文整理汇总了Python中senlin.tests.unit.db.shared.create_profile函数的典型用法代码示例。如果您正苦于以下问题:Python create_profile函数的具体用法?Python create_profile怎么用?Python create_profile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了create_profile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_profile_get_all_sort_keys_and_dir

    def test_profile_get_all_sort_keys_and_dir(self):
        values = [
            {"id": "001", "name": "profile1", "type": "C"},
            {"id": "002", "name": "profile3", "type": "B"},
            {"id": "003", "name": "profile2", "type": "A"},
        ]

        for v in values:
            shared.create_profile(self.ctx, **v)

        profiles = db_api.profile_get_all(self.ctx, sort_keys=["name", "type"], sort_dir="asc")
        self.assertEqual(3, len(profiles))
        # Sorted by name
        self.assertEqual("001", profiles[0].id)
        self.assertEqual("003", profiles[1].id)
        self.assertEqual("002", profiles[2].id)

        profiles = db_api.profile_get_all(self.ctx, sort_keys=["type", "name"], sort_dir="asc")
        self.assertEqual(3, len(profiles))
        # Sorted by levels (ascending)
        self.assertEqual("003", profiles[0].id)
        self.assertEqual("002", profiles[1].id)
        self.assertEqual("001", profiles[2].id)

        profiles = db_api.profile_get_all(self.ctx, sort_keys=["type", "name"], sort_dir="desc")
        self.assertEqual(3, len(profiles))
        # Sorted by statuses (descending)
        self.assertEqual("001", profiles[0].id)
        self.assertEqual("002", profiles[1].id)
        self.assertEqual("003", profiles[2].id)
开发者ID:MountainWei,项目名称:senlin,代码行数:30,代码来源:test_profile_api.py

示例2: test_profile_get_all

    def test_profile_get_all(self):
        ids = ["profile1", "profile2"]

        for pid in ids:
            shared.create_profile(self.ctx, id=pid)

        profiles = db_api.profile_get_all(self.ctx)
        self.assertEqual(2, len(profiles))
        profile_ids = [p.id for p in profiles]
        for pid in ids:
            self.assertIn(pid, profile_ids)

        # test show_deleted here
        db_api.profile_delete(self.ctx, profiles[1].id)

        # after delete one of them
        profiles = db_api.profile_get_all(self.ctx)
        self.assertEqual(1, len(profiles))

        profiles = db_api.profile_get_all(self.ctx, show_deleted=False)
        self.assertEqual(1, len(profiles))

        profiles = db_api.profile_get_all(self.ctx, show_deleted=True)
        self.assertEqual(2, len(profiles))

        # after delete both profiles
        db_api.profile_delete(self.ctx, profiles[0].id)

        profiles = db_api.profile_get_all(self.ctx)
        self.assertEqual(0, len(profiles))
        profiles = db_api.profile_get_all(self.ctx, show_deleted=True)
        self.assertEqual(2, len(profiles))
开发者ID:MountainWei,项目名称:senlin,代码行数:32,代码来源:test_profile_api.py

示例3: test_profile_get_all_sorting

    def test_profile_get_all_sorting(self):
        values = [{'id': '001', 'name': 'profile1', 'type': 'C'},
                  {'id': '002', 'name': 'profile3', 'type': 'B'},
                  {'id': '003', 'name': 'profile2', 'type': 'A'}]

        for v in values:
            shared.create_profile(self.ctx, **v)

        # Sorted by name,type
        profiles = db_api.profile_get_all(self.ctx, sort='name,type')
        self.assertEqual(3, len(profiles))
        self.assertEqual('001', profiles[0].id)
        self.assertEqual('003', profiles[1].id)
        self.assertEqual('002', profiles[2].id)

        # Sorted by type,name (ascending)
        profiles = db_api.profile_get_all(self.ctx, sort='type,name')
        self.assertEqual(3, len(profiles))
        self.assertEqual('003', profiles[0].id)
        self.assertEqual('002', profiles[1].id)
        self.assertEqual('001', profiles[2].id)

        # Sorted by type,name (descending)
        profiles = db_api.profile_get_all(self.ctx, sort='type:desc,name:desc')
        self.assertEqual(3, len(profiles))
        self.assertEqual('001', profiles[0].id)
        self.assertEqual('002', profiles[1].id)
        self.assertEqual('003', profiles[2].id)
开发者ID:jonnary,项目名称:senlin,代码行数:28,代码来源:test_profile_api.py

示例4: test_profile_get_all_with_limit_marker

    def test_profile_get_all_with_limit_marker(self):
        ids = ['profile1', 'profile2', 'profile3']
        for pid in ids:
            timestamp = tu.utcnow(True)
            shared.create_profile(self.ctx, id=pid, created_at=timestamp)

        # different limit settings
        profiles = db_api.profile_get_all(self.ctx, limit=1)
        self.assertEqual(1, len(profiles))

        profiles = db_api.profile_get_all(self.ctx, limit=2)
        self.assertEqual(2, len(profiles))

        # a large limit
        profiles = db_api.profile_get_all(self.ctx, limit=5)
        self.assertEqual(3, len(profiles))

        # use marker here
        profiles = db_api.profile_get_all(self.ctx, marker='profile1')
        self.assertEqual(2, len(profiles))

        profiles = db_api.profile_get_all(self.ctx, marker='profile2')
        self.assertEqual(1, len(profiles))

        profiles = db_api.profile_get_all(self.ctx, marker='profile3')
        self.assertEqual(0, len(profiles))

        profiles = db_api.profile_get_all(self.ctx, limit=1, marker='profile1')
        self.assertEqual(1, len(profiles))
开发者ID:jonnary,项目名称:senlin,代码行数:29,代码来源:test_profile_api.py

示例5: test_profile_get_by_short_id

    def test_profile_get_by_short_id(self):
        profile_ids = ['same-part-unique-part',
                       'same-part-part-unique']

        for pid in profile_ids:
            shared.create_profile(self.ctx, id=pid)

            # verify creation with set ID
            profile = db_api.profile_get(self.ctx, pid)
            self.assertIsNotNone(profile)
            self.assertEqual(pid, profile.id)

        # too short -> multiple choices
        for x in range(len('same-part-')):
            self.assertRaises(exception.MultipleChoices,
                              db_api.profile_get_by_short_id,
                              self.ctx, profile_ids[0][:x])

        # ids are unique
        profile = db_api.profile_get_by_short_id(self.ctx, profile_ids[0][:11])
        self.assertEqual(profile_ids[0], profile.id)
        profile = db_api.profile_get_by_short_id(self.ctx, profile_ids[1][:11])
        self.assertEqual(profile_ids[1], profile.id)

        # bad ids
        res = db_api.profile_get_by_short_id(self.ctx, 'non-existent')
        self.assertIsNone(res)
开发者ID:jonnary,项目名称:senlin,代码行数:27,代码来源:test_profile_api.py

示例6: test_profile_get_all_sort_keys_and_dir

    def test_profile_get_all_sort_keys_and_dir(self):
        values = [{'id': '001', 'name': 'profile1', 'type': 'C'},
                  {'id': '002', 'name': 'profile3', 'type': 'B'},
                  {'id': '003', 'name': 'profile2', 'type': 'A'}]

        for v in values:
            shared.create_profile(self.ctx, **v)

        profiles = db_api.profile_get_all(self.ctx, sort_keys=['name', 'type'],
                                          sort_dir='asc')
        self.assertEqual(3, len(profiles))
        # Sorted by name
        self.assertEqual('001', profiles[0].id)
        self.assertEqual('003', profiles[1].id)
        self.assertEqual('002', profiles[2].id)

        profiles = db_api.profile_get_all(self.ctx, sort_keys=['type', 'name'],
                                          sort_dir='asc')
        self.assertEqual(3, len(profiles))
        # Sorted by levels (ascending)
        self.assertEqual('003', profiles[0].id)
        self.assertEqual('002', profiles[1].id)
        self.assertEqual('001', profiles[2].id)

        profiles = db_api.profile_get_all(self.ctx, sort_keys=['type', 'name'],
                                          sort_dir='desc')
        self.assertEqual(3, len(profiles))
        # Sorted by statuses (descending)
        self.assertEqual('001', profiles[0].id)
        self.assertEqual('002', profiles[1].id)
        self.assertEqual('003', profiles[2].id)
开发者ID:KongJustin,项目名称:senlin,代码行数:31,代码来源:test_profile_api.py

示例7: test_profile_get_all_with_empty_filters

    def test_profile_get_all_with_empty_filters(self):
        for name in ['profile1', 'profile2']:
            shared.create_profile(self.ctx, name=name)

        filters = None
        results = db_api.profile_get_all(self.ctx, filters=filters)
        self.assertEqual(2, len(results))
开发者ID:jonnary,项目名称:senlin,代码行数:7,代码来源:test_profile_api.py

示例8: test_profile_get_all_admin_context

    def test_profile_get_all_admin_context(self):
        ids = ['profile1', 'profile2']
        for pid in ids:
            shared.create_profile(self.ctx, id=pid)

        admin_ctx = utils.dummy_context(project='a-different-project',
                                        is_admin=True)
        profiles = db_api.profile_get_all(admin_ctx, project_safe=True)
        self.assertEqual(2, len(profiles))
开发者ID:jonnary,项目名称:senlin,代码行数:9,代码来源:test_profile_api.py

示例9: test_profile_get_all_diff_project

    def test_profile_get_all_diff_project(self):
        ids = ['profile1', 'profile2']
        for pid in ids:
            shared.create_profile(self.ctx, id=pid)

        new_ctx = utils.dummy_context(project='a-different-project')
        profiles = db_api.profile_get_all(new_ctx)
        self.assertEqual(0, len(profiles))
        profiles = db_api.profile_get_all(new_ctx, project_safe=False)
        self.assertEqual(2, len(profiles))
开发者ID:jonnary,项目名称:senlin,代码行数:10,代码来源:test_profile_api.py

示例10: test_profile_get_by_name_diff_project

    def test_profile_get_by_name_diff_project(self):
        profile_name = "my_best_profile"
        shared.create_profile(self.ctx, name=profile_name)

        new_ctx = utils.dummy_context(project="a-different-project")
        res = db_api.profile_get_by_name(new_ctx, profile_name)
        self.assertIsNone(res)

        res = db_api.profile_get_by_name(new_ctx, profile_name, project_safe=False)
        self.assertIsNotNone(res)
        self.assertEqual(profile_name, res.name)
开发者ID:MountainWei,项目名称:senlin,代码行数:11,代码来源:test_profile_api.py

示例11: test_profile_get_by_short_id_diff_project

    def test_profile_get_by_short_id_diff_project(self):
        profile_id = "same-part-unique-part"
        shared.create_profile(self.ctx, id=profile_id)

        new_ctx = utils.dummy_context(project="a-different-project")
        res = db_api.profile_get_by_short_id(new_ctx, profile_id)
        self.assertIsNone(res)

        res = db_api.profile_get_by_short_id(new_ctx, profile_id, project_safe=False)
        self.assertIsNotNone(res)
        self.assertEqual(profile_id, res.id)
开发者ID:MountainWei,项目名称:senlin,代码行数:11,代码来源:test_profile_api.py

示例12: test_profile_get_all_used_sort_keys

    def test_profile_get_all_used_sort_keys(self, mock_paginate):
        ids = ['profile1', 'profile2', 'profile3']
        for pid in ids:
            shared.create_profile(self.ctx, id=pid)

        sort_keys = consts.PROFILE_SORT_KEYS
        db_api.profile_get_all(self.ctx, sort=','.join(sort_keys))

        args = mock_paginate.call_args[0]
        sort_keys.append('id')
        self.assertEqual(set(sort_keys), set(args[3]))
开发者ID:jonnary,项目名称:senlin,代码行数:11,代码来源:test_profile_api.py

示例13: test_profile_get_all_with_filters

    def test_profile_get_all_with_filters(self):
        for name in ["profile1", "profile2"]:
            shared.create_profile(self.ctx, name=name)

        filters = {"name": ["profile1", "profilex"]}
        results = db_api.profile_get_all(self.ctx, filters=filters)
        self.assertEqual(1, len(results))
        self.assertEqual("profile1", results[0]["name"])

        filters = {"name": "profile1"}
        results = db_api.profile_get_all(self.ctx, filters=filters)
        self.assertEqual(1, len(results))
        self.assertEqual("profile1", results[0]["name"])
开发者ID:MountainWei,项目名称:senlin,代码行数:13,代码来源:test_profile_api.py

示例14: test_profile_get_all_used_sort_keys

    def test_profile_get_all_used_sort_keys(self):
        ids = ["profile1", "profile2", "profile3"]
        for pid in ids:
            shared.create_profile(self.ctx, id=pid)

        mock_paginate = self.patchobject(db_api.utils, "paginate_query")
        sort_keys = ["type", "name", "permission", "metadata", "created_time", "updated_time", "deleted_time"]

        db_api.profile_get_all(self.ctx, sort_keys=sort_keys)

        args = mock_paginate.call_args[0]
        used_sort_keys = set(args[3])
        expected_keys = set(["id", "type", "name", "permission", "created_time", "updated_time", "deleted_time"])
        self.assertEqual(expected_keys, used_sort_keys)
开发者ID:MountainWei,项目名称:senlin,代码行数:14,代码来源:test_profile_api.py

示例15: test_profile_create

 def test_profile_create(self):
     data = parser.simple_parse(shared.sample_profile)
     profile = shared.create_profile(self.ctx)
     self.assertIsNotNone(profile.id)
     self.assertEqual(data['name'], profile.name)
     self.assertEqual(data['type'], profile.type)
     self.assertEqual(data['spec'], profile.spec)
开发者ID:jonnary,项目名称:senlin,代码行数:7,代码来源:test_profile_api.py


注:本文中的senlin.tests.unit.db.shared.create_profile函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。