• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python mixer.cycle函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mixer.backend.django.mixer.cycle函数的典型用法代码示例。如果您正苦于以下问题:Python cycle函数的具体用法?Python cycle怎么用?Python cycle使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_paginator

    def test_paginator(self):
        from adrest.mixin import EmitterMixin
        from django.views.generic import View
        from django.test import RequestFactory
        from tests.core.models import Pirate
        from adrest.utils.paginator import Paginator

        mixer.cycle(3).blend('core.pirate')

        class SomeResource(EmitterMixin, View):

            class Meta:
                model = 'core.pirate'
                dyn_prefix = 'adr-'
                limit_per_page = 2

            def dispatch(self, request, **resources):
                p = Paginator(request, self, Pirate.objects.all())
                return self.emit(p, request=request)

        rf = RequestFactory()
        resource = SomeResource()

        response = resource.dispatch(rf.get('/'))
        self.assertContains(response, '"page": 1')
        self.assertContains(response, '"num_pages": 2')
开发者ID:EricSchles,项目名称:adrest,代码行数:26,代码来源:serializer.py


示例2: test_handler

    def test_handler(self):
        mixer.cycle(3).blend(Reimbursement, search_vector=None)
        command = Command()
        command.handle(batch_size=2, silent=True)

        queryset = Reimbursement.objects.exclude(search_vector=None)
        self.assertEqual(3, queryset.count())
开发者ID:datasciencebr,项目名称:serenata-de-amor,代码行数:7,代码来源:test_searchvector_command.py


示例3: setUp

 def setUp(self):
     #Create/log in a normal user.
     self.a_user = mixer.blend(User, username='adminuser', is_superuser=True, is_staff=True)
     self.a_user.set_password('pass')
     self.a_user.save()
     self.client.login(username='adminuser', password='pass')
     mixer.blend(ChangeRequest)
     mixer.cycle(2).blend(ChangeLog)
     self.rfc = ChangeRequest.objects.first()
开发者ID:parksandwildlife,项目名称:it-assets,代码行数:9,代码来源:test_views.py


示例4: test_get_filter_queryset_custom_filter

 def test_get_filter_queryset_custom_filter(self):
     mixer.cycle(3).blend("testapp.comment")
     response = self.client.get(
         '/api/comment?filter=is_outdated=1',
         content_type='application/vnd.api+json',
         HTTP_ACCEPT='application/vnd.api+json'
     )
     data = json.loads(response.content.decode("utf-8"))
     self.assertEqual(len(data['data']), 1)
开发者ID:cmac1000,项目名称:jsonapi,代码行数:9,代码来源:test_api.py


示例5: test_get_include_many_many_db_queries

 def test_get_include_many_many_db_queries(self):
     mixer.cycle(10).blend("testapp.comment")
     # prefetch related join is done in python twice.
     with self.assertNumQueries(3):
         self.client.get(
             '/api/author?include=posts,posts.comments',
             content_type='application/vnd.api+json',
             HTTP_ACCEPT='application/vnd.api+json'
         )
开发者ID:cmac1000,项目名称:jsonapi,代码行数:9,代码来源:test_api.py


示例6: test_get_sort

 def test_get_sort(self):
     mixer.cycle(2).blend("testapp.comment")
     response = self.client.get(
         '/api/comment?sort=-id',
         content_type='application/vnd.api+json',
         HTTP_ACCEPT='application/vnd.api+json'
     )
     data = json.loads(response.content.decode("utf-8"))
     self.assertEqual([o['id'] for o in data['data']], [2, 1])
开发者ID:cmac1000,项目名称:jsonapi,代码行数:9,代码来源:test_api.py


示例7: test_get_include_db_query

 def test_get_include_db_query(self):
     mixer.cycle(10).blend("testapp.comment")
     # prefetch related join is done in python twice.
     # TODO: add 'comments.author' relationship (->to-many->to-one).
     with self.assertNumQueries(3):
         self.client.get(
             '/api/post?include=author,comments,author.comments',
             content_type='application/vnd.api+json',
             HTTP_ACCEPT='application/vnd.api+json'
         )
开发者ID:cmac1000,项目名称:jsonapi,代码行数:10,代码来源:test_api.py


示例8: setUp

 def setUp(self):
     super(ReferralCreateChildTest, self).setUp()
     self.ref = Referral.objects.first()
     # Ensure that conditions with 'approved' text exist on the referral.
     mixer.cycle(3).blend(
         Condition, referral=self.ref, category=mixer.SELECT,
         condition=mixer.RANDOM, model_condition=mixer.SELECT,
         proposed_condition=mixer.RANDOM)
     for i in Condition.objects.filter(referral=self.ref):
         i.proposed_condition_html = '<p>Proposed condition</p>'
         i.condition_html = '<p>Actual condition</p>'
         i.save()
开发者ID:parksandwildlife,项目名称:prs,代码行数:12,代码来源:test_views.py


示例9: setUp

    def setUp(self):
        super(AssetsAdminTestCase, self).setUp()
        # Create/log in an admin user.
        self.admin_user = mixer.blend(User, username='admin', is_superuser=True, is_staff=True)
        self.admin_user.set_password('pass')
        self.admin_user.save()
        self.client.login(username='admin', password='pass')
        mixer.cycle(5).blend(
            HardwareAsset, purchased_value=randint(100, 1000), date_purchased=random_datetime)

        mixer.cycle(5).blend(
            SoftwareAsset, support_expiry=random_datetime)
开发者ID:parksandwildlife,项目名称:it-assets,代码行数:12,代码来源:test_admin.py


示例10: handle

    def handle(self, *args, **options):
        self.stdout.write('Deleting data.......' )
        BlogCategory.objects.all().delete()
        BlogTopic.objects.all().delete()
        BlogPost.objects.all().delete()

        self.stdout.write('Start loading.......' )
        categories = mixer.cycle(10).blend(BlogCategory)
        for c in categories:
            topics = mixer.cycle(10).blend(BlogTopic,category=c, title=u'Заголовок блога категории '+c.name)
            for t in topics:
                posts = mixer.cycle(10).blend(BlogPost,topic=t,content=mixer.fake, author='Fedot')
        self.stdout.write('Well done' )
开发者ID:zdimon,项目名称:blog,代码行数:13,代码来源:loading.py


示例11: test_manager_methods

 def test_manager_methods(self):
     """Test the inherited ReferralLookup manager methods.
     """
     mixer.cycle(2).blend(DopTrigger)  # Some extras.
     obj_del = mixer.blend(DopTrigger)  # One to delete.
     obj_del.delete()
     all_pks = [i.pk for i in DopTrigger.objects.all()]
     current_pks = [i.pk for i in DopTrigger.objects.current()]
     del_pks = [i.pk for i in DopTrigger.objects.deleted()]
     self.assertTrue(obj_del.pk in all_pks)
     self.assertFalse(obj_del.pk in current_pks)
     self.assertTrue(obj_del.pk in del_pks)
     self.assertFalse(self.obj.pk in del_pks)
开发者ID:parksandwildlife,项目名称:prs,代码行数:13,代码来源:test_models.py


示例12: setUp

 def setUp(self):
     # We need a defined Group, because of the user_post_save signal in
     # the tracking app.
     Group.objects.create(name='Edit Resource Tracking Device')
     # Create User object.
     self.user1 = User.objects.create_user(
         username='testuser', email='[email protected]')
     self.user1.set_password('pass')
     self.user1.save()
     # Log in user1 by default.
     self.client.login(username=self.user1.username, password='pass')
     # Create a WeatherStation object.
     self.ws = mixer.blend(WeatherStation)
     mixer.cycle(5).blend(WeatherObservation, station=self.ws)
开发者ID:ropable,项目名称:resource_tracking,代码行数:14,代码来源:test_views.py


示例13: test_select

    def test_select(self):
        from mixer.backend.django import mixer

        mixer.cycle(3).blend(Rabbit)
        hole = mixer.blend(Hole, rabbit=mixer.select)
        self.assertFalse(hole.rabbit)

        rabbits = Rabbit.objects.all()
        hole = mixer.blend(Hole, owner=mixer.select)
        self.assertTrue(hole.owner in rabbits)

        rabbit = rabbits[0]
        hole = mixer.blend(Hole, owner=mixer.select(email=rabbit.email))
        self.assertEqual(hole.owner, rabbit)
开发者ID:checko,项目名称:mixer,代码行数:14,代码来源:test_django.py


示例14: test_get_include_many_to_many

    def test_get_include_many_to_many(self):
        group = mixer.blend('testapp.group')
        authors = mixer.cycle(2).blend('testapp.author')
        memberships = mixer.cycle(2).blend('testapp.membership', group=group,
                                           author=(a for a in authors))

        # prefetch related join is done in python
        with self.assertNumQueries(2):
            response = self.client.get(
                '/api/author?include=memberships',
                content_type='application/vnd.api+json',
                HTTP_ACCEPT='application/vnd.api+json'
            )

        data = json.loads(response.content.decode("utf-8"))
        expected_data = {
            "data": [{
                "id": author.id,
                "name": author.name,
                "links": {
                    "memberships": author.membership_set.values_list(
                        "id", flat=True)
                }
            } for author in authors],
            "links": {
            },
            "linked": [{
                "type": "memberships",
                "id": membership.id,
                "links": {
                    "group": membership.group_id,
                    "author": membership.author_id,
                }
            } for membership in memberships]
        }
        compare(data, expected_data)

        response = self.client.get(
            '/api/author?include=memberships,memberships.group',
            content_type='application/vnd.api+json',
            HTTP_ACCEPT='application/vnd.api+json'
        )
        data = json.loads(response.content.decode("utf-8"))
        expected_data["linked"].append({
            "type": "group",
            "id": group.id,
            "name": group.name,
        })
        compare(data, expected_data)
开发者ID:gitter-badger,项目名称:jsonapi,代码行数:49,代码来源:test_api.py


示例15: setUp

 def setUp(self):
     """Generate from FreshdeskTicket objects.
     """
     super(FreshdeskTicketResourceTestCase, self).setUp()
     mixer.cycle(5).blend(
         FreshdeskContact, email=random_dpaw_email)
     mixer.cycle(5).blend(
         FreshdeskTicket,
         subject=mixer.RANDOM, description_text=mixer.RANDOM, type='Test',
         freshdesk_requester=mixer.SELECT,
         it_system=mixer.SELECT,
         custom_fields={
             'support_category': None, 'support_subcategory': None},
     )
     self.ticket = FreshdeskTicket.objects.first()
开发者ID:ropable,项目名称:oim-cms,代码行数:15,代码来源:test_api.py


示例16: test_get_include

 def test_get_include(self):
     author = mixer.blend("testapp.author")
     mixer.cycle(2).blend("testapp.post", author=author)
     response = self.client.get(
         '/api/post?include=author',
         content_type='application/vnd.api+json',
         HTTP_ACCEPT='application/vnd.api+json'
     )
     data = json.loads(response.content.decode("utf-8"))["linked"]
     expected_data = [{
         "type": "author",
         "id": author.id,
         "name": author.name
     }]
     self.assertEqual(data, expected_data)
开发者ID:gitter-badger,项目名称:jsonapi,代码行数:15,代码来源:test_api.py


示例17: test_update_models

    def test_update_models(self):
        authors = mixer.cycle(2).blend("testapp.author", name="")
        response = self.client.put(
            '/api/author/{}'.format(",".join([str(a.id) for a in authors])),
            json.dumps({
                "data": [{
                    "id": a.id,
                    "name": "author",
                } for a in authors],
            }),
            content_type='application/vnd.api+json',
            HTTP_ACCEPT='application/vnd.api+json'
        )
        self.assertEqual(response.status_code, 200)
        self.assertEqual(Author.objects.count(), 2)
        for author in Author.objects.all():
            self.assertEqual(author.name, "author")

        expected_data = {
            "data": [{
                "id": a.id,
                "name": "author",
            } for a in authors],
        }
        data = json.loads(response.content.decode("utf-8"))
        self.assertEqual(data, expected_data)
开发者ID:gitter-badger,项目名称:jsonapi,代码行数:26,代码来源:test_api.py


示例18: test_pagination

    def test_pagination(self):

        pirates = mixer.cycle(3).blend('core.pirate')

        class SomeResource(DynamicMixin, View):

            class Meta:
                model = 'core.pirate'
                limit_per_page = 2

            def dispatch(self, request, **resources):
                collection = self.get_collection(request, **resources)
                return self.paginate(request, collection)

        rf = RequestFactory()
        resource = SomeResource()

        response = resource.dispatch(rf.get('/'))
        self.assertEqual(len(response.resources), 2)

        resource._meta.limit_per_page = 0
        response = resource.dispatch(rf.get('/'))
        self.assertEqual(len(response), len(pirates))

        response = resource.dispatch(rf.get('/?adr-max=1'))
        self.assertEqual(len(response.resources), 1)
开发者ID:9seconds,项目名称:adrest,代码行数:26,代码来源:dynamic.py


示例19: test_base

    def test_base(self):

        pirates = mixer.cycle(3).blend('core.pirate')

        class SomeResource(DynamicMixin, View):

            class Meta:
                model = 'core.pirate'

            def dispatch(self, request, **resources):
                return self.get_collection(request, **resources)

        rf = RequestFactory()
        resource = SomeResource()

        response = resource.dispatch(rf.get('/'))
        self.assertEqual(len(response), len(pirates))

        response = resource.dispatch(rf.get('/?name=' + pirates[0].name))
        self.assertEqual(list(response), [pirates[0]])

        response = resource.dispatch(
            rf.get('/?adr-sort=name&adr-sort=captain'))
        self.assertEqual(list(response), sorted(
            pirates, key=lambda p: (p.name, p.captain)))
开发者ID:9seconds,项目名称:adrest,代码行数:25,代码来源:dynamic.py


示例20: test_update_models_save_error_atomic

    def test_update_models_save_error_atomic(self):
        """ Ensure models are not created if one of them raises exception."""
        authors = mixer.cycle(2).blend('testapp.author', name="name")
        response = self.client.put(
            '/api/author/{}'.format(",".join([str(a.id) for a in authors])),
            json.dumps({
                "data": [{
                    "id": authors[0].id,
                    "name": "allowed name",
                }, {
                    "id": authors[1].id,
                    "name": "forbidden name",
                }],
            }),
            content_type='application/vnd.api+json',
            HTTP_ACCEPT='application/vnd.api+json'
        )

        self.assertEqual(response.status_code, 400)

        expected_data = {
            "errors": [{
                "status": 400,
                "code": 32102,
                "title": "Model form save error",
                "detail": "Name forbidden name is not allowed",
            }]
        }

        data = json.loads(response.content.decode("utf-8"))
        self.assertEqual(data, expected_data)
        self.assertEqual(Author.objects.count(), 2)
        self.assertEqual(
            set(Author.objects.values_list("name", flat=True)), {'name'})
开发者ID:gitter-badger,项目名称:jsonapi,代码行数:34,代码来源:test_api.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python mixer.blend函数代码示例发布时间:2022-05-27
下一篇:
Python mixer.blend函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap