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


Python MagicMock.is_staff方法代码示例

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


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

示例1: test_search_ascendants

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import is_staff [as 别名]
def test_search_ascendants(categorys):
    user = MagicMock(spec=auth_models.User)
    user.is_staff = True
    queryset = MagicMock(spec=QuerySet)

    expected_result = MagicMock(spec=QuerySet)
    (queryset
        .select_related.return_value
        .prefetch_related.return_value
        .filter.return_value) = expected_result

    params = {'instance': categorys['Parent'].pk, 'mode': 'ascendants'}
    result = models.category.objects.get_search_queryset(
        user, queryset, params)

    chained = (
       call
       .select_related('cover_photo')
       .prefetch_related('cover_photo__photo_file_set')
       .filter(
           descendant_set__descendant=categorys['Parent'],
           descendant_set__position__gt=0)
    )
    assert queryset.mock_calls == chained.call_list()
    assert result is expected_result
开发者ID:brianmay,项目名称:spud,代码行数:27,代码来源:test_search.py

示例2: test_search_q

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import is_staff [as 别名]
def test_search_q():
    user = MagicMock(spec=auth_models.User)
    user.is_staff = True
    queryset = MagicMock(spec=QuerySet)

    expected_result = MagicMock(spec=QuerySet)
    (queryset
        .select_related.return_value
        .prefetch_related.return_value
        .filter.return_value) = expected_result

    params = {'q': ['meow']}
    result = models.place.objects.get_search_queryset(user, queryset, params)

    q = (
        MyQ(title__icontains='meow')
        | MyQ(address__icontains='meow')
        | MyQ(address2__icontains='meow')
        | MyQ(city__icontains='meow')
        | MyQ(state__icontains='meow')
        | MyQ(country__icontains='meow')
    )
    chained = (
       call
       .select_related('cover_photo')
       .prefetch_related('cover_photo__photo_file_set')
       .filter(q)
    )
    assert queryset.mock_calls == chained.call_list()
    assert result is expected_result
开发者ID:brianmay,项目名称:spud,代码行数:32,代码来源:test_search.py

示例3: setUp

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import is_staff [as 别名]
    def setUp(self):
        views.RSS = MagicMock()
        self.rss_object = MagicMock()
        self.views.RSS.objects.all.return_value = [self.rss_object]

        # Create mock request
        user_object = MagicMock()
        user_object.is_staff = True
        user_object.userprofile.actor_id = 2

        self.request = MagicMock()
        self.request.user = user_object

        # Mock user
        views.User = MagicMock()
        views.User.objects.get = MagicMock()
        views.User.objects.get.return_value = user_object

        # Mock Userprofile
        views.UserProfile = FakeProfile()
        views.Organization = FakeOrganization()

        views.RSSManagerFactory = MagicMock()
        self._rss_factory = MagicMock()
        views.RSSManagerFactory.return_value = self._rss_factory

        self.exp_object = MagicMock()
        self._rss_factory.get_expenditure_manager.return_value = self.exp_object
开发者ID:Fiware,项目名称:apps.Wstore,代码行数:30,代码来源:tests.py

示例4: test_search_children

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import is_staff [as 别名]
def test_search_children(persons):
    user = MagicMock(spec=auth_models.User)
    user.is_staff = True
    queryset = MagicMock(spec=QuerySet)

    expected_result = MagicMock(spec=QuerySet)
    (queryset
        .select_related.return_value
        .prefetch_related.return_value
        .select_related.return_value
        .filter.return_value) = expected_result

    params = {'instance': persons['Parent'].pk, 'mode': 'children'}
    result = models.person.objects.get_search_queryset(
        user, queryset, params, 'detail')

    chained = (
       call
       .select_related('cover_photo')
       .prefetch_related('cover_photo__photo_file_set')
       .select_related('mother', 'father', 'spouse', 'home', 'work')
       .filter(MyQ(mother=persons['Parent']) | MyQ(father=persons['Parent']))
    )
    assert queryset.mock_calls == chained.call_list()
    assert result is expected_result
开发者ID:brianmay,项目名称:spud,代码行数:27,代码来源:test_search.py

示例5: test_search_root_only

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import is_staff [as 别名]
def test_search_root_only():
    user = MagicMock(spec=auth_models.User)
    user.is_staff = True
    queryset = MagicMock(spec=QuerySet)

    expected_result = MagicMock(spec=QuerySet)
    (queryset
        .select_related.return_value
        .prefetch_related.return_value
        .select_related.return_value
        .filter.return_value) = expected_result

    params = {'root_only': True}
    result = models.person.objects.get_search_queryset(
        user, queryset, params, 'detail')

    chained = (
       call
       .select_related('cover_photo')
       .prefetch_related('cover_photo__photo_file_set')
       .select_related('mother', 'father', 'spouse', 'home', 'work')
       .filter(mother__isnull=True, father__isnull=True)
    )
    assert queryset.mock_calls == chained.call_list()
    assert result is expected_result
开发者ID:brianmay,项目名称:spud,代码行数:27,代码来源:test_search.py

示例6: test_search_needs_revision

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import is_staff [as 别名]
def test_search_needs_revision():
    user = MagicMock(spec=auth_models.User)
    user.is_staff = True
    queryset = MagicMock(spec=QuerySet)

    expected_result = MagicMock(spec=QuerySet)
    (queryset
        .select_related.return_value
        .prefetch_related.return_value
        .filter.return_value
        .annotate.return_value
        .order_by.return_value) = expected_result

    params = {'needs_revision': True}
    result = models.album.objects.get_search_queryset(user, queryset, params)

    chained = (
       call
       .select_related('cover_photo')
       .prefetch_related('cover_photo__photo_file_set')
       .filter(MyQ(revised__lt=ANY) | MyQ(revised__isnull=True))
       .annotate(null_revised=ANY)
       .order_by('null_revised', 'revised', '-pk')
    )
    assert queryset.mock_calls == chained.call_list()
    assert result is expected_result
开发者ID:brianmay,项目名称:spud,代码行数:28,代码来源:test_search.py

示例7: test_search_related

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import is_staff [as 别名]
def test_search_related(photos):
    user = MagicMock(spec=auth_models.User)
    user.is_staff = True
    queryset = MagicMock(spec=QuerySet)

    expected_result = MagicMock(spec=QuerySet)
    (queryset
        .select_related.return_value
        .prefetch_related.return_value
        .prefetch_related.return_value
        .prefetch_related.return_value
        .prefetch_related.return_value
        .prefetch_related.return_value
        .prefetch_related.return_value
        .prefetch_related.return_value
        .prefetch_related.return_value
        .prefetch_related.return_value
        .prefetch_related.return_value
        .prefetch_related.return_value
        .prefetch_related.return_value
        .prefetch_related.return_value
        .prefetch_related.return_value
        .filter.return_value
        .filter.return_value
        .filter.return_value
        .distinct.return_value) = expected_result

    params = {'instance': photos['Parent'].pk, 'mode': 'children'}
    result = models.photo.objects.get_search_queryset(
        user, queryset, params, 'detail')

    chained = (
       call
       .select_related('place')
       .prefetch_related('photo_file_set')
       .prefetch_related('place__cover_photo')
       .prefetch_related('place__cover_photo__photo_file_set')
       .prefetch_related('feedbacks')
       .prefetch_related('albums')
       .prefetch_related('albums__cover_photo')
       .prefetch_related('albums__cover_photo__photo_file_set')
       .prefetch_related('categorys')
       .prefetch_related('categorys__cover_photo')
       .prefetch_related('categorys__cover_photo__photo_file_set')
       .prefetch_related('photo_person_set')
       .prefetch_related('photo_person_set__person')
       .prefetch_related('photo_person_set__person__cover_photo')
       .prefetch_related(
           'photo_person_set__person__cover_photo__photo_file_set')
       .filter(MyQ())
       .filter(MyQ())
       .filter(
           MyQ(relations_1__photo_2=photos['Parent'])
           | MyQ(relations_2__photo_1=photos['Parent']))
       .distinct()
    )
    assert queryset.mock_calls == chained.call_list()
    assert result is expected_result
开发者ID:brianmay,项目名称:spud,代码行数:60,代码来源:test_search.py

示例8: setUp

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import is_staff [as 别名]
    def setUp(self):
        # Create mock request
        user_object = MagicMock()
        user_object.is_staff = True
        user_object.userprofile.actor_id = 2

        self.request = MagicMock()
        self.request.user = user_object

        # Mock user
        views.User = MagicMock()
        views.User.objects.get = MagicMock()
        views.User.objects.get.return_value = user_object

        # Mock Userprofile
        views.UserProfile = FakeProfile()
        views.Organization = FakeOrganization()
开发者ID:huygun,项目名称:wstore,代码行数:19,代码来源:tests.py

示例9: setUp

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import is_staff [as 别名]
    def setUp(self):
        # Create request user mock
        user_object = MagicMock()
        user_object.username = 'test_user'
        user_object.pk = '1111'
        user_object.is_staff = False
        self.request = MagicMock()
        self.request.user = user_object

        # Create organization mock
        self.org_object = MagicMock()
        self.org_object.name = 'test_org'
        self.org_object.managers = ['1111']
        self.org_object.payment_info = {
            'number': '4567456745674567'
        }
        views.Organization = MagicMock()
        views.Organization.objects.get.return_value = self.org_object
开发者ID:jartieda,项目名称:wstore,代码行数:20,代码来源:tests.py

示例10: test_search_all

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import is_staff [as 别名]
def test_search_all():
    user = MagicMock(spec=auth_models.User)
    user.is_staff = True
    queryset = MagicMock(spec=QuerySet)

    expected_result = MagicMock(spec=QuerySet)
    (queryset
        .select_related.return_value
        .prefetch_related.return_value) = expected_result

    params = {}
    result = models.place.objects.get_search_queryset(user, queryset, params)

    chained = (
       call
       .select_related('cover_photo')
       .prefetch_related('cover_photo__photo_file_set')
    )
    assert queryset.mock_calls == chained.call_list()
    assert result is expected_result
开发者ID:brianmay,项目名称:spud,代码行数:22,代码来源:test_search.py

示例11: setUp

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import is_staff [as 别名]
    def setUp(self):

        # Create mock request
        user_object = MagicMock()
        user_object.is_staff = False
        user_object.pk = '2222'
        user_object.userprofile.actor_id = 2
        user_object.username = 'test_user'

        self.request = MagicMock()
        self.request.META.get.return_value = 'application/json'
        self.request.user = user_object

        # Mock user
        views.User = MagicMock()
        views.User.objects.get = MagicMock()
        views.User.objects.get.return_value = user_object

        views.Organization = MagicMock()
        self.org = MagicMock()
        self.org.name = 'test_org'
        self.org.managers = []
        views.Organization.objects.get.return_value = self.org
开发者ID:tmforum,项目名称:tmffiware,代码行数:25,代码来源:tests.py


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