本文整理汇总了Python中unittest.mock.MagicMock.comment方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.comment方法的具体用法?Python MagicMock.comment怎么用?Python MagicMock.comment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest.mock.MagicMock
的用法示例。
在下文中一共展示了MagicMock.comment方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_users_to_notify
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import comment [as 别名]
def test_users_to_notify():
project = f.ProjectFactory.create()
role1 = f.RoleFactory.create(project=project, permissions=['view_issues'])
role2 = f.RoleFactory.create(project=project, permissions=[])
member1 = f.MembershipFactory.create(project=project, role=role1)
member2 = f.MembershipFactory.create(project=project, role=role1)
member3 = f.MembershipFactory.create(project=project, role=role1)
member4 = f.MembershipFactory.create(project=project, role=role1)
member5 = f.MembershipFactory.create(project=project, role=role2)
issue = f.IssueFactory.create(project=project, owner=member4.user)
policy_model_cls = apps.get_model("notifications", "NotifyPolicy")
policy1 = policy_model_cls.objects.get(user=member1.user)
policy2 = policy_model_cls.objects.get(user=member2.user)
policy3 = policy_model_cls.objects.get(user=member3.user)
history = MagicMock()
history.owner = member2.user
history.comment = ""
# Test basic description modifications
issue.description = "test1"
issue.save()
users = services.get_users_to_notify(issue)
assert len(users) == 1
assert tuple(users)[0] == issue.get_owner()
# Test watch notify level in one member
policy1.notify_level = NotifyLevel.watch
policy1.save()
users = services.get_users_to_notify(issue)
assert len(users) == 2
assert users == {member1.user, issue.get_owner()}
# Test with watchers
issue.watchers.add(member3.user)
users = services.get_users_to_notify(issue)
assert len(users) == 3
assert users == {member1.user, member3.user, issue.get_owner()}
# Test with watchers with ignore policy
policy3.notify_level = NotifyLevel.ignore
policy3.save()
issue.watchers.add(member3.user)
users = services.get_users_to_notify(issue)
assert len(users) == 2
assert users == {member1.user, issue.get_owner()}
# Test with watchers without permissions
issue.watchers.add(member5.user)
users = services.get_users_to_notify(issue)
assert len(users) == 2
assert users == {member1.user, issue.get_owner()}
示例2: test_analize_object_for_watchers_adding_owner_non_empty_comment
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import comment [as 别名]
def test_analize_object_for_watchers_adding_owner_non_empty_comment():
user1 = f.UserFactory.create()
issue = MagicMock()
issue.description = "Foo"
issue.content = ""
history = MagicMock()
history.comment = "Comment"
history.owner = user1
services.analize_object_for_watchers(issue, history.comment, history.owner)
assert issue.add_watcher.call_count == 1
示例3: test_analize_object_for_watchers
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import comment [as 别名]
def test_analize_object_for_watchers():
user1 = f.UserFactory.create()
user2 = f.UserFactory.create()
issue = MagicMock()
issue.description = "Foo @{0} @{1} ".format(user1.username, user2.username)
issue.content = ""
history = MagicMock()
history.comment = ""
services.analize_object_for_watchers(issue, history.comment, history.owner)
assert issue.add_watcher.call_count == 2
示例4: test_users_to_notify
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import comment [as 别名]
def test_users_to_notify():
project = f.ProjectFactory.create()
role1 = f.RoleFactory.create(project=project, permissions=['view_issues'])
role2 = f.RoleFactory.create(project=project, permissions=[])
member1 = f.MembershipFactory.create(project=project, role=role1)
policy_member1 = member1.user.notify_policies.get(project=project)
policy_member1.notify_level = NotifyLevel.none
policy_member1.save()
member2 = f.MembershipFactory.create(project=project, role=role1)
policy_member2 = member2.user.notify_policies.get(project=project)
policy_member2.notify_level = NotifyLevel.none
policy_member2.save()
member3 = f.MembershipFactory.create(project=project, role=role1)
policy_member3 = member3.user.notify_policies.get(project=project)
policy_member3.notify_level = NotifyLevel.none
policy_member3.save()
member4 = f.MembershipFactory.create(project=project, role=role1)
policy_member4 = member4.user.notify_policies.get(project=project)
policy_member4.notify_level = NotifyLevel.none
policy_member4.save()
member5 = f.MembershipFactory.create(project=project, role=role2)
policy_member5 = member5.user.notify_policies.get(project=project)
policy_member5.notify_level = NotifyLevel.none
policy_member5.save()
inactive_member1 = f.MembershipFactory.create(project=project, role=role1)
inactive_member1.user.is_active = False
inactive_member1.user.save()
system_member1 = f.MembershipFactory.create(project=project, role=role1)
system_member1.user.is_system = True
system_member1.user.save()
issue = f.IssueFactory.create(project=project, owner=member4.user)
policy_model_cls = apps.get_model("notifications", "NotifyPolicy")
policy_inactive_member1 = policy_model_cls.objects.get(user=inactive_member1.user)
policy_inactive_member1.notify_level = NotifyLevel.all
policy_inactive_member1.save()
policy_system_member1 = policy_model_cls.objects.get(user=system_member1.user)
policy_system_member1.notify_level = NotifyLevel.all
policy_system_member1.save()
history = MagicMock()
history.owner = member2.user
history.comment = ""
# Test basic description modifications
issue.description = "test1"
issue.save()
policy_member4.notify_level = NotifyLevel.all
policy_member4.save()
users = services.get_users_to_notify(issue)
assert len(users) == 1
assert tuple(users)[0] == issue.get_owner()
# Test watch notify level in one member
policy_member1.notify_level = NotifyLevel.all
policy_member1.save()
del project.cached_notify_policies
users = services.get_users_to_notify(issue)
assert len(users) == 2
assert users == {member1.user, issue.get_owner()}
# Test with watchers
issue.add_watcher(member3.user)
policy_member3.notify_level = NotifyLevel.all
policy_member3.save()
del project.cached_notify_policies
users = services.get_users_to_notify(issue)
assert len(users) == 3
assert users == {member1.user, member3.user, issue.get_owner()}
# Test with watchers with ignore policy
policy_member3.notify_level = NotifyLevel.none
policy_member3.save()
issue.add_watcher(member3.user)
del project.cached_notify_policies
users = services.get_users_to_notify(issue)
assert len(users) == 2
assert users == {member1.user, issue.get_owner()}
# Test with watchers without permissions
issue.add_watcher(member5.user)
del project.cached_notify_policies
users = services.get_users_to_notify(issue)
assert len(users) == 2
assert users == {member1.user, issue.get_owner()}
# Test with inactive user
issue.add_watcher(inactive_member1.user)
assert len(users) == 2
assert users == {member1.user, issue.get_owner()}
# Test with system user
issue.add_watcher(system_member1.user)
#.........这里部分代码省略.........
示例5: test_send_notifications_using_services_method
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import comment [as 别名]
def test_send_notifications_using_services_method(settings, mail):
settings.CHANGE_NOTIFICATIONS_MIN_INTERVAL = 1
project = f.ProjectFactory.create()
role = f.RoleFactory.create(project=project, permissions=['view_issues', 'view_us', 'view_tasks', 'view_wiki_pages'])
member1 = f.MembershipFactory.create(project=project, role=role)
member2 = f.MembershipFactory.create(project=project, role=role)
history_change = MagicMock()
history_change.user = {"pk": member1.user.pk}
history_change.comment = ""
history_change.type = HistoryType.change
history_change.is_hidden = False
history_create = MagicMock()
history_create.user = {"pk": member1.user.pk}
history_create.comment = ""
history_create.type = HistoryType.create
history_create.is_hidden = False
history_delete = MagicMock()
history_delete.user = {"pk": member1.user.pk}
history_delete.comment = ""
history_delete.type = HistoryType.delete
history_delete.is_hidden = False
# Issues
issue = f.IssueFactory.create(project=project, owner=member2.user)
take_snapshot(issue)
services.send_notifications(issue,
history=history_create)
services.send_notifications(issue,
history=history_change)
services.send_notifications(issue,
history=history_delete)
# Userstories
us = f.UserStoryFactory.create(project=project, owner=member2.user)
take_snapshot(us)
services.send_notifications(us,
history=history_create)
services.send_notifications(us,
history=history_change)
services.send_notifications(us,
history=history_delete)
# Tasks
task = f.TaskFactory.create(project=project, owner=member2.user)
take_snapshot(task)
services.send_notifications(task,
history=history_create)
services.send_notifications(task,
history=history_change)
services.send_notifications(task,
history=history_delete)
# Wiki pages
wiki = f.WikiPageFactory.create(project=project, owner=member2.user)
take_snapshot(wiki)
services.send_notifications(wiki,
history=history_create)
services.send_notifications(wiki,
history=history_change)
services.send_notifications(wiki,
history=history_delete)
assert models.HistoryChangeNotification.objects.count() == 12
assert len(mail.outbox) == 0
time.sleep(1)
services.process_sync_notifications()
assert len(mail.outbox) == 12
示例6: test_send_notifications_using_services_method
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import comment [as 别名]
def test_send_notifications_using_services_method(settings, mail):
settings.CHANGE_NOTIFICATIONS_MIN_INTERVAL = 1
project = f.ProjectFactory.create()
role = f.RoleFactory.create(project=project, permissions=['view_issues', 'view_us', 'view_tasks', 'view_wiki_pages'])
member1 = f.MembershipFactory.create(project=project, role=role)
member2 = f.MembershipFactory.create(project=project, role=role)
history_change = MagicMock()
history_change.user = {"pk": member1.user.pk}
history_change.comment = ""
history_change.type = HistoryType.change
history_change.is_hidden = False
history_create = MagicMock()
history_create.user = {"pk": member1.user.pk}
history_create.comment = ""
history_create.type = HistoryType.create
history_create.is_hidden = False
history_delete = MagicMock()
history_delete.user = {"pk": member1.user.pk}
history_delete.comment = ""
history_delete.type = HistoryType.delete
history_delete.is_hidden = False
# Issues
issue = f.IssueFactory.create(project=project, owner=member2.user)
take_snapshot(issue, user=issue.owner)
services.send_notifications(issue,
history=history_create)
services.send_notifications(issue,
history=history_change)
services.send_notifications(issue,
history=history_delete)
# Userstories
us = f.UserStoryFactory.create(project=project, owner=member2.user)
take_snapshot(us, user=us.owner)
services.send_notifications(us,
history=history_create)
services.send_notifications(us,
history=history_change)
services.send_notifications(us,
history=history_delete)
# Tasks
task = f.TaskFactory.create(project=project, owner=member2.user)
take_snapshot(task, user=task.owner)
services.send_notifications(task,
history=history_create)
services.send_notifications(task,
history=history_change)
services.send_notifications(task,
history=history_delete)
# Wiki pages
wiki = f.WikiPageFactory.create(project=project, owner=member2.user)
take_snapshot(wiki, user=wiki.owner)
services.send_notifications(wiki,
history=history_create)
services.send_notifications(wiki,
history=history_change)
services.send_notifications(wiki,
history=history_delete)
assert models.HistoryChangeNotification.objects.count() == 12
assert len(mail.outbox) == 0
time.sleep(1)
services.process_sync_notifications()
assert len(mail.outbox) == 12
# test headers
events = [issue, us, task, wiki]
domain = settings.SITES["api"]["domain"].split(":")[0] or settings.SITES["api"]["domain"]
i = 0
for msg in mail.outbox:
# each event has 3 msgs
event = events[math.floor(i / 3)]
# each set of 3 should have the same headers
if i % 3 == 0:
if hasattr(event, 'ref'):
e_slug = event.ref
elif hasattr(event, 'slug'):
e_slug = event.slug
else:
e_slug = 'taiga-system'
m_id = "{project_slug}/{msg_id}".format(
project_slug=project.slug,
msg_id=e_slug
#.........这里部分代码省略.........
示例7: test_fixme
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import comment [as 别名]
def test_fixme(self, path_read_text, json_load) -> None:
arguments = MagicMock()
arguments.comment = None
arguments.description = False
# Test empty.
json_load.return_value = []
upgrade.run_fixme(arguments)
# Test single error.
with patch.object(pathlib.Path, 'write_text') as path_write_text:
json_load.return_value = [
{
'path': 'path.py',
'line': 1,
'description': 'Error [1]: description',
},
]
path_read_text.return_value = " 1\n2"
upgrade.run_fixme(arguments)
path_write_text.assert_called_once_with(" # pyre-fixme[1]\n 1\n2")
# Test error with comment.
with patch.object(pathlib.Path, 'write_text') as path_write_text:
json_load.return_value = [
{
'path': 'path.py',
'line': 1,
'description': 'Error [1]: description',
},
]
path_read_text.return_value = " 1\n2"
arguments.comment = 'T1234'
upgrade.run_fixme(arguments)
arguments.comment = None
path_write_text.assert_called_once_with(" # pyre-fixme[1]: T1234\n 1\n2")
# Test multiple errors and multiple lines.
with patch.object(pathlib.Path, 'write_text') as path_write_text:
json_load.return_value = [
{
'path': 'path.py',
'line': 1,
'description': 'Error [1]: description',
},
{
'path': 'path.py',
'line': 2,
'description': 'Error [1]: description',
},
{
'path': 'path.py',
'line': 2,
'description': 'Error [2]: description',
},
]
path_read_text.return_value = "1\n2"
upgrade.run_fixme(arguments)
path_write_text.assert_called_once_with(
"# pyre-fixme[1]\n1\n# pyre-fixme[1, 2]\n2")
# Test errors in multiple files.
with patch.object(pathlib.Path, 'write_text') as path_write_text:
json_load.return_value = [
{
'path': 'path.py',
'line': 1,
'description': 'Error [1]: description',
},
{
'path': 'other.py',
'line': 2,
'description': 'Error [2]: description',
},
]
path_read_text.return_value = "1\n2"
upgrade.run_fixme(arguments)
path_write_text.has_calls([
call("# pyre-fixme[1]\n1\n2"),
call("1\n#pyre-fixme[2]\n2"),
])
# Test error with description.
with patch.object(pathlib.Path, 'write_text') as path_write_text:
json_load.return_value = [
{
'path': 'path.py',
'line': 1,
'description': 'Error [2]: description',
},
]
path_read_text.return_value = " 1\n2"
arguments.description = True
upgrade.run_fixme(arguments)
arguments.comment = None
path_write_text.assert_called_once_with(
" # pyre-fixme[2]: description\n 1\n2")
#.........这里部分代码省略.........
示例8: test_send_notifications_using_services_method
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import comment [as 别名]
def test_send_notifications_using_services_method(mail):
project = f.ProjectFactory.create()
member1 = f.MembershipFactory.create(project=project)
member2 = f.MembershipFactory.create(project=project)
history_change = MagicMock()
history_change.user = {"pk": member1.user.pk}
history_change.comment = ""
history_change.type = HistoryType.change
history_create = MagicMock()
history_create.user = {"pk": member1.user.pk}
history_create.comment = ""
history_create.type = HistoryType.create
history_delete = MagicMock()
history_delete.user = {"pk": member1.user.pk}
history_delete.comment = ""
history_delete.type = HistoryType.delete
# Issues
issue = f.IssueFactory.create(project=project)
take_snapshot(issue)
services.send_notifications(issue,
history=history_create)
services.send_notifications(issue,
history=history_change)
services.send_notifications(issue,
history=history_delete)
# Userstories
us = f.UserStoryFactory.create()
take_snapshot(us)
services.send_notifications(us,
history=history_create)
services.send_notifications(us,
history=history_change)
services.send_notifications(us,
history=history_delete)
# Tasks
task = f.TaskFactory.create()
take_snapshot(task)
services.send_notifications(task,
history=history_create)
services.send_notifications(task,
history=history_change)
services.send_notifications(task,
history=history_delete)
# Wiki pages
wiki = f.WikiPageFactory.create()
take_snapshot(wiki)
services.send_notifications(wiki,
history=history_create)
services.send_notifications(wiki,
history=history_change)
services.send_notifications(wiki,
history=history_delete)
assert models.HistoryChangeNotification.objects.count() == 12
assert len(mail.outbox) == 0
time.sleep(1)
services.process_sync_notifications()
assert len(mail.outbox) == 12
示例9: test_send_notifications_using_services_method
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import comment [as 别名]
def test_send_notifications_using_services_method(mail):
project = f.ProjectFactory.create()
member1 = f.MembershipFactory.create(project=project)
member2 = f.MembershipFactory.create(project=project)
history_change = MagicMock()
history_change.owner = member1.user
history_change.comment = ""
history_change.type = HistoryType.change
history_create = MagicMock()
history_create.owner = member1.user
history_create.comment = ""
history_create.type = HistoryType.create
history_delete = MagicMock()
history_delete.owner = member1.user
history_delete.comment = ""
history_delete.type = HistoryType.delete
# Issues
issue = f.IssueFactory.create(project=project)
services.send_notifications(issue,
history=history_create,
users={member1.user, member2.user})
services.send_notifications(issue,
history=history_change,
users={member1.user, member2.user})
services.send_notifications(issue,
history=history_delete,
users={member1.user, member2.user})
# Userstories
us = f.UserStoryFactory.create()
services.send_notifications(us,
history=history_create,
users={member1.user, member2.user})
services.send_notifications(us,
history=history_change,
users={member1.user, member2.user})
services.send_notifications(us,
history=history_delete,
users={member1.user, member2.user})
# Tasks
task = f.TaskFactory.create()
services.send_notifications(task,
history=history_create,
users={member1.user, member2.user})
services.send_notifications(task,
history=history_change,
users={member1.user, member2.user})
services.send_notifications(task,
history=history_delete,
users={member1.user, member2.user})
# Wiki pages
wiki = f.WikiPageFactory.create()
services.send_notifications(wiki,
history=history_create,
users={member1.user, member2.user})
services.send_notifications(wiki,
history=history_change,
users={member1.user, member2.user})
services.send_notifications(wiki,
history=history_delete,
users={member1.user, member2.user})
assert len(mail.outbox) == 24