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


Python ddt.data方法代码示例

本文整理汇总了Python中ddt.data方法的典型用法代码示例。如果您正苦于以下问题:Python ddt.data方法的具体用法?Python ddt.data怎么用?Python ddt.data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ddt的用法示例。


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

示例1: test_detach_volume

# 需要导入模块: import ddt [as 别名]
# 或者: from ddt import data [as 别名]
def test_detach_volume(self, update_device_metadata,
                           mock_update_dev_meta,
                           mock_get_volume_driver):
        mock_instance = fake_instance.fake_instance_obj()
        fake_volume_driver = mock_get_volume_driver.return_value
        fake_conn_info = {'data': 'fake_conn_info_data'}

        self._volumeops.detach_volume(mock.sentinel.context,
                                      fake_conn_info,
                                      mock_instance,
                                      update_device_metadata)

        mock_get_volume_driver.assert_called_once_with(
            fake_conn_info)
        fake_volume_driver.detach_volume.assert_called_once_with(
            fake_conn_info, mock_instance.name)
        fake_volume_driver.disconnect_volume.assert_called_once_with(
            fake_conn_info)

        if update_device_metadata:
            mock_update_dev_meta.assert_called_once_with(
                mock.sentinel.context, mock_instance)
        else:
            mock_update_dev_meta.assert_not_called() 
开发者ID:openstack,项目名称:compute-hyperv,代码行数:26,代码来源:test_volumeops.py

示例2: _test_get_disk_resource_path_by_conn_info

# 需要导入模块: import ddt [as 别名]
# 或者: from ddt import data [as 别名]
def _test_get_disk_resource_path_by_conn_info(self,
                                                  mock_get_disk_res_path,
                                                  disk_found=True):
        conn_info = get_fake_connection_info()
        mock_vol_paths = [mock.sentinel.disk_path] if disk_found else []
        self._conn.get_volume_paths.return_value = mock_vol_paths

        if disk_found:
            disk_res_path = self._base_vol_driver.get_disk_resource_path(
                conn_info)

            self._conn.get_volume_paths.assert_called_once_with(
                conn_info['data'])
            self.assertEqual(mock_get_disk_res_path.return_value,
                             disk_res_path)
            mock_get_disk_res_path.assert_called_once_with(
                mock.sentinel.disk_path)
        else:
            self.assertRaises(exception.DiskNotFound,
                              self._base_vol_driver.get_disk_resource_path,
                              conn_info) 
开发者ID:openstack,项目名称:compute-hyperv,代码行数:23,代码来源:test_volumeops.py

示例3: test_update_share_metadata_post

# 需要导入模块: import ddt [as 别名]
# 或者: from ddt import data [as 别名]
def test_update_share_metadata_post(self):
        share = test_data.share_with_metadata
        data = {
            'metadata': 'aaa=ccc',
        }
        form_data = {
            'metadata': {'aaa': 'ccc'},
        }
        url = reverse(
            'horizon:project:shares:update_metadata', args=[share.id])
        self.mock_object(
            api_manila, "share_get", mock.Mock(return_value=share))
        self.mock_object(api_manila, "share_set_metadata")
        self.mock_object(
            neutron, "is_service_enabled", mock.Mock(return_value=[True]))

        res = self.client.post(url, data)

        api_manila.share_set_metadata.assert_called_once_with(
            mock.ANY, share, form_data['metadata'])
        self.assertRedirectsNoFollow(res, INDEX_URL) 
开发者ID:openstack,项目名称:manila-ui,代码行数:23,代码来源:tests.py

示例4: test_share_group_snapshot_delete_post

# 需要导入模块: import ddt [as 别名]
# 或者: from ddt import data [as 别名]
def test_share_group_snapshot_delete_post(self):
        data = {'action': 'share_group_snapshots__delete__%s' % self.sgs.id}
        self.mock_object(api_manila, "share_group_snapshot_delete")
        self.mock_object(
            api_manila, "share_group_snapshot_list",
            mock.Mock(return_value=[self.sgs]))

        res = self.client.post(INDEX_URL, data)

        self.assertStatusCode(res, 302)
        self.assertMessageCount(success=1)
        api_manila.share_group_snapshot_delete.assert_called_once_with(
            mock.ANY, self.sgs.id)
        api_manila.share_group_snapshot_list.assert_called_once_with(
            mock.ANY, search_opts={'all_tenants': True})
        self.assertRedirectsNoFollow(res, INDEX_URL) 
开发者ID:openstack,项目名称:manila-ui,代码行数:18,代码来源:tests.py

示例5: test_handle_success_only_unset

# 需要导入模块: import ddt [as 别名]
# 或者: from ddt import data [as 别名]
def test_handle_success_only_unset(self, mock_horizon_messages_success):
        initial = {
            'id': 'fake_id',
            'name': 'fake_name',
            'extra_specs': {'foo': 'bar'}
        }
        form = self._get_form(initial)
        data = {'extra_specs': 'foo\r\n'}
        share_types_get = self.manilaclient.share_types.get
        share_types_get.return_value.get_keys.return_value = {
            'foo': 'bar', 'quuz': 'zaab'}

        result = form.handle(self.request, data)

        self.assertTrue(result)
        mock_horizon_messages_success.assert_called_once_with(
            mock.ANY, mock.ANY)
        self.manilaclient.share_types.get.assert_has_calls([
            mock.call(initial['id'])])
        share_types_get.return_value.get_keys.assert_called_once_with()
        self.assertFalse(share_types_get.return_value.set_keys.called)
        share_types_get.return_value.unset_keys.assert_called_once_with(
            {'foo'}) 
开发者ID:openstack,项目名称:manila-ui,代码行数:25,代码来源:test_forms.py

示例6: test_handle_success_set_and_unset

# 需要导入模块: import ddt [as 别名]
# 或者: from ddt import data [as 别名]
def test_handle_success_set_and_unset(self, mock_horizon_messages_success):
        initial = {
            'id': 'fake_id',
            'name': 'fake_name',
            'extra_specs': {'foo': 'bar'}
        }
        form = self._get_form(initial)
        data = {'extra_specs': 'foo\r\nquuz=zaab'}
        share_types_get = self.manilaclient.share_types.get
        share_types_get.return_value.get_keys.return_value = {'foo': 'bar'}

        result = form.handle(self.request, data)

        self.assertTrue(result)
        mock_horizon_messages_success.assert_called_once_with(
            mock.ANY, mock.ANY)
        self.manilaclient.share_types.get.assert_has_calls([
            mock.call(initial['id'])])
        share_types_get.return_value.get_keys.assert_called_once_with()
        share_types_get.return_value.set_keys.assert_called_once_with(
            {'quuz': 'zaab'})
        share_types_get.return_value.unset_keys.assert_called_once_with(
            {'foo'}) 
开发者ID:openstack,项目名称:manila-ui,代码行数:25,代码来源:test_forms.py

示例7: test_create_share_type

# 需要导入模块: import ddt [as 别名]
# 或者: from ddt import data [as 别名]
def test_create_share_type(self, mock_horizon_messages_success):
        form = self._get_form()
        data = {
            'extra_specs': '',
            'is_public': False,
            'spec_driver_handles_share_servers': 'True',
            'name': 'share',
        }

        result = form.handle(self.request, data)

        self.assertTrue(result)
        self.manilaclient.share_types.create.assert_called_once_with(
            name=data['name'],
            spec_driver_handles_share_servers='true',
            is_public=data["is_public"])
        mock_horizon_messages_success.assert_called_once_with(
            self.request, mock.ANY) 
开发者ID:openstack,项目名称:manila-ui,代码行数:20,代码来源:test_forms.py

示例8: test_jinja_render_template_multiple_variables

# 需要导入模块: import ddt [as 别名]
# 或者: from ddt import data [as 别名]
def test_jinja_render_template_multiple_variables(self):
        fake_instance_data = {
            'v1': {
                'localhostname': 'fake_hostname'
            },
            'ds': {
                'meta_data': {
                    'hostname': 'fake_hostname'
                },
                'meta-data': {
                    'hostname': 'fake_hostname'
                }
            }
        }
        fake_template = b'{{ds.meta_data.hostname}}'
        expected_result = b'fake_hostname'
        self._test_jinja_render_template(
            fake_instance_data=fake_instance_data,
            expected_result=expected_result,
            fake_template=fake_template) 
开发者ID:cloudbase,项目名称:cloudbase-init,代码行数:22,代码来源:test_jinja2_template.py

示例9: test_get_guest_data

# 需要导入模块: import ddt [as 别名]
# 或者: from ddt import data [as 别名]
def test_get_guest_data(self, test_data, expected_encoding,
                            mock_get_guestinfo_value,
                            mock_decode_data):

        (data_key, encoding_ret) = test_data
        (is_base64, is_gzip) = expected_encoding
        data_key_ret = 'fake_data'
        decoded_data = 'fake_decoded_data'

        def guest_info_side_effect(*args, **kwargs):
            if args[0] == data_key:
                return data_key_ret
            return encoding_ret

        mock_get_guestinfo_value.side_effect = guest_info_side_effect
        mock_decode_data.return_value = decoded_data

        data = self._service._get_guest_data(data_key)

        self.assertEqual(data, decoded_data)
        mock_decode_data.assert_called_once_with(data_key_ret,
                                                 is_base64, is_gzip) 
开发者ID:cloudbase,项目名称:cloudbase-init,代码行数:24,代码来源:test_vmwareguestinfoservice.py

示例10: test_get_user_data_b64

# 需要导入模块: import ddt [as 别名]
# 或者: from ddt import data [as 别名]
def test_get_user_data_b64(self, mock_get_cache_data):
        user_data = b'fake userdata'
        user_data_b64 = 'ZmFrZSB1c2VyZGF0YQ=='
        userdata_key = "%s/user-data" % self._module.MD_INSTANCE_ATTR
        userdata_enc_key = (
            "%s/user-data-encoding" % self._module.MD_INSTANCE_ATTR)

        def _get_cache_data_side_effect(*args, **kwargs):
            if args[0] == ("%s/user-data" % self._module.MD_INSTANCE_ATTR):
                return user_data_b64
            return 'base64'
        mock_get_cache_data.side_effect = _get_cache_data_side_effect

        response = self._service.get_user_data()

        mock_calls = [mock.call(userdata_key),
                      mock.call(userdata_enc_key, decode=True)]
        mock_get_cache_data.assert_has_calls(mock_calls)
        self.assertEqual(response, user_data) 
开发者ID:cloudbase,项目名称:cloudbase-init,代码行数:21,代码来源:test_gceservice.py

示例11: test_no_organization

# 需要导入模块: import ddt [as 别名]
# 或者: from ddt import data [as 别名]
def test_no_organization(self, mock_consul):
        """
        GET+POST - An instance manager without an organization can't see/update any PR.
        """
        self.api_client.login(username='user5', password='pass')
        watched_pr = make_watched_pr_and_instance(branch_name='api-test-branch')

        response = self.api_client.get('/api/v1/pr_watch/')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data, [])

        response = self.api_client.get('/api/v1/pr_watch/{pk}/'.format(pk=watched_pr.pk))
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)

        response = self.api_client.post('/api/v1/pr_watch/{pk}/update_instance/'.format(pk=watched_pr.pk))
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) 
开发者ID:open-craft,项目名称:opencraft,代码行数:18,代码来源:test_api.py

示例12: test_update_instance_branch_delete

# 需要导入模块: import ddt [as 别名]
# 或者: from ddt import data [as 别名]
def test_update_instance_branch_delete(self, mock_get_pr_by_number, mock_get_commit_id_from_ref, mock_consul):
        """
        Test what happens when we try to update an instance for a PR whose branch has been
        deleted.

        Note: Once WatchedPullRequest.update_instance_from_pr() has been refactored so that it
        first queries GitHub for PR details (rather than accepting a PR parameter), it can get
        the commit ID from the PR details response, rather than using get_branch_tip(), and then
        this test won't be necessary since the PR API always contains the commit information
        (in ["head"]["sha"]) even if the branch has been deleted.
        """
        self.api_client.login(username='user3', password='pass')

        watched_pr = make_watched_pr_and_instance()
        mock_get_pr_by_number.return_value = PRFactory(number=watched_pr.github_pr_number)
        response = self.api_client.post('/api/v1/pr_watch/{pk}/update_instance/'.format(pk=watched_pr.pk))
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(response.data, {'error': 'Could not fetch updated details from GitHub.'}) 
开发者ID:open-craft,项目名称:opencraft,代码行数:20,代码来源:test_api.py

示例13: test_not_all_appservers_are_loaded_by_default

# 需要导入模块: import ddt [as 别名]
# 或者: from ddt import data [as 别名]
def test_not_all_appservers_are_loaded_by_default(self, mock_consul):
        """
        Tries to add e.g. 7 appservers and then verifies that only 5 are returned initially.
        That is, the results are filtered by the NUM_INITIAL_APPSERVERS_SHOWN setting.
        """
        self.api_client.login(username='user3', password='pass')
        instance = OpenEdXInstanceFactory(sub_domain='domain.api')
        for _ in range(settings.NUM_INITIAL_APPSERVERS_SHOWN + 2):
            make_test_appserver(instance)

        response = self.api_client.get('/api/v1/instance/{pk}/'.format(pk=instance.ref.pk))
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        # After creating e.g. 7, we check that 7 exist but only 5 are loaded
        self.assertEqual(response.data['appserver_count'], settings.NUM_INITIAL_APPSERVERS_SHOWN + 2)
        self.assertTrue(
            len(response.data['appservers']) <= settings.NUM_INITIAL_APPSERVERS_SHOWN,
            "Too many initial app servers for instance detail"
        ) 
开发者ID:open-craft,项目名称:opencraft,代码行数:21,代码来源:test_instance.py

示例14: test_get_log_entries

# 需要导入模块: import ddt [as 别名]
# 或者: from ddt import data [as 别名]
def test_get_log_entries(self, mock_consul):
        """
        GET - Log entries
        """
        self.api_client.login(username='user3', password='pass')
        instance = OpenEdXInstanceFactory(name="Test!")
        instance.logger.info("info")
        instance.logger.error("error")

        response = self.api_client.get('/api/v1/instance/{pk}/logs/'.format(pk=instance.ref.pk))
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        expected_list = [
            {'level': 'INFO', 'text': 'instance.models.instance  | instance={inst_id} (Test!) | info'},
            {'level': 'ERROR', 'text': 'instance.models.instance  | instance={inst_id} (Test!) | error'},
        ]
        log_entries = response.data['log_entries']
        self.assertEqual(len(expected_list), len(log_entries))

        for expected_entry, log_entry in zip(expected_list, log_entries):
            self.assertEqual(expected_entry['level'], log_entry['level'])
            self.assertEqual(expected_entry['text'].format(inst_id=instance.ref.pk), log_entry['text'])
            self.assertEqual(expected_entry['text'].format(inst_id=instance.ref.pk), log_entry['text']) 
开发者ID:open-craft,项目名称:opencraft,代码行数:25,代码来源:test_instance.py

示例15: test_get_app_servers_list

# 需要导入模块: import ddt [as 别名]
# 或者: from ddt import data [as 别名]
def test_get_app_servers_list(self, mock_consul):
        """
        GET - App Servers
        """
        self.api_client.login(username='user3', password='pass')
        instance = OpenEdXInstanceFactory(name="Test!")

        for _ in range(10):
            make_test_appserver(instance)

        response = self.api_client.get('/api/v1/instance/{pk}/app_servers/'.format(pk=instance.ref.pk))

        self.assertEqual(response.status_code, status.HTTP_200_OK)

        self.assertTrue('app_servers' in response.data)

        # Verify that all of them are returned, not only NUM_INITIAL_APPSERVERS_SHOWN
        self.assertEqual(len(response.data['app_servers']), 10)
        self.assertTrue('name' in response.data['app_servers'][0])
        self.assertTrue('name' in response.data['app_servers'][9]) 
开发者ID:open-craft,项目名称:opencraft,代码行数:22,代码来源:test_instance.py


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