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


Python MagicMock.user方法代码示例

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


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

示例1: test_get_storefront

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import user [as 别名]
    def test_get_storefront(self):
        """
        test for model_access.get_storefront()

        TODO: test for correct fields returned, number of entries returned,
            and ordering. Might want to use factories here (instead of the
            sample data generator)

        """
        request = MagicMock()
        request.user = 'wsmith'
        request.query_params.get.side_effect = lambda *arg: True

        data, extra_data = model_access.get_storefront(request)

        # test that only APPROVED listings are returned
        for i in data['recommended']:
            self.assertEqual(i.approval_status, models.Listing.APPROVED)

        for i in data['featured']:
            self.assertEqual(i.approval_status, models.Listing.APPROVED)

        for i in data['recent']:
            self.assertEqual(i.approval_status, models.Listing.APPROVED)

        for i in data['most_popular']:
            self.assertEqual(i.approval_status, models.Listing.APPROVED)
开发者ID:aml-development,项目名称:ozp-backend,代码行数:29,代码来源:test_storefront.py

示例2: _render_stars_template

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import user [as 别名]
 def _render_stars_template(self, username, object):
     t = Template(
         "{% load stars_tags %}"
         "{% get_stars object as stars %}"
     )
     r = MagicMock()
     r.user = self.users[username]
     c = Context(dict(request=r, object=object))
     r = t.render(c)
     # get_stars は何も描画しない
     self.assertEqual(r.strip(), "")
     return c['stars']
开发者ID:Clpsplug,项目名称:Kawaz3rd,代码行数:14,代码来源:test_templatetags.py

示例3: _render_template_with_author

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import user [as 别名]
 def _render_template_with_author(self, username, author):
     t = Template(
         "{% load blogs_tags %}"
         "{% get_published_entries_of user as entries %}"
     )
     r = MagicMock()
     r.user = self.users[username]
     c = Context(dict(request=r, user=author))
     r = t.render(c)
     # get_blog_entries は何も描画しない
     self.assertEqual(r.strip(), "")
     return c['entries']
开发者ID:Clpsplug,项目名称:Kawaz3rd,代码行数:14,代码来源:test_templatetags.py

示例4: _render_template_with_member

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import user [as 别名]
 def _render_template_with_member(self, username, member):
     t = Template(
         "{% load projects_tags %}"
         "{% get_published_projects_members_of member as projects %}"
     )
     r = MagicMock()
     r.user = self.users[username]
     c = Context(dict(request=r, member=member))
     r = t.render(c)
     # get_blog_projects は何も描画しない
     self.assertEqual(r.strip(), "")
     return c['projects']
开发者ID:Clpsplug,项目名称:Kawaz3rd,代码行数:14,代码来源:test_templatetags.py

示例5: _render_template

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import user [as 别名]
 def _render_template(self, username, lookup=''):
     t = Template(
         "{{% load events_tags %}}"
         "{{% get_events {} as events %}}".format(
             "'{}'".format(lookup) if lookup else ''
         )
     )
     r = MagicMock()
     r.user = self.users[username]
     c = Context(dict(request=r))
     r = t.render(c)
     # get_blog_events は何も描画しない
     self.assertEqual(r.strip(), "")
     return c['events']
开发者ID:Clpsplug,项目名称:Kawaz3rd,代码行数:16,代码来源:test_templatetags.py

示例6: init_issues

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import user [as 别名]
 def init_issues(self):
     issue = MagicMock()
     repository = MagicMock()
     repository.url = "repository_url"
     issue.id = 3
     issue.url = "issue_url"
     issue.repository = repository
     issue.labels_url = "labels_url"
     issue.comments_url = "comments_url"
     issue.events_url = "events_url"
     issue.html_url = "html_url"
     issue.number = 5
     issue.state = "open"
     issue.title = "title"
     issue.body = "git gud or git rekt"
     issue.user = self.init_user(self)
     issue.assignee = None
     issue.milestone = None
     issue.labels = None
     issue.comments = "comments"
     issue.pull_request = None
     return [issue]
开发者ID:luiseduardo1,项目名称:Github-API,代码行数:24,代码来源:GithubTest.py

示例7: test_send_notifications_using_services_method

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

示例8: test_send_notifications_using_services_method

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

示例9: test_invalid_code

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import user [as 别名]
 def test_invalid_code(self, m_verify):
     m_verify.return_value = True
     request = MagicMock()
     request.user = UserFactory.build()
     form = forms.OtpForm(request, {'code': '0'})
     self.assertFalse(form.is_valid())
开发者ID:node13h,项目名称:droll,代码行数:8,代码来源:test_forms.py

示例10: test_send_notifications_using_services_method

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


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