本文整理汇总了Python中mock.MagicMock.description方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.description方法的具体用法?Python MagicMock.description怎么用?Python MagicMock.description使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.MagicMock
的用法示例。
在下文中一共展示了MagicMock.description方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import description [as 别名]
def setUp(self):
# Mock resource model
resource1 = MagicMock()
resource1.name = 'Resource1'
resource1.version = '1.0'
resource1.description = 'Test resource 1'
resource1.content_type = 'text/plain'
resource1.state = 'created'
resource1.open = False
resource1.get_url.return_value = 'http://localhost/media/resources/resource1'
resource2 = MagicMock()
resource2.name = 'Resource2'
resource2.version = '2.0'
resource2.description = 'Test resource 2'
resource2.content_type = 'text/plain'
resource2.state = 'created'
resource2.open = False
resource2.get_url.return_value = 'http://localhost/media/resources/resource2'
resource3 = MagicMock()
resource3.name = 'Resource3'
resource3.version = '2.0'
resource3.description = 'Test resource 3'
resource3.content_type = 'text/plain'
resource3.state = 'created'
resource3.open = True
resource3.get_url.return_value = 'http://localhost/media/resources/resource3'
resource4 = MagicMock()
resource4.name = 'Resource4'
resource4.version = '1.0'
resource4.description = 'Test resource 4'
resource4.content_type = 'text/plain'
resource4.state = 'created'
resource4.open = True
resource4.get_url.return_value = 'http://localhost/media/resources/resource4'
resource4.offerings = ['1111', '2222']
resources_management.Resource = MagicMock()
resources_management.Resource.objects.filter.return_value = [
resource1,
resource2,
resource3,
resource4
]
self.user = MagicMock()
self.org = MagicMock()
self.user.userprofile.current_organization = self.org
示例2: test_init
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import description [as 别名]
def test_init(self, release_mock):
repo_mock = MagicMock()
repo_mock.description = u'Takes a jinja2 template and some json and sends an email'
repo_mock.forks_count = 1
repo_mock.html_url = u'https://github.com/sanger-pathogens/json2email'
repo_mock.name = u'json2email'
repo_mock.stargazers_count = 1
repo_mock.updated_at = datetime.datetime(2015, 3, 28, 16, 58, 12)
repo_mock.url = u'https://api.github.com/repos/sanger-pathogens/json2email'
repo = RepoParser(repo_mock)
self.assertEqual(repo.name, u'json2email')
self.assertEqual(
repo.description,
u'Takes a jinja2 template and some json and sends an email'
)
self.assertEqual(
repo.html_url,
u'https://github.com/sanger-pathogens/json2email'
)
self.assertEqual(
repo.updated_at,
datetime.datetime(2015, 3, 28, 16, 58, 12)
)
self.assertEqual(repo.stargazers_count, 1)
self.assertEqual(repo.forks_count, 1)
release_mock.assert_called_once_with(
u'https://api.github.com/repos/sanger-pathogens/json2email',
None
)
示例3: test_update_project_another_error
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import description [as 别名]
def test_update_project_another_error(self, find_mock):
"""Test update_project another error works."""
project = MagicMock()
project.name = 'name'
project.short_name = 'short_name'
project.description = 'description'
project.info = dict()
find_mock.return_value = project
task_presenter = "test/template.html"
results = "test/results.html"
tutorial = "test/tutorial.html"
long_description = "test/long_description.md"
pbclient = MagicMock()
pbclient.update_project.return_value = self.error
self.config.pbclient = pbclient
res = _update_project(self.config, task_presenter, results,
long_description, tutorial)
msg = ("Project not found! The project: short_name is missing." \
" Use the flag --all=1 to search in all the server ")
assert res == msg, msg
示例4: test_add_tasks_po_from_filextension
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import description [as 别名]
def test_add_tasks_po_from_filextension(self, find_mock, po_mock):
"""Test add_tasks po without specifying file extension works."""
project = MagicMock()
project.name = 'name'
project.short_name = 'short_name'
project.description = 'description'
project.info = dict()
find_mock.return_value = project
entry = MagicMock()
entry.msgid = 'English'
entry.msgtr = ''
po = MagicMock()
po.untranslated_entries.return_value = [entry]
po_mock.return_value = po
tasks = MagicMock()
tasks.name = 'tasks.po'
tasks.read.return_value = json.dumps([{'info': {'msgid': 'English',
'msgtr':''}}])
pbclient = MagicMock()
pbclient.create_task.return_value = {'id': 1, 'info': {'msgid': 'English',
'msgtr': ''}}
self.config.pbclient = pbclient
res = _add_tasks(self.config, tasks, None, 0, 30)
assert res == '1 tasks added to project: short_name', res
示例5: test_add_helping_materials_excel_with_info
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import description [as 别名]
def test_add_helping_materials_excel_with_info(self, auto_mock, find_mock, workbook_mock):
"""Test add_helpingmaterials excel with info field works."""
auto_mock.return_value = (0, None)
project = MagicMock()
project.name = 'name'
project.short_name = 'short_name'
project.description = 'description'
project.info = dict()
project.id = 1
wb = Workbook()
ws = wb.active
headers = ['Column Name', 'foo']
ws.append(headers)
for row in range(2, 10):
ws.append(['value', 'bar'])
ws.append([None, None])
ws.append([None, None])
find_mock.return_value = project
helpingmaterials = MagicMock()
helpingmaterials.read.return_value = wb
workbook_mock.return_value = wb
pbclient = MagicMock()
self.config.pbclient = pbclient
res = _add_helpingmaterials(self.config, helpingmaterials, 'xlsx')
self.config.pbclient.create_helpingmaterial.assert_called_with(project_id=find_mock().id,
info={u'column_name': u'value',
u'foo': u'bar'})
assert res == '8 helping materials added to project: short_name', res
示例6: test_execute_query
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import description [as 别名]
def test_execute_query(self, mock_db, mock_statsd, mock_statsd_scoring):
mock_cursor = MagicMock(spec=Cursor)
mock_cursor.fetchall.return_value = DUMMY_QUERY['rows']
mock_cursor.description = DUMMY_QUERY['description']
db = MagicMock()
db.cursor = MagicMock(return_value=mock_cursor)
results = self.grader.execute_query(db, DUMMY_QUERY['query'])
self.assertEquals(DUMMY_QUERY['result'], results)
示例7: test_delete_another_error_one_tasks
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import description [as 别名]
def test_delete_another_error_one_tasks(self, find_mock):
"""Test delete tasks another error works for one task."""
project = MagicMock()
project.name = 'name'
project.short_name = 'short_name'
project.description = 'description'
project.info = dict()
find_mock.return_value = project
pbclient = MagicMock()
pbclient.delete_task.return_value = self.error_task
self.config.pbclient = pbclient
assert_raises(TaskNotFound, _delete_tasks, self.config, 1)
示例8: test_delete_connection_error
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import description [as 别名]
def test_delete_connection_error(self, find_mock):
"""Test delete tasks connection error works."""
project = MagicMock()
project.name = 'name'
project.short_name = 'short_name'
project.description = 'description'
project.info = dict()
find_mock.return_value = project
pbclient = MagicMock()
pbclient.delete_task.side_effect = exceptions.ConnectionError
self.config.pbclient = pbclient
res = _delete_tasks(self.config, 1)
assert res == "Connection Error! The server http://server is not responding", res
示例9: test_delete_task
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import description [as 别名]
def test_delete_task(self, find_mock):
"""Test delete task works."""
project = MagicMock()
project.name = 'name'
project.short_name = 'short_name'
project.description = 'description'
project.info = dict()
find_mock.return_value = project
pbclient = MagicMock()
pbclient.delete_task.return_value = []
self.config.pbclient = pbclient
res = _delete_tasks(self.config, 1)
assert res == "Task.id = 1 and its associated task_runs have been deleted", res
示例10: _generate_basic_datarequest
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import description [as 别名]
def _generate_basic_datarequest(id=DATAREQUEST_ID, user_id='example_uuidv4_user',
title='This is a title', description='This is a basic description',
organization_id='example_uuidv4_organization', closed=False):
datarequest = MagicMock()
datarequest.id = id
datarequest.user_id = user_id
datarequest.title = title
datarequest.description = description
datarequest.organization_id = organization_id
datarequest.open_time = datetime.datetime.now()
datarequest.closed = closed
datarequest.close_time = None
datarequest.accepted_dataset_id = None
datarequest.accepted_dataset = {'test': 'test1', 'test2': 'test3'}
return datarequest
示例11: test_delete_another_error_all_tasks
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import description [as 别名]
def test_delete_another_error_all_tasks(self, find_mock):
"""Test delete tasks another error works for all tasks."""
project = MagicMock()
project.name = 'name'
project.short_name = 'short_name'
project.description = 'description'
project.info = dict()
find_mock.return_value = project
pbclient = MagicMock()
pbclient.delete_task.return_value = self.error
task = MagicMock()
task.id = 1
pbclient.get_tasks.return_value = [task]
self.config.pbclient = pbclient
assert_raises(ProjectNotFound, _delete_tasks, self.config, None)
示例12: test_update_task_redundancy_fails
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import description [as 别名]
def test_update_task_redundancy_fails(self, auto_mock, find_mock):
"""Test update task redundancy fails works."""
auto_mock.return_value = (0, None)
project = MagicMock()
project.name = 'name'
project.short_name = 'short_name'
project.description = 'description'
project.info = dict()
find_mock.return_value = project
pbclient = MagicMock()
pbclient.find_tasks.return_value = self.error_task
self.config.pbclient = pbclient
assert_raises(TaskNotFound, _update_tasks_redundancy, self.config,
9999, 5)
示例13: test_update_task_redundancy_individually
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import description [as 别名]
def test_update_task_redundancy_individually(self, auto_mock, find_mock):
"""Test update task redundancy individually works."""
auto_mock.return_value = (0, None)
project = MagicMock()
project.name = 'name'
project.short_name = 'short_name'
project.description = 'description'
project.info = dict()
find_mock.return_value = project
pbclient = MagicMock()
self.config.pbclient = pbclient
res = _update_tasks_redundancy(self.config, 1, 5)
msg = "Task.id = 1 redundancy has been updated to 5"
assert res == msg, res
示例14: test_get_sinks
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import description [as 别名]
def test_get_sinks(self):
request = MagicMock()
sink = MagicMock()
sink.channel_count = 2
sink.channel_list = ["front-left", "front-right"]
sink.description = "test"
sink.index = 0
sink.name = "test"
sink.volume = MagicMock()
sink.volume.values = [1.0, 1.0]
self.pulse.sink_list.return_value = [sink]
response = self.api.get_sinks(request)
data = json.loads(response)
assert len(data) == 1
assert data[0]['name'] == "test"
示例15: test_add_tasks_another_error
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import description [as 别名]
def test_add_tasks_another_error(self, find_mock):
"""Test add_tasks another error works."""
project = MagicMock()
project.name = 'name'
project.short_name = 'short_name'
project.description = 'description'
project.info = dict()
find_mock.return_value = project
tasks = MagicMock()
tasks.read.return_value = json.dumps([{'key': 'value'}])
pbclient = MagicMock()
pbclient.create_task.return_value = self.error
self.config.pbclient = pbclient
assert_raises(ProjectNotFound, _add_tasks, self.config,
tasks, 'json', 0, 30)