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

Python mixer.blend函数代码示例

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

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



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

示例1: test_add_grados_profesor

    def test_add_grados_profesor(self):
        """
        Comprueba la vista add_grados_profesor

        Comprueba que si no se le pasan datos muestra el formulario.
        Comprueba que se muestra al añadir un profesor.
        Comprueba que si no se le pasan los datos correctamente no te dirige a añadir los grados.
        """
        profesor = User.objects.get(username="profesor")
        mixer.blend(Grado, profesores=profesor, id=10)
        self.client = Client()
        self.client.login(username="admin", password="admin")
        session = self.client.session
        session['profesor'] = profesor.id
        session.save()
        response = self.client.post("/miPanel/addGradosProfesor/", {})
        boolean = True if not response.context['grados'] else False
        self.assertEquals(boolean, False)

        response = self.client.post("/miPanel/addGradosProfesor/", {'choices': 'error'})
        boolean = True if not response.context['grados'] else False
        self.assertEquals(boolean, False)

        response = self.client.post("/miPanel/addGradosProfesor/", {'choices': '10'})
        boolean = True if not response.context else False
        self.assertEquals(boolean, True)
开发者ID:4Fantasticos,项目名称:gestorTutorias,代码行数:26,代码来源:tests.py


示例2: test_with_invalid_product_id

    def test_with_invalid_product_id(self):
        """test the behavior of the import function if a product was not found in the database"""
        global CURRENT_PRODUCT_MIGRATION_TEST_DATA
        CURRENT_PRODUCT_MIGRATION_TEST_DATA = pd.DataFrame(
            [
                [
                    "Product that is not in the Database",
                    "Existing Migration Source",
                    "Replacement Product ID",
                    "comment of the migration",
                    "Invalid URL"
                ]
            ], columns=PRODUCT_MIGRATION_TEST_DATA_COLUMNS
        )
        mixer.blend("productdb.Product", product_id="Product A", vendor=Vendor.objects.get(id=1))
        mixer.blend("productdb.ProductMigrationSource", name="Existing Migration Source")

        product_migrations_file = ProductMigrationsExcelImporter("virtual_file.xlsx")
        assert product_migrations_file.is_valid_file() is False

        product_migrations_file.verify_file()
        assert product_migrations_file.is_valid_file() is True

        product_migrations_file.import_to_database()
        assert ProductMigrationOption.objects.count() == 0
        assert "Product Product that is not in the Database not found in database, skip " \
               "entry" in product_migrations_file.import_result_messages

        Product.objects.all().delete()
        ProductMigrationOption.objects.all().delete()
        ProductMigrationSource.objects.all().delete()
开发者ID:hoelsner,项目名称:product-database,代码行数:31,代码来源:test_productdb_excel_import.py


示例3: test_security

 def test_security(self):
     user = mixer.blend('auth.User', first_name='Martin')
     post = mixer.blend('birdie.Post')
     req = RequestFactory().post('/', data={})
     req.user = user
     with pytest.raises(Http404):
         views.PostUpdateView.as_view()(req, pk=post.pk)
开发者ID:macndesign,项目名称:tested,代码行数:7,代码来源:test_views.py


示例4: test_form

    def test_form(self):
        data = {'text': 'Foo'}
        form = forms.MessageForm(user=self.user, conversation=None, data=data,
                                 initial_user=self.other_user)
        self.assertFalse(form.errors)
        self.assertTrue(form.is_valid())
        conversation = form.save()
        self.assertEqual(Conversation.objects.count(), 1, msg=(
            'A new conversation should\'ve been started with the message.'))
        form = forms.MessageForm(user=self.user, data=data, initial_user=None,
                                 conversation=conversation)

        form.save()
        self.assertEqual(Conversation.objects.count(), 1, msg=(
            'The existing conversation should\'ve been re-used.'))

        blocked_user = mixer.blend('conversation.BlockedUser',
                                   blocked_by=self.user, user=self.other_user)
        form = forms.MessageForm(user=self.user, data=data, initial_user=None,
                                 conversation=conversation)
        self.assertTrue(form.errors, msg=(
            'Conversation should have been blocked'))

        blocked_user.delete()
        mixer.blend('conversation.BlockedUser',
                    user=self.user, blocked_by=self.other_user)
        form = forms.MessageForm(user=self.user, data=data, initial_user=None,
                                 conversation=conversation)
        self.assertTrue(form.errors, msg=(
            'Conversation should have been blocked'))
开发者ID:bitmazk,项目名称:django-conversation,代码行数:30,代码来源:forms_tests.py


示例5: test_import_with_missing_product_value

    def test_import_with_missing_product_value(self):
        """test import with missing product (ignore it)"""
        global CURRENT_PRODUCT_MIGRATION_TEST_DATA
        CURRENT_PRODUCT_MIGRATION_TEST_DATA = pd.DataFrame(
            [
                [
                    None,
                    "Existing Migration Source",
                    "Replacement Product ID",
                    "comment of the migration",
                    "Invalid URL"
                ]
            ], columns=PRODUCT_MIGRATION_TEST_DATA_COLUMNS
        )
        mixer.blend("productdb.Product", product_id="Product A", vendor=Vendor.objects.get(id=1))
        mixer.blend("productdb.ProductMigrationSource", name="Existing Migration Source")

        product_migrations_file = ProductMigrationsExcelImporter("no file.xlsx")
        assert product_migrations_file.is_valid_file() is False

        product_migrations_file.verify_file()
        assert product_migrations_file.is_valid_file() is True

        product_migrations_file.import_to_database()
        assert ProductMigrationOption.objects.count() == 0
        assert len(product_migrations_file.import_result_messages) == 0

        Product.objects.all().delete()
        ProductMigrationOption.objects.all().delete()
        ProductMigrationSource.objects.all().delete()
开发者ID:hoelsner,项目名称:product-database,代码行数:30,代码来源:test_productdb_excel_import.py


示例6: test_invalid_scheme

 def test_invalid_scheme():
     from mixer.backend.django import mixer
     try:
         mixer.blend('django_app.Unknown')
     except ValueError:
         return False
     raise Exception('test.failed')
开发者ID:checko,项目名称:mixer,代码行数:7,代码来源:test_django.py


示例7: test_form

 def test_form(self):
     account = mixer.blend('account_keeping.Account')
     data = {
         'transaction_type': 'd',
         'transaction_date': now().strftime('%Y-%m-%d'),
         'account': account.pk,
         'payee': mixer.blend('account_keeping.Payee').pk,
         'category': mixer.blend('account_keeping.Category').pk,
         'currency': mixer.blend('currency_history.Currency').pk,
         'amount_net': 0,
         'amount_gross': 0,
         'vat': 0,
         'value_net': 0,
         'value_gross': 0,
         'mark_invoice': True,
     }
     form = forms.TransactionForm(data=data, branch=account.branch)
     self.assertFalse(form.errors)
     transaction = form.save()
     transaction.invoice = mixer.blend('account_keeping.Invoice',
                                       payment_date=None)
     transaction.invoice.save()
     self.assertFalse(transaction.invoice.payment_date)
     data.update({'invoice': transaction.invoice.pk})
     form = forms.TransactionForm(data=data, branch=account.branch)
     self.assertFalse(form.errors)
     transaction = form.save()
     self.assertTrue(transaction.invoice.payment_date)
开发者ID:bitmazk,项目名称:django-account-keeping,代码行数:28,代码来源:forms_tests.py


示例8: test_form_suppress_notification_only_for_superusers

    def test_form_suppress_notification_only_for_superusers(self):
        # anonymous users are not allowed to add a notification
        files = {"excel_file": SimpleUploadedFile("myfile.xlsx", b"yxz")}
        data = {"suppress_notification": False}
        form = ImportProductsFileUploadForm(user=AnonymousUser(), data=data, files=files)

        assert form.is_valid() is True
        assert form.fields["suppress_notification"].disabled is True
        assert form.cleaned_data["suppress_notification"] is True

        # authenticated users are not allowed to add a notification
        authuser = mixer.blend("auth.User")
        files = {"excel_file": SimpleUploadedFile("myfile.xlsx", b"yxz")}
        data = {"suppress_notification": False}
        form = ImportProductsFileUploadForm(user=authuser, data=data, files=files)

        assert form.is_valid() is True
        assert form.fields["suppress_notification"].disabled is True
        assert form.cleaned_data["suppress_notification"] is True

        # superusers are allowed to change the parameter
        superuser = mixer.blend("auth.User", is_superuser=True)
        files = {"excel_file": SimpleUploadedFile("myfile.xlsx", b"yxz")}
        data = {"suppress_notification": False}
        form = ImportProductsFileUploadForm(user=superuser, data=data, files=files)

        assert form.is_valid() is True
        assert form.fields["suppress_notification"].disabled is False
        assert form.cleaned_data["suppress_notification"] is False
开发者ID:hoelsner,项目名称:product-database,代码行数:29,代码来源:test_productdb_forms.py


示例9: test_relate_existing_object_to_task

 def test_relate_existing_object_to_task(self):
     """Test POST to relate existing note/record to a task
     """
     # First, ensure that a task, record and note all exist.
     task = mixer.blend(Task, referral=self.ref)
     note = mixer.blend(Note, referral=self.ref)
     record = mixer.blend(Record, referral=self.ref)
     init_records = task.records.count()
     init_notes = task.notes.count()
     url = reverse('referral_create_child_related', kwargs={
         'pk': self.ref.pk,
         'model': 'task',
         'id': task.pk,
         'type': 'addrecord'})
     resp = self.client.post(url, {'records': [record.pk]})
     self.assertEqual(resp.status_code, 302)
     self.assertTrue(task.records.count() > init_records)
     url = reverse('referral_create_child_related', kwargs={
         'pk': self.ref.pk,
         'model': 'task',
         'id': task.pk,
         'type': 'addnote'})
     resp = self.client.post(url, {'notes': [note.pk]})
     self.assertEqual(resp.status_code, 302)
     self.assertTrue(task.notes.count() > init_notes)
开发者ID:parksandwildlife,项目名称:prs,代码行数:25,代码来源:test_views.py


示例10: test_tag

 def test_tag(self):
     self.assertFalse(conversation_tags.is_blocked('foo', 'bar'))
     user1 = mixer.blend('auth.User')
     user2 = mixer.blend('auth.User')
     self.assertFalse(conversation_tags.is_blocked(user1, user2))
     mixer.blend('conversation.BlockedUser', blocked_by=user1, user=user2)
     self.assertTrue(conversation_tags.is_blocked(user1, user2))
开发者ID:bitmazk,项目名称:django-conversation,代码行数:7,代码来源:tags_tests.py


示例11: setUp

 def setUp(self):
     self.user = mixer.blend('auth.User')
     self.doc = mixer.blend('document_library.Document')
     self.doc_en = self.doc.translate('en')
     self.doc_en.save()
     self.doc_de = self.doc.translate('de')
     self.doc_de.save()
开发者ID:bitmazk,项目名称:django-document-library,代码行数:7,代码来源:document_library_tags_tests.py


示例12: test_get_average_rating_with_custom_choices

    def test_get_average_rating_with_custom_choices(self):
        self.assertFalse(self.review.get_average_rating(), msg=(
            'If there are no ratings, it should return False.'))
        rating1 = mixer.blend('review.Rating', review=self.review, value='4')
        # we create choices to simulate, that the previous value was the max
        for i in range(0, 5):
            mixer.blend('review.RatingCategoryChoiceTranslation',
                        language_code='en-us',
                        ratingcategory=rating1.category, value=i)
        rating2 = mixer.blend('review.Rating', review=self.review, value='6')
        # we create choices to simulate, that the previous value was the max
        for i in range(0, 7):
            mixer.blend('review.RatingCategoryChoiceTranslation',
                        language_code='en-us',
                        ratingcategory=rating2.category, value=i)
        mixer.blend('review.Rating', category=rating2.category,
                    review=self.review, value='6')
        mixer.blend('review.Rating', category=rating2.category,
                    review=self.review, value=None)
        # testing the absolute max voting
        self.assertEqual(self.review.get_average_rating(6), 6, msg=(
            'Should return the average rating value.'))
        self.assertEqual(self.review.get_average_rating(4), 4, msg=(
            'Should return the average rating value.'))
        self.assertEqual(self.review.get_average_rating(100), 100, msg=(
            'Should return the average rating value.'))

        # testing the category averages
        """
开发者ID:WirelessElephant,项目名称:django-review,代码行数:29,代码来源:models_tests.py


示例13: setUp

 def setUp(self):
     self.extra_info = mixer.blend(
         'review.ReviewExtraInfo',
         review=mixer.blend('review.Review',
                            content_type=ContentType.objects.get_for_model(
                                WeatherCondition)),
         content_type=ContentType.objects.get_for_model(WeatherCondition))
开发者ID:WirelessElephant,项目名称:django-review,代码行数:7,代码来源:models_tests.py


示例14: test_product_migration_source_names_set

    def test_product_migration_source_names_set(self):
        site = AdminSite()
        product_admin = admin.ProductAdmin(models.Product, site)
        obj = mixer.blend(
            "productdb.Product",
            name="Product",
            eox_update_time_stamp=None
        )

        result = product_admin.product_migration_source_names(obj)
        expected = ""
        assert result == expected

        mixer.blend(
            "productdb.ProductMigrationOption",
            product=obj,
            migration_source=ProductMigrationSource.objects.create(name="test"),
            replacement_product_id="MyProductId"
        )

        result = product_admin.product_migration_source_names(obj)
        expected = "test"
        assert result == expected
        mixer.blend(
            "productdb.ProductMigrationOption",
            product=obj,
            migration_source=ProductMigrationSource.objects.create(name="test2"),
            replacement_product_id="MyProductId"
        )

        result = product_admin.product_migration_source_names(obj)
        expected = "test\ntest2"
        assert result == expected
开发者ID:hoelsner,项目名称:product-database,代码行数:33,代码来源:test_productdb_admin.py


示例15: test_form

    def test_form(self):
        form = ProductListForm(data={})
        assert form.is_valid() is False
        assert "name" in form.errors
        assert "description" not in form.errors, "Null/Blank values are allowed"
        assert "string_product_list" in form.errors

        data = {
            "name": "Test Product List",
            "description": "",
            "string_product_list": ""
        }
        form = ProductListForm(data=data)
        assert form.is_valid() is False
        assert "name" not in form.errors, "Should be allowed (can be any string)"
        assert "description" not in form.errors, "Null/Blank values are allowed"
        assert "string_product_list" in form.errors, "At least one Product is required"

        data = {
            "name": "Test Product List",
            "description": "",
            "string_product_list": "Product"
        }
        mixer.blend("productdb.Product", product_id="Product")
        form = ProductListForm(data=data)
        assert form.is_valid() is True, form.errors
开发者ID:hoelsner,项目名称:product-database,代码行数:26,代码来源:test_productdb_forms.py


示例16: test_generic

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

        hole = mixer.blend(Hole)
        rabbit = mixer.blend(Rabbit, content_object=hole)
        self.assertEqual(rabbit.object_id, hole.pk)
        self.assertEqual(rabbit.content_type.model_class(), Hole)
开发者ID:f4bsch,项目名称:mixer,代码行数:7,代码来源:test_django.py


示例17: test_custom

def test_custom(mixer):
    mixer.register(Rabbit, title=lambda: 'Mr. Rabbit')

    rabbit = mixer.blend(Rabbit)
    assert rabbit.title == 'Mr. Rabbit'

    from mixer.backend.django import GenFactory

    def getter(*args, **kwargs):
        return "Always same"

    class MyFactory(GenFactory):
        generators = {models.CharField: getter}

    fabric = MyFactory.gen_maker(models.CharField)
    assert next(fabric()) == "Always same"

    mixer = Mixer(factory=MyFactory, fake=False)
    assert mixer._Mixer__factory == MyFactory

    test = mixer.blend(Rabbit)
    assert test.title == "Always same"

    @mixer.middleware('auth.user')
    def encrypt_password(user): # noqa
        user.set_password(user.password)
        return user

    user = mixer.blend('auth.User', password='test')
    assert user.check_password('test')

    user = user.__class__.objects.get(pk=user.pk)
    assert user.check_password('test')
开发者ID:timka,项目名称:mixer,代码行数:33,代码来源:test_django.py


示例18: node

def node(data, parent=None):
    new_node = None
    # Create topics
    if data['kind_id'] == "topic":
        new_node = cc.ContentNode(kind=topic(), parent=parent, title=data['title'], node_id=data['node_id'])
        new_node.save()

        for child in data['children']:
            node(child, parent=new_node)

    # Create videos
    elif data['kind_id'] == "video":
        new_node = cc.ContentNode(kind=video(), parent=parent, title=data['title'], node_id=data['node_id'], license=license_wtfpl())
        new_node.save()
        video_file = fileobj_video(contents="Video File")
        video_file.contentnode = new_node
        video_file.preset_id = format_presets.VIDEO_HIGH_RES
        video_file.save()

    # Create exercises
    elif data['kind_id'] == "exercise":
        extra_fields = "{{\"mastery_model\":\"{}\",\"randomize\":true,\"m\":{},\"n\":{}}}".format(data['mastery_model'], data.get('m') or 0, data.get('n') or 0)
        new_node = cc.ContentNode(kind=exercise(), parent=parent, title=data['title'], node_id=data[
                                  'node_id'], license=license_wtfpl(), extra_fields=extra_fields)
        new_node.save()
        for assessment_item in data['assessment_items']:
            mixer.blend(cc.AssessmentItem,
                        contentnode=new_node,
                        assessment_id=assessment_item['assessment_id'],
                        question=assessment_item['question'],
                        type=assessment_item['type'],
                        answers=json.dumps(assessment_item['answers'])
                        )

    return new_node
开发者ID:fle-internal,项目名称:content-curation,代码行数:35,代码来源:testdata.py


示例19: setUp

 def setUp(self):
     self.user = mixer.blend('auth.User')
     self.other_user = mixer.blend('auth.User')
     self.review = mixer.blend(
         'review.Review', user=self.user,
         object_id=mixer.blend('test_app.WeatherCondition').pk,
         content_type=ContentType.objects.get_for_model(WeatherCondition))
开发者ID:WirelessElephant,项目名称:django-review,代码行数:7,代码来源:views_tests.py


示例20: test_is_not_subscribed

 def test_is_not_subscribed(self):
     sub1 = mixer.blend('subscribe.Subscription',
                        content_object=mixer.blend('test_app.DummyModel'))
     sub2 = mixer.blend('subscribe.Subscription',
                        content_object=mixer.blend('test_app.DummyModel'))
     result = is_subscribed(sub1.user, sub2.content_object)
     self.assertFalse(result)
开发者ID:bitmazk,项目名称:django-subscribe,代码行数:7,代码来源:subscribe_tags_tests.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python mixer.cycle函数代码示例发布时间:2022-05-27
下一篇:
Python utils.camelize函数代码示例发布时间: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