• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python utils.save_models函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_get_result

    def test_get_result(self, _):
        """Result of task with given id and environment id is returned."""
        now = timeutils.utcnow()
        expected_environment_id = 'test_environment'
        expected_task_id = 'test_task'
        expected_result = {'test_result': 'test_result'}

        environment = models.Environment(
            id=expected_environment_id,
            name='test_environment', created=now, updated=now,
            tenant_id=self.tenant
        )

        task = models.Task(
            id=expected_task_id,
            started=now,
            finished=now,
            result=expected_result,
            environment_id=expected_environment_id
        )

        test_utils.save_models(environment, task)

        request = self._get(
            '/environments/{environment_id}/actions/{task_id}'
            .format(environment_id=expected_environment_id,
                    task_id=expected_task_id),
        )

        response = request.get_response(self.api)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.json, expected_result)
开发者ID:tianshangjun,项目名称:murano,代码行数:33,代码来源:test_actions.py


示例2: test_delete_environment

    def test_delete_environment(self):
        """Test that environment deletion results in the correct rpc call."""
        self._set_policy_rules(
            {'delete_environment': '@'}
        )
        self.expect_policy_check(
            'delete_environment', {'environment_id': '12345'}
        )

        fake_now = timeutils.utcnow()
        expected = dict(
            id='12345',
            name='my-env',
            version=0,
            networking={},
            created=fake_now,
            updated=fake_now,
            tenant_id=self.tenant,
            description={
                'Objects': {
                    '?': {'id': '12345'}
                },
                'Attributes': {}
            }
        )
        e = models.Environment(**expected)
        test_utils.save_models(e)

        req = self._delete('/environments/12345')
        result = req.get_response(self.api)

        # Should this be expected behavior?
        self.assertEqual('', result.body)
        self.assertEqual(200, result.status_code)
开发者ID:aawm,项目名称:murano,代码行数:34,代码来源:test_environments.py


示例3: test_update_environment

    def test_update_environment(self):
        """Check that environment rename works."""
        self._set_policy_rules(
            {'show_environment': '@',
             'update_environment': '@'}
        )
        self.expect_policy_check('update_environment',
                                 {'environment_id': '12345'})

        fake_now = timeutils.utcnow()
        timeutils.utcnow.override_time = fake_now

        expected = dict(
            id='12345',
            name='my-env',
            version=0,
            description_text='',
            created=fake_now,
            updated=fake_now,
            tenant_id=self.tenant,
            description={
                'Objects': {
                    '?': {'id': '12345'}
                },
                'Attributes': []
            }
        )
        e = models.Environment(**expected)
        test_utils.save_models(e)

        fake_now = timeutils.utcnow()
        timeutils.utcnow.override_time = fake_now

        del expected['description']
        expected['services'] = []
        expected['status'] = 'ready'
        expected['name'] = 'renamed_env'
        expected['updated'] = fake_now

        body = {
            'name': 'renamed_env'
        }
        req = self._put('/environments/12345', jsonutils.dump_as_bytes(body))
        result = req.get_response(self.api)
        self.assertEqual(200, result.status_code)

        self.expect_policy_check('show_environment',
                                 {'environment_id': '12345'})
        req = self._get('/environments/12345')
        result = req.get_response(self.api)
        self.assertEqual(200, result.status_code)

        expected['created'] = timeutils.isotime(expected['created'])[:-1]
        expected['updated'] = timeutils.isotime(expected['updated'])[:-1]
        expected['acquired_by'] = None

        self.assertEqual(expected, jsonutils.loads(result.body))
开发者ID:AleptNamrata,项目名称:murano,代码行数:57,代码来源:test_environments.py


示例4: test_update_environment_with_existing_name

    def test_update_environment_with_existing_name(self):
        self._set_policy_rules(
            {'update_environment': '@'}
        )

        fake_now = timeutils.utcnow()
        timeutils.utcnow.override_time = fake_now

        expected = dict(
            id='111',
            name='env1',
            version=0,
            networking={},
            created=fake_now,
            updated=fake_now,
            tenant_id=self.tenant,
            description={
                'Objects': {
                    '?': {'id': '111'}
                },
                'Attributes': []
            }
        )
        e = models.Environment(**expected)
        test_utils.save_models(e)

        fake_now = timeutils.utcnow()
        timeutils.utcnow.override_time = fake_now

        expected = dict(
            id='222',
            name='env2',
            version=0,
            networking={},
            created=fake_now,
            updated=fake_now,
            tenant_id=self.tenant,
            description={
                'Objects': {
                    '?': {'id': '222'}
                },
                'Attributes': []
            }
        )
        e = models.Environment(**expected)
        test_utils.save_models(e)

        self.expect_policy_check('update_environment',
                                 {'environment_id': '111'})

        body = {
            'name': 'env2'
        }
        req = self._put('/environments/111', json.dumps(body))
        result = req.get_response(self.api)
        self.assertEqual(409, result.status_code)
开发者ID:aawm,项目名称:murano,代码行数:56,代码来源:test_environments.py


示例5: test_update_env_template

    def test_update_env_template(self):
        """Check that environment rename works."""
        self._set_policy_rules(
            {'show_env_template': '@',
             'update_env_template': '@'}
        )
        self.expect_policy_check('update_env_template',
                                 {'env_template_id': '12345'})

        fake_now = timeutils.utcnow()
        timeutils.utcnow.override_time = fake_now

        expected = dict(
            id='12345',
            is_public=False,
            name='my-temp',
            version=0,
            created=fake_now,
            updated=fake_now,
            tenant_id=self.tenant,
            description_text='',
            description={
                'name': 'my-temp',
                '?': {'id': '12345'}
            }
        )
        e = models.EnvironmentTemplate(**expected)
        test_utils.save_models(e)

        fake_now = timeutils.utcnow()
        timeutils.utcnow.override_time = fake_now

        del expected['description']
        expected['services'] = []
        expected['name'] = 'renamed_temp'
        expected['updated'] = fake_now

        body = {
            'name': 'renamed_temp'
        }
        req = self._put('/templates/12345', jsonutils.dump_as_bytes(body))
        result = req.get_response(self.api)
        self.assertEqual(200, result.status_code)

        self.expect_policy_check('show_env_template',
                                 {'env_template_id': '12345'})
        req = self._get('/templates/12345')
        result = req.get_response(self.api)
        self.assertEqual(200, result.status_code)

        expected['created'] = timeutils.isotime(expected['created'])[:-1]
        expected['updated'] = timeutils.isotime(expected['updated'])[:-1]

        self.assertEqual(expected, jsonutils.loads(result.body))
开发者ID:AleptNamrata,项目名称:murano,代码行数:54,代码来源:test_env_templates.py


示例6: _create_fake_environment

 def _create_fake_environment(self, env_name="my-env", env_id="123"):
     fake_now = timeutils.utcnow()
     expected = dict(
         id=env_id,
         name=env_name,
         version=0,
         created=fake_now,
         updated=fake_now,
         tenant_id=self.tenant,
         description={"Objects": {"?": {"id": "{0}".format(env_id)}}, "Attributes": {}},
     )
     e = models.Environment(**expected)
     test_utils.save_models(e)
开发者ID:NikolayStarodubtsev,项目名称:murano,代码行数:13,代码来源:test_environments.py


示例7: test_delete_category

    def test_delete_category(self):
        """Check that category deleted successfully
        """

        self._set_policy_rules({"delete_category": "@"})
        self.expect_policy_check("delete_category", {"category_id": "12345"})

        fake_now = timeutils.utcnow()
        expected = {"name": "new_category", "created": fake_now, "updated": fake_now, "id": "12345"}

        e = models.Category(**expected)
        test_utils.save_models(e)

        req = self._delete("/catalog/categories/12345")
        processed_result = req.get_response(self.api)
        self.assertEqual("", processed_result.body)
        self.assertEqual(200, processed_result.status_code)
开发者ID:NikolayStarodubtsev,项目名称:murano,代码行数:17,代码来源:test_catalog.py


示例8: test_get_environment_acquired

    def test_get_environment_acquired(self):
        """Test GET request of an environment in deploying status"""
        self._set_policy_rules(
            {'show_environment': '@'}
        )
        self.expect_policy_check('show_environment',
                                 {'environment_id': '1234'})
        fake_now = timeutils.utcnow()
        timeutils.utcnow.override_time = fake_now

        env_id = '1234'
        self._create_fake_environment(env_id=env_id)

        sess_id = '321'
        expected = dict(
            id=sess_id,
            environment_id=env_id,
            version=0,
            state=states.SessionState.DEPLOYING,
            user_id=self.tenant,
            description={
                'Objects': {
                    '?': {'id': '{0}'.format(env_id)}
                },
                'Attributes': {}
            }
        )
        s = models.Session(**expected)
        test_utils.save_models(s)

        req = self._get('/environments/{0}'.format(env_id))
        result = req.get_response(self.api)
        self.assertEqual(200, result.status_code)

        expected = {'tenant_id': self.tenant,
                    'id': env_id,
                    'name': 'my-env',
                    'version': 0,
                    'description_text': '',
                    'created': timeutils.isotime(fake_now)[:-1],
                    'updated': timeutils.isotime(fake_now)[:-1],
                    'acquired_by': sess_id,
                    'services': [],
                    'status': states.EnvironmentStatus.DEPLOYING,
                    }
        self.assertEqual(expected, jsonutils.loads(result.body))
开发者ID:AleptNamrata,项目名称:murano,代码行数:46,代码来源:test_environments.py


示例9: _create_fake_environment

 def _create_fake_environment(self, env_name='my-env', env_id='123'):
     fake_now = timeutils.utcnow()
     expected = dict(
         id=env_id,
         name=env_name,
         version=0,
         created=fake_now,
         updated=fake_now,
         tenant_id=self.tenant,
         description={
             'Objects': {
                 '?': {'id': '{0}'.format(env_id)}
             },
             'Attributes': {}
         }
     )
     e = models.Environment(**expected)
     test_utils.save_models(e)
开发者ID:Aqsamm,项目名称:murano,代码行数:18,代码来源:test_environments.py


示例10: test_update_environment

    def test_update_environment(self):
        """Check that environment rename works."""
        self._set_policy_rules({"show_environment": "@", "update_environment": "@"})
        self.expect_policy_check("update_environment", {"environment_id": "12345"})

        fake_now = timeutils.utcnow()
        timeutils.utcnow.override_time = fake_now

        expected = dict(
            id="12345",
            name="my-env",
            version=0,
            created=fake_now,
            updated=fake_now,
            tenant_id=self.tenant,
            description={"Objects": {"?": {"id": "12345"}}, "Attributes": []},
        )
        e = models.Environment(**expected)
        test_utils.save_models(e)

        fake_now = timeutils.utcnow()
        timeutils.utcnow.override_time = fake_now

        del expected["description"]
        expected["services"] = []
        expected["status"] = "ready"
        expected["name"] = "renamed_env"
        expected["updated"] = fake_now

        body = {"name": "renamed_env"}
        req = self._put("/environments/12345", json.dumps(body))
        result = req.get_response(self.api)
        self.assertEqual(200, result.status_code)

        self.expect_policy_check("show_environment", {"environment_id": "12345"})
        req = self._get("/environments/12345")
        result = req.get_response(self.api)
        self.assertEqual(200, result.status_code)

        expected["created"] = timeutils.isotime(expected["created"])[:-1]
        expected["updated"] = timeutils.isotime(expected["updated"])[:-1]
        expected["acquired_by"] = None

        self.assertEqual(expected, json.loads(result.body))
开发者ID:NikolayStarodubtsev,项目名称:murano,代码行数:44,代码来源:test_environments.py


示例11: test_delete_category

    def test_delete_category(self):
        """Check that category deleted successfully"""

        self._set_policy_rules({'delete_category': '@'})
        self.expect_policy_check('delete_category',
                                 {'category_id': '12345'})

        fake_now = timeutils.utcnow()
        expected = {'name': 'new_category',
                    'created': fake_now,
                    'updated': fake_now,
                    'id': '12345'}

        e = models.Category(**expected)
        test_utils.save_models(e)

        req = self._delete('/catalog/categories/12345')
        processed_result = req.get_response(self.api)
        self.assertEqual('', processed_result.body)
        self.assertEqual(200, processed_result.status_code)
开发者ID:ISCAS-VDI,项目名称:murano-base,代码行数:20,代码来源:test_catalog.py


示例12: test_get_result_not_found

    def test_get_result_not_found(self, _):
        """If task does not exists, it should be handled correctly
        and API should return 404.
        """
        expected_environment_id = 'test_environment'

        environment = models.Environment(
            id=expected_environment_id,
            name='test_environment',
            tenant_id=self.tenant
        )
        test_utils.save_models(environment)

        request = self._get(
            '/environments/{environment_id}/actions/{task_id}'
            .format(environment_id=expected_environment_id,
                    task_id='not_existent_task_id'),
        )

        response = request.get_response(self.api)

        self.assertEqual(response.status_code, 404)
开发者ID:tianshangjun,项目名称:murano,代码行数:22,代码来源:test_actions.py


示例13: test_get_environment_acquired

    def test_get_environment_acquired(self):
        """Test GET request of an environment in deploying status"""
        self._set_policy_rules({"show_environment": "@"})
        self.expect_policy_check("show_environment", {"environment_id": "1234"})
        fake_now = timeutils.utcnow()
        timeutils.utcnow.override_time = fake_now

        env_id = "1234"
        self._create_fake_environment(env_id=env_id)

        sess_id = "321"
        expected = dict(
            id=sess_id,
            environment_id=env_id,
            version=0,
            state=states.SessionState.DEPLOYING,
            user_id=self.tenant,
            description={"Objects": {"?": {"id": "{0}".format(env_id)}}, "Attributes": {}},
        )
        s = models.Session(**expected)
        test_utils.save_models(s)

        req = self._get("/environments/{0}".format(env_id))
        result = req.get_response(self.api)
        self.assertEqual(200, result.status_code)

        expected = {
            "tenant_id": self.tenant,
            "id": env_id,
            "name": "my-env",
            "version": 0,
            "created": timeutils.isotime(fake_now)[:-1],
            "updated": timeutils.isotime(fake_now)[:-1],
            "acquired_by": sess_id,
            "services": [],
            "status": states.EnvironmentStatus.DEPLOYING,
        }
        self.assertEqual(expected, json.loads(result.body))
开发者ID:NikolayStarodubtsev,项目名称:murano,代码行数:38,代码来源:test_environments.py


示例14: test_execute_action

    def test_execute_action(self, mock_policy_check):
        """Test that action execution results in the correct rpc call."""
        self._set_policy_rules(
            {'execute_action': '@'}
        )

        fake_now = timeutils.utcnow()
        expected = dict(
            id='12345',
            name='my-env',
            version=0,
            created=fake_now,
            updated=fake_now,
            tenant_id=self.tenant,
            description={
                'Objects': {
                    '?': {'id': '12345',
                          '_actions': {
                              'actionsID_action': {
                                  'enabled': True,
                                  'name': 'Testaction'
                              }
                          }}
                },
                'Attributes': {}
            }
        )
        e = models.Environment(**expected)
        test_utils.save_models(e)

        rpc_task = {
            'action': {
                'args': '{}',
                'method': 'Testaction',
                'object_id': '12345'
            },
            'tenant_id': self.tenant,
            'model': {
                'Attributes': {},
                'Objects': {
                    'applications': [],
                    '?': {
                        '_actions': {
                            'actionsID_action': {
                                'enabled': True,
                                'name': 'Testaction'
                            }
                        },
                        'id': '12345'
                    }
                }
            },
            'token': None,
            'id': '12345'
        }

        req = self._post('/environments/12345/actions/actionID_action', '{}')
        result = self.controller.execute(req, '12345', 'actionsID_action',
                                         '{}')

        self.mock_engine_rpc.handle_task.assert_called_once_with(rpc_task)

        self.assertIn('task_id', result)
开发者ID:tianshangjun,项目名称:murano,代码行数:63,代码来源:test_actions.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.generate_name函数代码示例发布时间:2022-05-27
下一篇:
Python log.getLogger函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap