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

Python mommy.prepare函数代码示例

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

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



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

示例1: setUp

 def setUp(self):
     User = get_user_model()
     self.student = mommy.prepare(User, is_active=True)
     self.student.set_password('123')
     self.student.save()
     self.leader = mommy.prepare(User, is_active=True)
     self.leader.set_password('123')
     self.leader.save()
     self.superuser = mommy.prepare(
         User, is_active=True, is_superuser=True, is_staff=True
     )
     self.superuser.set_password('123')
     self.superuser.save()
     self.project1 = mommy.make(Project, leader=self.leader)
     self.project2 = mommy.make(Project)
     self.announcements_project1 = mommy.make(
         Announcement, project=self.project1, fixed=False, _quantity=5
     )
     self.announcements_project2 = mommy.make(
         Announcement, project=self.project2, fixed=False, _quantity=10
     )
     self.enrollment = mommy.make(
         Enrollment, project=self.project1, user=self.student,
         blocked=True
     )
     self.client = Client()
开发者ID:gileno,项目名称:sofia,代码行数:26,代码来源:test_views.py


示例2: test_has_module_perms

    def test_has_module_perms(self):
        """Staff members have all Django admin perms"""
        user = prepare(User, is_staff=False)
        self.assertFalse(user.has_module_perms("foo"), user)

        user = prepare(User, is_staff=True)
        self.assertTrue(user.has_module_perms("foo"), user)
开发者ID:mdj2,项目名称:project_template,代码行数:7,代码来源:tests.py


示例3: test_prepare_should_create_objects_respecting_quantity_parameter

    def test_prepare_should_create_objects_respecting_quantity_parameter(self):
        people = mommy.prepare(Person, _quantity=5)
        self.assertEqual(len(people), 5)
        self.assertTrue(all(not p.id for p in people))

        people = mommy.prepare(Person, _quantity=5, name="George Washington")
        self.assertTrue(all(p.name == "George Washington" for p in people))
开发者ID:helber,项目名称:model_mommy,代码行数:7,代码来源:test_mommy.py


示例4: test_wipes_old_email

    def test_wipes_old_email(self):
        """Test that old emails are wiped"""
        latest_email_open = mommy.prepare(EmailOpen)
        latest_email_open.user_agent = ''
        latest_email_open.save()

        old_email_open = mommy.prepare(EmailOpen)
        old_email_open.user_agent = ''
        old_email_open.opened_at = self.month_ago
        old_email_open.save()

        # As the database will always update with the last modified at time we
        # need to do an `UPDATE` operation in the database to change the time
        # the open was created.
        EmailOpen.objects.filter(
            pk=old_email_open.pk).update(opened_at=self.month_ago)

        all_email_opens_pre = EmailOpen.objects.all()

        self.assertIn(latest_email_open, all_email_opens_pre)
        self.assertIn(old_email_open, all_email_opens_pre)

        tasks.wipe_old_email_opens()

        all_email_opens_post = EmailOpen.objects.all()
        self.assertIn(latest_email_open, all_email_opens_post)
        self.assertNotIn(old_email_open, all_email_opens_post)
开发者ID:lpatmo,项目名称:actionify_the_news,代码行数:27,代码来源:test_tasks.py


示例5: test

    def test(self):
        class Car(models.Model):
            name = models.CharField(max_length=255)

        class CarIndex(Index):
            class Meta:
                fields = ['name']
                model = Car


        CarIndex.objects.put_mapping()
        # I don't understand why this is the *only* test that will randomly
        # blow up, unless you give ES a little time to do its thing
        time.sleep(.1)

        with suspended_updates():
            car = prepare(Car, pk=1)
            car2 = prepare(Car, pk=2)
            car3 = prepare(Car, pk=3)
            CarIndex.objects.update([car])
            CarIndex.objects.update(car2)
            CarIndex.objects.update(car3)
            # bulk saving shouldn't happen yet
            self.assertEqual([], CarIndex.objects.query("match", name=car.name).execute().hits)
            # suspended_updates should handle deletes too
            CarIndex.objects.delete(car3)

        # now saving to ES should have happen
        self.assertEqual(1, len(CarIndex.objects.query("match", name=car.name).execute().hits))
        self.assertEqual(1, len(CarIndex.objects.query("match", name=car2.name).execute().hits))
        # the third car was deleted
        self.assertEqual(0, len(CarIndex.objects.query("match", name=car3.name).execute().hits))
开发者ID:PSU-OIT-ARC,项目名称:elasticmodels,代码行数:32,代码来源:tests.py


示例6: test_str

 def test_str(self):
     user = prepare(User, first_name="foo", last_name="bar")
     self.assertEqual(str(user), "bar, foo")
     # the str method should fall back on the email address if a part of
     # their name is blank
     user = prepare(User, first_name="", last_name="bar")
     self.assertEqual(str(user), user.email)
开发者ID:mdj2,项目名称:project_template,代码行数:7,代码来源:tests.py


示例7: __create_distinct_comments

    def __create_distinct_comments(self, label):
        assignment = mommy.make_recipe('devilry.apps.core.assignment_activeperiod_start')
        group = mommy.make('core.AssignmentGroup', parentnode=assignment)
        feedbackset = mommy.make('devilry_group.FeedbackSet', group=group)

        examiner = mommy.make('core.Examiner',
                              assignmentgroup=group,
                              relatedexaminer__user=mommy.make(settings.AUTH_USER_MODEL))

        count = 100
        comments = []
        for x in range(count):
            comments.append(mommy.prepare(GroupComment, user=examiner.relatedexaminer.user, feedback_set=feedbackset,
                                          user_role=GroupComment.USER_ROLE_ADMIN))
            comments.append(mommy.prepare(GroupComment, user=examiner.relatedexaminer.user, feedback_set=feedbackset,
                                          user_role=GroupComment.USER_ROLE_STUDENT))
            comments.append(mommy.prepare(GroupComment, user=examiner.relatedexaminer.user, feedback_set=feedbackset,
                                          user_role=GroupComment.USER_ROLE_EXAMINER))

        with TimeExecution('{} ({})'.format(label, count)):
            for c in comments:
                c.save()

                # for c in comments:
                #    c.delete()
                #
        return group
开发者ID:devilry,项目名称:devilry-django,代码行数:27,代码来源:test_benchmarks.py


示例8: test_allow_create_fkey_related_model

    def test_allow_create_fkey_related_model(self):
        try:
            person = mommy.make(Person, dog_set=[mommy.prepare(Dog), mommy.prepare(Dog)])
        except TypeError:
            self.fail('type error raised')

        self.assertEqual(person.dog_set.count(), 2)
开发者ID:aioTV,项目名称:model_mommy,代码行数:7,代码来源:test_mommy.py


示例9: test_financial_aid_in_range_0_to_100

 def test_financial_aid_in_range_0_to_100(self):
     trips_year = self.init_trips_year()
     with self.assertRaises(ValidationError):
         mommy.make(IncomingStudent, trips_year=trips_year, financial_aid=-1).full_clean()
     with self.assertRaises(ValidationError):
         mommy.prepare(IncomingStudent, trips_year=trips_year, financial_aid=101).full_clean()
     mommy.prepare(IncomingStudent, trips_year=trips_year, financial_aid=100).full_clean()
开发者ID:rlmv,项目名称:doc-trips,代码行数:7,代码来源:tests.py


示例10: test_can_cloak_as

    def test_can_cloak_as(self):
        """Only staffers can cloak"""
        user = prepare(User, is_staff=False)
        self.assertFalse(user.has_module_perms("foo"), user)

        user = prepare(User, is_staff=True)
        self.assertTrue(user.has_module_perms("foo"), user)
开发者ID:mdj2,项目名称:project_template,代码行数:7,代码来源:tests.py


示例11: test_checks_if_token_has_expired

 def test_checks_if_token_has_expired(self):
     #  expired token
     yesterday = datetime.now() - timedelta(days=1)
     sso_user_token = mommy.prepare(SSOUserToken, expiration_datetime=yesterday)
     self.assertTrue(sso_user_token.has_expired)
     #  valid token
     tomorrow = datetime.now() + timedelta(days=1)
     sso_user_token = mommy.prepare(SSOUserToken, expiration_datetime=tomorrow)
     self.assertFalse(sso_user_token.has_expired)
开发者ID:innvent,项目名称:innvent-sso-python-client,代码行数:9,代码来源:test_models.py


示例12: test_clean_grading_points_is_none

 def test_clean_grading_points_is_none(self):
     testuser = mommy.prepare(settings.AUTH_USER_MODEL)
     testfeedbackset = mommy.prepare('devilry_group.FeedbackSet',
                                     grading_published_datetime=timezone.now(),
                                     grading_published_by=testuser,
                                     grading_points=None)
     with self.assertRaisesMessage(ValidationError,
                                   'A FeedbackSet can not be published without providing "points".'):
         testfeedbackset.clean()
开发者ID:devilry,项目名称:devilry-django,代码行数:9,代码来源:test_feedback_set.py


示例13: test_password_field_only_when_user_being_created

    def test_password_field_only_when_user_being_created(self):
        """
        The password field should only be on the form if the user is being
        created (not edited)
        """
        form = UserForm(user=prepare(User))
        self.assertIn("password", form.fields)

        form = UserForm(instance=make(User), user=prepare(User))
        self.assertNotIn("password", form.fields)
开发者ID:mdj2,项目名称:project_template,代码行数:10,代码来源:tests.py


示例14: test_category_list_content

def test_category_list_content(mocker):
    """Test the dictionary with the months and years."""
    category_mock = mocker.patch('djangopress.blog.models.Category.objects')
    uncategorized = mommy.prepare(Category, name='Uncategorized')
    uncategorized.pk = 1
    categories = mommy.prepare(Category, _quantity=3)
    categories.insert(0, uncategorized)
    category_mock.all.return_value = categories
    dictionary = {}
    dictionary['categories'] = categories
    assert category_list() == dictionary
开发者ID:gilmrjc,项目名称:djangopress,代码行数:11,代码来源:test_templatetags.py


示例15: test_bus_assignment_is_either_one_way_or_round_trip

 def test_bus_assignment_is_either_one_way_or_round_trip(self):
     msg = "Cannot have round-trip AND one-way bus assignments"
     with self.assertRaisesRegexp(ValidationError, msg):
         mommy.prepare(
             IncomingStudent, bus_assignment_round_trip=mommy.make(Stop), bus_assignment_to_hanover=mommy.make(Stop)
         ).full_clean()
     with self.assertRaisesRegexp(ValidationError, msg):
         mommy.prepare(
             IncomingStudent,
             bus_assignment_round_trip=mommy.make(Stop),
             bus_assignment_from_hanover=mommy.make(Stop),
         ).full_clean()
开发者ID:rlmv,项目名称:doc-trips,代码行数:12,代码来源:tests.py


示例16: test_tag

    def test_tag(self):
        # dog = Recipe(Dog)
        # tag_recipe = Recipe(
        #     Tag,
        #     content_object=foreign_key(dog))

        # tag = tag_recipe.prepare()
        dog = mommy.prepare(Dog)
        tag = mommy.prepare(Tag)
        tag.content_object = dog
        self.assertIsNotNone(tag.content_object)
        print "Mommy - test_tag: Dog Count", Dog.objects.all()
        print "Mommy - test_tag: Person Count", Person.objects.all()
开发者ID:cameronmaske,项目名称:pytest-django,代码行数:13,代码来源:test_model_mommy.py


示例17: test_default_pagination_value

def test_default_pagination_value(rf, mocker):
    """Test the default value when a bad pagination option is given."""
    mocker.patch('djangopress.blog.views.Option.objects.get_or_create',
                 new=option_get_or_create_stub('a')
                 )
    category_mock = mocker.patch('djangopress.blog.models.Category.objects')
    category = mommy.prepare(Category, name='Uncategorized')
    category.pk = 1
    category_mock.get_or_create.return_value = category, None
    posts_mock = mocker.patch('djangopress.blog.models.Post.objects.all')
    posts_mock.return_value = mommy.prepare(Post, _quantity=6)
    request = rf.get(reverse('djangopress:home'))
    response = PostList.as_view()(request)
    assert response.context_data['paginator'].per_page == 5
开发者ID:gilmrjc,项目名称:djangopress,代码行数:14,代码来源:test_views.py


示例18: test_post_list_custom_pagination_pag

def test_post_list_custom_pagination_pag(rf, mocker):
    """Test a custom pagination value."""
    mocker.patch('djangopress.blog.views.Option.objects.get_or_create',
                 new=option_get_or_create_stub('3')
                 )
    category_mock = mocker.patch('djangopress.blog.models.Category.objects')
    category = mommy.prepare(Category, name='Uncategorized')
    category.pk = 1
    category_mock.get_or_create.return_value = category, None
    posts_mock = mocker.patch('djangopress.blog.models.Post.objects.all')
    posts_mock.return_value = mommy.prepare(Post, _quantity=4)
    request = rf.get(reverse('djangopress:home'))
    response = PostList.as_view()(request)
    assert response.context_data['is_paginated']
开发者ID:gilmrjc,项目名称:djangopress,代码行数:14,代码来源:test_views.py


示例19: test_only_single_editable_group_for_each_period_id_none

 def test_only_single_editable_group_for_each_period_id_none(self):
     period1 = mommy.make('core.Period')
     period2 = mommy.make('core.Period')
     permissiongroup = mommy.make('devilry_account.PermissionGroup',
                                  grouptype=PermissionGroup.GROUPTYPE_PERIODADMIN,
                                  is_custom_manageable=True)
     mommy.make('devilry_account.PeriodPermissionGroup',
                permissiongroup=permissiongroup,
                period=period1)
     with self.assertRaisesMessage(ValidationError, 'Only a single editable permission '
                                                    'group is allowed for a semester.'):
         mommy.prepare('devilry_account.PeriodPermissionGroup',
                       permissiongroup=permissiongroup,
                       period=period2).clean()
开发者ID:Nasmi1,项目名称:devilry-django,代码行数:14,代码来源:test_models.py


示例20: test_only_single_editable_group_for_each_subject_id_none

 def test_only_single_editable_group_for_each_subject_id_none(self):
     subject1 = mommy.make('core.Subject')
     subject2 = mommy.make('core.Subject')
     permissiongroup = mommy.make('devilry_account.PermissionGroup',
                                  grouptype=PermissionGroup.GROUPTYPE_SUBJECTADMIN,
                                  is_custom_manageable=True)
     mommy.make('devilry_account.SubjectPermissionGroup',
                permissiongroup=permissiongroup,
                subject=subject1)
     with self.assertRaisesMessage(ValidationError, 'Only a single editable permission '
                                                    'group is allowed for a course.'):
         mommy.prepare('devilry_account.SubjectPermissionGroup',
                       permissiongroup=permissiongroup,
                       subject=subject2).clean()
开发者ID:Nasmi1,项目名称:devilry-django,代码行数:14,代码来源:test_models.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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