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


Python mommy.prepare函数代码示例

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


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


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