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


Python mommy.prepare_recipe函数代码示例

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


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

示例1: test_base_form_catches_gender_of_consent

 def test_base_form_catches_gender_of_consent(self):
     site_consents.registry = {}
     self.consent_factory(
         start=self.study_open_datetime,
         end=self.study_open_datetime + timedelta(days=50),
         version='1.0',
         gender=[MALE])
     subject_consent = mommy.prepare_recipe(
         'edc_consent.subjectconsent',
         consent_datetime=self.study_open_datetime,
         dob=self.dob,
         gender=MALE)
     form = SubjectConsentForm(subject_consent.__dict__)
     subject_consent.initials = subject_consent.first_name[
         0] + subject_consent.last_name[0]
     self.assertTrue(form.is_valid())
     subject_consent = mommy.prepare_recipe(
         'edc_consent.subjectconsent',
         consent_datetime=self.study_open_datetime,
         dob=self.dob,
         gender=FEMALE)
     form = SubjectConsentForm(subject_consent.__dict__)
     subject_consent.initials = subject_consent.first_name[
         0] + subject_consent.last_name[0]
     self.assertFalse(form.is_valid())
开发者ID:botswana-harvard,项目名称:edc-consent,代码行数:25,代码来源:test_consent_form.py

示例2: test_blog_exposes_articles_tags_are_order

def test_blog_exposes_articles_tags_are_order():
    """
    The Blog model can retrieve a list of all available tags.
    The list of tags is ordered according to the usage so that
    more used tags are listed first.
        - the Blog page is a child of the root page
        - the Blog page contains two posts
        - post_1 has two tags, post_2 has one tags
        - a tag is used twice while the other only once
        - blog.tags must return two tags; the first one should be
          the most common
    """
    # create a blog page with two posts
    root_page = get_root_page()
    blog = mommy.prepare_recipe('tests.recipes.blog')
    posts = mommy.prepare_recipe('tests.recipes.post', _quantity=2)
    link_page(root_page, blog)
    link_page(blog, posts)
    # append two tags to two different posts
    tag_1 = mommy.make('blog.PostTag', content_object=posts[0]).tag
    tag_2 = mommy.make('blog.PostTag', content_object=posts[1]).tag
    # one tag is used twice
    mommy.make('blog.PostTag', tag=tag_2, content_object=posts[0])

    assert len(blog.tags) == 2
    assert blog.tags[0] == tag_2
    assert blog.tags[1] == tag_1
开发者ID:palazzem,项目名称:wagtail-nesting-box,代码行数:27,代码来源:test_blog.py

示例3: test_blog_tag_filter

def test_blog_tag_filter(rf):
    """
    Alice is a user that wants to read our blog. She opens the
    /blog/ webpage and choose a particular tag filter.
    She expects to find only a subset of posts, according to
    the chosen tag.
        - the Blog page contains three posts
        - two posts shares one tag while the other one has
          a different tag
        - Alice navigates to /blog/ page choosing the common tag
        - Alice expects to see two posts
    """
    # create a blog page with three posts
    root_page = get_root_page()
    blog = mommy.prepare_recipe('tests.recipes.blog')
    posts = mommy.prepare_recipe('tests.recipes.post', _quantity=3)
    link_page(root_page, blog)
    link_page(blog, posts)
    # append the proper tags
    tag_1 = mommy.make('blog.PostTag', content_object=posts[0]).tag
    tag_2 = mommy.make('blog.PostTag', content_object=posts[1]).tag
    # the third post is tagged with tag_1
    mommy.make('blog.PostTag', tag=tag_1, content_object=posts[2])
    # create a fake request with a tag attribute
    request = add_site_to_request(rf.get(blog.slug, {'tag': tag_1.name}))
    context = blog.get_context(request)
    assert len(context['articles']) == 2
    assert context['current_tag'] == tag_1.name
开发者ID:palazzem,项目名称:wagtail-nesting-box,代码行数:28,代码来源:test_blog_views.py

示例4: test_save_related_instances_on_prepare_recipe

    def test_save_related_instances_on_prepare_recipe(self):
        dog = mommy.prepare_recipe("test.generic.homeless_dog")
        self.assertIsNone(dog.id)
        self.assertIsNone(dog.owner.id)

        dog = mommy.prepare_recipe("test.generic.homeless_dog", _save_related=True)
        self.assertIsNone(dog.id)
        self.assertTrue(dog.owner.id)
开发者ID:berinhard,项目名称:model_mommy,代码行数:8,代码来源:test_recipes.py

示例5: test_do_not_create_related_model

 def test_do_not_create_related_model(self):
     """
       It should not attempt to create other object when
       passing the object as argument
     """
     person = mommy.make_recipe('test.generic.person')
     self.assertEqual(Person.objects.count(), 1)
     mommy.make_recipe('test.generic.dog', owner=person)
     self.assertEqual(Person.objects.count(), 1)
     mommy.prepare_recipe('test.generic.dog', owner=person)
     self.assertEqual(Person.objects.count(), 1)
开发者ID:lucassimon,项目名称:model_mommy,代码行数:11,代码来源:test_recipes.py

示例6: test_gets_most_recent_assignment_date

    def test_gets_most_recent_assignment_date(self):
        assignment1 = mommy.prepare_recipe('devices.assignment_recipe')
        assignment2 = mommy.prepare_recipe('devices.assignment_recipe')

        old_date = datetime.date.today() - datetime.timedelta(days=14)
        assignment1.save()
        assignment2.save()
        self.device.save()
        mommy.make('DeviceAssignment', device=self.device, assignment=assignment1, assignment_date=old_date)
        mommy.make('DeviceAssignment', device=self.device, assignment=assignment2)
        result = self.device.get_last_assignment_date()
        assert_equal(result, assignment2.assignment_date())
开发者ID:OperacionesTW-EC,项目名称:selene,代码行数:12,代码来源:device_test.py

示例7: _assert_text_field_has_maximum_length_of_characters

    def _assert_text_field_has_maximum_length_of_characters(self, mommy_recipe, field, max_length):
        """
        Helper method for asserting a field has a maximum length of characters
        """
        test_object1 = mommy.prepare_recipe(mommy_recipe, **{field: 'a'*(max_length+1)})
        exclude_fields = test_object1._meta.get_all_field_names()
        exclude_fields.remove(field)
        test_object1.full_clean.when.called_with(exclude=exclude_fields).should\
            .throw(ValidationError, "{'%s': [u'%s must be %s characters or less']}" % (field, field, max_length))

        test_object2 = mommy.prepare_recipe(mommy_recipe, **{field: 'a'*max_length})
        test_object2.full_clean.when.called_with(exclude=exclude_fields).should_not.throw(Exception)
开发者ID:grjones,项目名称:exercise,代码行数:12,代码来源:base.py

示例8: test_can_get_last_assignment_date

 def test_can_get_last_assignment_date(self):
     assignment = mommy.prepare_recipe('devices.assignment_recipe')
     assignment.save()
     self.device.save()
     mommy.make('DeviceAssignment', device=self.device, assignment=assignment)
     result = self.device.get_last_assignment_date()
     assert_equal(result, assignment.assignment_date())
开发者ID:OperacionesTW-EC,项目名称:selene,代码行数:7,代码来源:device_test.py

示例9: test_increment_for_strings

 def test_increment_for_strings(self):
     person = mommy.make_recipe("test.generic.serial_person")
     self.assertEqual(person.name, "joe1")
     person = mommy.prepare_recipe("test.generic.serial_person")
     self.assertEqual(person.name, "joe2")
     person = mommy.make_recipe("test.generic.serial_person")
     self.assertEqual(person.name, "joe3")
开发者ID:berinhard,项目名称:model_mommy,代码行数:7,代码来源:test_recipes.py

示例10: test_increment_after_override_definition_field

 def test_increment_after_override_definition_field(self):
     person = mommy.make_recipe("test.generic.serial_person", name="tom")
     self.assertEqual(person.name, "tom")
     person = mommy.make_recipe("test.generic.serial_person")
     self.assertEqual(person.name, "joe1")
     person = mommy.prepare_recipe("test.generic.serial_person")
     self.assertEqual(person.name, "joe2")
开发者ID:berinhard,项目名称:model_mommy,代码行数:7,代码来源:test_recipes.py

示例11: test_lcavailed_post_save_without_lc_number_validation

    def test_lcavailed_post_save_without_lc_number_validation(self):
        """Test saving LcAvailed with lc_number validation switched off."""

        lc = mommy.prepare_recipe('lcavail.lcavailed')

        # calling save() on the LcAvailed instance will raise ValidationError
        # because the lc_number will not return True when we call
        # adhocmodels.models.ValidTransactionRef.is_valid_trxn_ref(
        #     lc_number)
        with nt.assert_raises(ValidationError):
            lc.save()

        # we assert that no LcAvailed object has been created because the
        # previous call raised ValidationError
        nt.eq_(LcAvailed.objects.count(), 0)

        # we set the dont_validate property for lc_number
        lc.dont_validate = {
            'lc_number': True,
        }

        # calling save( now will not raise ValidationError)
        lc.save()

        # we check that an LcAvailed object has indeed been created
        nt.eq_(LcAvailed.objects.count(), 1)
开发者ID:samba6,项目名称:recons2,代码行数:26,代码来源:tests.py

示例12: test_do_query_lookup_for_recipes_prepare_method

 def test_do_query_lookup_for_recipes_prepare_method(self):
     """
       It should not attempt to create other object when
       using query lookup syntax
     """
     dog = mommy.prepare_recipe('test.generic.dog', owner__name='James')
     self.assertEqual(dog.owner.name, 'James')
开发者ID:berinhard,项目名称:model_mommy,代码行数:7,代码来源:test_recipes.py

示例13: test_blog_exposes_empty_tags_as_default

def test_blog_exposes_empty_tags_as_default():
    """
    The Blog model can retrieve a list of all available tags.
    By default, a Post doesn't have a Tag.
        - the Blog page is a child of the root page
        - the Blog page contains a post
        - blog.tags must return an empty list
    """
    # create a blog post with two posts
    root_page = get_root_page()
    blog = mommy.prepare_recipe('tests.recipes.blog')
    post = mommy.prepare_recipe('tests.recipes.post')
    link_page(root_page, blog)
    link_page(blog, post)

    assert len(blog.tags) == 0
开发者ID:palazzem,项目名称:wagtail-nesting-box,代码行数:16,代码来源:test_blog.py

示例14: setup

 def setup(self):
     self.project = models.Project(name='Selene')
     self.device = mommy.prepare_recipe('devices.non_asset_device_recipe')
     self.device.sequence = None
     self.device.code = None
     self.device.save()
     self.project.save()
开发者ID:OperacionesTW-EC,项目名称:selene,代码行数:7,代码来源:assigment_test.py

示例15: test_blog_articles

def test_blog_articles():
    """
    Test the Blog model so that users may retrieve all published
    articles.
        - the Blog page is a child of the root page
        - the Blog page contains two posts
        - blog.articles must return two (live) posts
    """
    # create a blog post with two posts
    root_page = get_root_page()
    blog = mommy.prepare_recipe('tests.recipes.blog')
    posts = mommy.prepare_recipe('tests.recipes.post', _quantity=2)
    link_page(root_page, blog)
    link_page(blog, posts)

    assert len(blog.articles) == 2
开发者ID:palazzem,项目名称:wagtail-nesting-box,代码行数:16,代码来源:test_blog.py


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