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


Python MagicMock.owner方法代码示例

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


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

示例1: test_users_to_notify

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import owner [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()}
开发者ID:FlorianBezagu,项目名称:taiga-back,代码行数:60,代码来源:test_notifications.py

示例2: test_ok

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import owner [as 别名]
    def test_ok(self, PathInfo):
        path_info = MagicMock()
        path_info.mode = "0664"
        path_info.owner = "root"
        path_info.group = "root"
        path_info.is_directory = True
        PathInfo.return_value = path_info

        f = directories.Directory(MagicMock(), "/", {"mode": "0664", "owner": "root", "group": "root"})
        status = f.get_status()
        self.assertTrue(status.correct)
        self.assertEqual(status.info["needs_fixing"], [])
开发者ID:lowks,项目名称:bundlewrap,代码行数:14,代码来源:directories_tests.py

示例3: test_analize_object_for_watchers_adding_owner_non_empty_comment

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import owner [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
开发者ID:tnir,项目名称:taiga-back,代码行数:15,代码来源:test_notifications.py

示例4: test_group

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import owner [as 别名]
    def test_group(self, PathInfo):
        path_info = MagicMock()
        path_info.mode = "0664"
        path_info.owner = "root"
        path_info.group = "yolocrowd"
        path_info.is_directory = True
        PathInfo.return_value = path_info

        f = directories.Directory(MagicMock(), "/", {
            'mode': "0664",
            'owner': "root",
            'group': "root",
        })
        status = f.get_status()
        self.assertFalse(status.correct)
        self.assertEqual(status.info['needs_fixing'], ['group'])
开发者ID:jrragan,项目名称:bundlewrap,代码行数:18,代码来源:directories_tests.py

示例5: test_ok

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import owner [as 别名]
    def test_ok(self, PathInfo):
        path_info = MagicMock()
        path_info.mode = "0664"
        path_info.owner = "root"
        path_info.group = "root"
        path_info.sha1 = "47"
        path_info.is_file = True
        PathInfo.return_value = path_info

        f = files.File(MagicMock(), "/foo", {
            'mode': "0664",
            'owner': "root",
            'group': "root",
        })
        status = f.get_status()
        self.assertTrue(status.correct)
        self.assertEqual(status.info['needs_fixing'], [])
开发者ID:jrragan,项目名称:bundlewrap,代码行数:19,代码来源:files_tests.py

示例6: test_ok

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import owner [as 别名]
    def test_ok(self, PathInfo):
        path_info = MagicMock()
        path_info.mode = "0777"
        path_info.owner = "root"
        path_info.group = "root"
        path_info.is_symlink = True
        path_info.symlink_target = "/bar"
        PathInfo.return_value = path_info

        f = symlinks.Symlink(MagicMock(), "/foo", {
            'owner': "root",
            'group': "root",
            'target': "/bar",
        })
        status = f.get_status()
        self.assertTrue(status.correct)
        self.assertEqual(status.info['needs_fixing'], [])
开发者ID:bkendinibilir,项目名称:bundlewrap,代码行数:19,代码来源:symlinks_tests.py

示例7: test_type

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import owner [as 别名]
    def test_type(self, PathInfo):
        path_info = MagicMock()
        path_info.mode = "0777"
        path_info.owner = "root"
        path_info.group = "root"
        path_info.is_symlink = False
        PathInfo.return_value = path_info

        f = symlinks.Symlink(MagicMock(), "/foo", {
            'owner': "root",
            'group': "root",
            'target': "/bar",
        })
        status = f.get_status()
        self.assertFalse(status.correct)
        self.assertEqual(
            set(status.info['needs_fixing']),
            set(['type']),
        )
开发者ID:bkendinibilir,项目名称:bundlewrap,代码行数:21,代码来源:symlinks_tests.py

示例8: test_users_to_notify

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import owner [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)
#.........这里部分代码省略.........
开发者ID:tnir,项目名称:taiga-back,代码行数:103,代码来源:test_notifications.py

示例9: test_send_notifications_using_services_method

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import owner [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
开发者ID:6ft,项目名称:taiga-back,代码行数:78,代码来源:test_project_notifications.py


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