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


Python mommy.make_one函数代码示例

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


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

示例1: test_make_path

 def test_make_path(self):
     page = mommy.make_one(WikiPage, title='p1')
     page2 = mommy.make_one(WikiPage, title='p2', parent_page=page)
     pages = WikiPage.make_path('p1/p2/p3')
     assert page.id == pages[0].id
     assert page2.id == pages[1].id
     assert len(pages) == 2
开发者ID:Apkawa,项目名称:django-wikinya,代码行数:7,代码来源:tests.py

示例2: gerarTemplate

    def gerarTemplate(self):
        "gera um template com filtro coerentes"
        from Avaliacao.Questao.models import Questao

#    Avaliação ->
#    1 -> q1
#    2 -> C, Facil
#    3 -> Facil, C.Malloc
        #prepara a avaliacao
        self.templateAvaliacao = TemplateAvaliacao(titulo="Avaliacao Teste Filtros",turma=self.turma,ativa=True)
        self.templateAvaliacao.data_inicio = datetime.datetime.now() - datetime.timedelta(hours=3)
        self.templateAvaliacao.data_termino = datetime.datetime.now() + datetime.timedelta(hours=5)
        self.templateAvaliacao.save()
        #prepara os filtros
        #são 3 questoes na avaliacao

        tipos = TipoQuestao.objects.filter(tipo__in = ["C", "Facil"] )
        fq1 = mommy.make_one(FiltroQuestao,templateAvaliacao=self.templateAvaliacao,questaoExata=Questao.objects.get(pk=1),tipo=tipos)
        fq1.save()

        tipos = TipoQuestao.objects.filter(tipo__in = ["C", "Facil"] )
        fq2 = mommy.make_one(FiltroQuestao,templateAvaliacao=self.templateAvaliacao,questaoExata=None,tipo=tipos)
        fq2.save()

        tipos = TipoQuestao.objects.filter(tipo__in = ["Facil","Malloc"] )
        fq3 = mommy.make_one(FiltroQuestao,templateAvaliacao=self.templateAvaliacao,questaoExata=None,tipo=tipos)
        fq3.save()
开发者ID:arruda,项目名称:amao,代码行数:27,代码来源:test_models.py

示例3: test_model_listener_stop

    def test_model_listener_stop(self):
        """
        Tests that stopping the signal will not fire the events
        """
        ml = ModelListener()
        ml.name = "test_listener"
        ml.app = "example_app"
        ml.model = "Dummy"
        ml.active = True
        ml.post_save_handler = "example.example_app.tests.fake_functions.fake"
        ml.post_delete_handler = "example.example_app.tests.fake_functions.fake"
        ml.auto_on = True
        ml.save()

        ModelListenerTestCase.fired = False

        self.assertTrue(ml._is_method_valid(ml.post_save_handler))
        self.assertTrue(ml._is_method_valid(ml.post_delete_handler))

        ml._stop_listening()

        dummy = mommy.make_one(Dummy)
        dummy.save()

        self.assertFalse(ModelListenerTestCase.fired)

        ml._start_listening()
        ModelListenerTestCase.fired = False

        dummy2 = mommy.make_one(Dummy)

        self.assertTrue(ModelListenerTestCase.fired)

        ml._stop_listening()
开发者ID:sigma-geosistemas,项目名称:sigma.metamodel,代码行数:34,代码来源:models.py

示例4: test_model_listener_turn_off

    def test_model_listener_turn_off(self):
        """
        Simple model listener construction.
        Tests that the signals will not be fired when auto_on = False
        """
        ml = ModelListener()
        ml.name = "test_listener"
        ml.app = "example_app"
        ml.model = "Dummy"
        ml.active = True
        ml.post_save_handler = "example.example_app.tests.fake_functions.fake"
        ml.post_delete_handler = "example.example_app.tests.fake_functions.fake"
        ml.auto_on = True
        ml.save()

        self.assertTrue(ml._is_method_valid(ml.post_save_handler))
        self.assertTrue(ml._is_method_valid(ml.post_delete_handler))

        dummy = mommy.make_one(Dummy)
        dummy.save()

        self.assertTrue(ModelListenerTestCase.fired)

        ml._stop_listening()
        ModelListenerTestCase.fired = False

        dummy2 = mommy.make_one(Dummy)

        self.assertFalse(ModelListenerTestCase.fired)

        ml._stop_listening()
开发者ID:sigma-geosistemas,项目名称:sigma.metamodel,代码行数:31,代码来源:models.py

示例5: setUp

    def setUp(self):
        #Tastypie stuff
        super(TestDeploymentResource, self).setUp()

        self.bob_api_client = TestApiClient()
        self.bill_api_client = TestApiClient()
        self.anon_api_client = TestApiClient()

        # Create a user bob.
        self.user_bob_username = 'bob'
        self.user_bob_password = 'bob'
        self.user_bob = User.objects.create_user(self.user_bob_username,
                                                 '[email protected]',
                                                 self.user_bob_password)

        # Create a user bob.
        self.user_bill_username = 'bill'
        self.user_bill_password = 'bill'
        self.user_bill = User.objects.create_user(self.user_bill_username,
                                                  '[email protected]',
                                                  self.user_bill_password)

        self.bob_api_client.client.login(username='bob', password='bob')
        self.bill_api_client.client.login(username='bill', password='bill')

        #assign users to the Public group
        public_group, created = Group.objects.get_or_create(name='Public')
        self.user_bob.groups.add(public_group)
        self.user_bill.groups.add(public_group)
        guardian.utils.get_anonymous_user().groups.add(public_group)

        #make a couple of campaigns and save
        self.campaign_bobs = mommy.make_one('catamidb.Campaign', id=1)
        self.campaign_bills = mommy.make_one('catamidb.Campaign', id=2)

        #make a deployments
        self.deployment_bobs = mommy.make_recipe('catamidb.Deployment1',
                                                 id=1,
                                                 campaign=self.campaign_bobs)
        self.deployment_bills = mommy.make_recipe('catamidb.Deployment2',
                                                  id=2,
                                                  campaign=self.campaign_bills)

        #assign this one to bob
        authorization.apply_campaign_permissions(
            self.user_bob, self.campaign_bobs)

        #assign this one to bill
        authorization.apply_campaign_permissions(self.user_bill,
                                                 self.campaign_bills)

        #the API url for deployments
        self.deployment_url = '/api/dev/deployment/'

        #some post data for testing deployment creation
        self.post_data = {
            'type': 'AUV',
            'operator': 'XXX',
        }
开发者ID:catami,项目名称:catami,代码行数:59,代码来源:tests.py

示例6: test_create_two_penguins_in_love

    def test_create_two_penguins_in_love(self):
        from model_mommy import mommy
        from model_mommy.models import Penguin

        male = mommy.make_one(Penguin)
        female = mommy.make_one(Penguin, partner=male)
        self.assertEqual(male, female.partner)
        self.assertEqual(male.mate, female)
开发者ID:MediaSapiens,项目名称:model_mommy,代码行数:8,代码来源:test_mommy.py

示例7: setUp

    def setUp(self):
        #Tastypie stuff
        super(TestCampaignResource, self).setUp()

        self.bob_api_client = TestApiClient()
        self.bill_api_client = TestApiClient()
        self.anon_api_client = TestApiClient()

        # Create a user bob.
        self.user_bob_username = 'bob'
        self.user_bob_password = 'bob'
        self.user_bob = User.objects.create_user(self.user_bob_username,
                                                 '[email protected]',
                                                 self.user_bob_password)

        # Create a user bob.
        self.user_bill_username = 'bill'
        self.user_bill_password = 'bill'
        self.user_bill = User.objects.create_user(self.user_bill_username,
                                                  '[email protected]',
                                                  self.user_bill_password)

        self.bob_api_client.client.login(username='bob', password='bob')
        self.bill_api_client.client.login(username='bill', password='bill')

        #assign users to the Public group
        public_group, created = Group.objects.get_or_create(name='Public')
        self.user_bob.groups.add(public_group)
        self.user_bill.groups.add(public_group)
        guardian.utils.get_anonymous_user().groups.add(public_group)

        #make a couple of campaigns and save
        self.campaign_bobs = mommy.make_one('catamidb.Campaign', id=1)
        self.campaign_bills = mommy.make_one('catamidb.Campaign', id=2)

        #assign this one to bob
        authorization.apply_campaign_permissions(
            self.user_bob, self.campaign_bobs)

        #assign this one to bill
        authorization.apply_campaign_permissions(
            self.user_bill, self.campaign_bills)

        #the API url for campaigns
        self.campaign_url = '/api/dev/campaign/'

        #some post data for testing campaign creation
        self.post_data = {
            'short_name': 'Blah',
            'description': 'Blah',
            'associated_researchers': 'Blah',
            'associated_publications': 'Blah',
            'associated_research_grant': 'Blah',
            'date_start': '2012-05-01',
            'date_end': '2012-05-01',
            'contact_person': 'Blah',
        }
开发者ID:acfrmarine,项目名称:squidle,代码行数:57,代码来源:tests.py

示例8: setUp

    def setUp(self):
        # Tastypie stuff
        super(TestCameraResource, self).setUp()

        self.bob_api_client = TestApiClient()
        self.bill_api_client = TestApiClient()
        self.anon_api_client = TestApiClient()

        # Create a user bob.
        self.user_bob_username = "bob"
        self.user_bob_password = "bob"
        self.user_bob = User.objects.create_user(self.user_bob_username, "[email protected]", self.user_bob_password)

        # Create a user bob.
        self.user_bill_username = "bill"
        self.user_bill_password = "bill"
        self.user_bill = User.objects.create_user(
            self.user_bill_username, "[email protected]", self.user_bill_password
        )

        self.bob_api_client.client.login(username="bob", password="bob")
        self.bill_api_client.client.login(username="bill", password="bill")

        # assign users to the Public group
        public_group, created = Group.objects.get_or_create(name="Public")
        self.user_bob.groups.add(public_group)
        self.user_bill.groups.add(public_group)
        guardian.utils.get_anonymous_user().groups.add(public_group)

        # make a couple of campaigns and save
        self.campaign_bobs = mommy.make_one("catamidb.Campaign", id=1)
        self.campaign_bills = mommy.make_one("catamidb.Campaign", id=2)

        # make a deployments
        self.deployment_bobs = mommy.make_recipe("catamidb.Deployment1", id=1, campaign=self.campaign_bobs)
        self.deployment_bills = mommy.make_recipe("catamidb.Deployment2", id=2, campaign=self.campaign_bills)

        # make images
        self.image_bobs = mommy.make_recipe("catamidb.Image1", id=1, deployment=self.deployment_bobs)

        self.image_bills = mommy.make_recipe("catamidb.Image2", id=2, deployment=self.deployment_bills)

        # make cameras
        self.camera_bobs = mommy.make_one("catamidb.Camera", id=1, image=self.image_bobs)
        self.camera_bills = mommy.make_one("catamidb.Camera", id=2, image=self.image_bills)

        # assign this one to bob
        authorization.apply_campaign_permissions(self.user_bob, self.campaign_bobs)

        # assign this one to bill
        authorization.apply_campaign_permissions(self.user_bill, self.campaign_bills)

        # the API url for deployments
        self.camera_url = "/api/dev/camera/"

        # some post data for testing camera creation
        self.post_data = []
开发者ID:stevenvandervalk,项目名称:benthobox,代码行数:57,代码来源:tests.py

示例9: setUp

 def setUp(self):
     mommy.make_one(Chapter)
     self.ontem = date.today() - timedelta(days=1)
     old = mommy.make_one(Chapter)
     old.day = self.ontem
     old.save()
     old = mommy.make_one(Chapter)
     old.day = self.ontem
     old.save()
开发者ID:flavioamieiro,项目名称:umahistoria,代码行数:9,代码来源:tests.py

示例10: create_setup

def create_setup(self):
    self.campaign_one = mommy.make_one('catamidb.Campaign', id=1)

    self.deployment_one = mommy.make_one('catamidb.Deployment',
            start_position=Point(12.4604, 43.9420),
            end_position=Point(12.4604, 43.9420),
            transect_shape=Polygon(((0.0, 0.0), (0.0, 50.0), (50.0, 50.0), (50.0, 0.0), (0.0, 0.0))),
            id=1,
            campaign=self.campaign_one
        )
    self.deployment_two = mommy.make_one('catamidb.Deployment',
            start_position=Point(12.4604, 43.9420),
            end_position=Point(12.4604, 43.9420),
            transect_shape=Polygon(((0.0, 0.0), (0.0, 50.0), (50.0, 50.0), (50.0, 0.0), (0.0, 0.0))),
            id=1,
            campaign=self.campaign_one
        )

    self.pose_one = mommy.make_one('catamidb.Pose',
            position=Point(12.4, 23.5),
            id=1,
            deployment=self.deployment_one
        )
    self.pose_two = mommy.make_one('catamidb.Pose',
            position=Point(12.4, 23.5),
            id=2,
            deployment=self.deployment_two
        )

    self.camera_one = mommy.make_one('catamidb.Camera',
            deployment=self.deployment_one,
            id=1,
        )
    self.camera_two = mommy.make_one('catamidb.Camera',
            deployment=self.deployment_two,
            id=1,
        )

    self.image_list = ['/live/test/test2.jpg', '/live/test/test1.jpg']
    self.mock_image_one = mommy.make_one('catamidb.Image',
            pose=self.pose_one,
            camera=self.camera_one,
            web_location=self.image_list[0],
            pk=1
        )
    self.mock_image_two = mommy.make_one('catamidb.Image',
            pose=self.pose_two,
            camera=self.camera_two,
            web_location=self.image_list[1],
            pk=2
        )

    image_objects = Image.objects.all()
    for image in image_objects:
        self.djt.image_primary_keys.append(image.pk)
开发者ID:acfrmarine,项目名称:squidle,代码行数:55,代码来源:tests.py

示例11: test_camera_operations_as_authorised_users

    def test_camera_operations_as_authorised_users(self):
        # create a campaign & deployment that ONLY bill can see
        bills_campaign = mommy.make_one('catamidb.Campaign', id=3, short_name='cp_3')
        bills_deployment = mommy.make_recipe('catamidb.Deployment3', id=3,
                                             campaign=bills_campaign)
        assign('view_campaign', self.user_bill, bills_campaign)

        #make exclusive image for bill and assign this image to camera to image
        self.image_bill_exc = mommy.make_recipe(
            'catamidb.Image3',
            id=3,             
            deployment=bills_deployment) #IMPORTANT camera checks campaign which has reference to deployment. Image has reference to deployment and camera

        #make exclusive camera for bill
        self.camera_bill_exc = mommy.make_one(
            'catamidb.Camera',
            id=3,
            image=self.image_bill_exc)

        # check that bill can see via the API
        response = self.bill_api_client.get(self.camera_url, format='json')
        self.assertValidJSONResponse(response)
        self.assertEqual(len(self.deserialize(response)['objects']), 3)

        # check that bill can get to the object itself
        response = self.bill_api_client.get(self.camera_url + "3/",
                                            format='json')
        self.assertValidJSONResponse(response)

        # check that bob can not see - now we know tastypie API has correct
        # permission validation
        response = self.bob_api_client.get(self.camera_url, format='json')       
        self.assertValidJSONResponse(response)
        self.assertEqual(len(self.deserialize(response)['objects']), 2)

        # check bob can NOT get to the hidden object
        response = self.bob_api_client.get(self.camera_url + "3/",
                                           format='json')
        self.assertHttpUnauthorized(response)

        #check that anonymous can see public ones as well
        response = self.anon_api_client.get(self.camera_url, format='json')
        self.assertValidJSONResponse(response)
        self.assertEqual(len(self.deserialize(response)['objects']), 2)

        #check anonymous can NOT get to the hidden object
        response = self.anon_api_client.get(self.camera_url + "3/",
                                            format='json')
        self.assertHttpUnauthorized(response)
开发者ID:catami,项目名称:catami,代码行数:49,代码来源:tests.py

示例12: test_image_measurement_operations_as_authorised_users

    def test_image_measurement_operations_as_authorised_users(self):
        # create a campaign & deployment that ONLY bill can see
        bills_campaign = mommy.make_one('catamidb.Campaign', id=3)
        bills_deployment = mommy.make_recipe('catamidb.auvdeployment', id=3,
                                             campaign=bills_campaign)
        bills_pose = mommy.make_recipe('catamidb.pose3', id=3,
                                       deployment=bills_deployment)
        bills_camera = mommy.make_one('catamidb.Camera', id=3,
                                      deployment=bills_deployment)
        bills_image = mommy.make_one('catamidb.Image', id=3, pose=bills_pose,
                                     camera=bills_camera)
        bills_image_measurement = mommy.make_one(
            'catamidb.ScientificImageMeasurement', id=3, image=bills_image)
        assign('view_campaign', self.user_bill, bills_campaign)

        # check that bill can see via the API
        response = self.bill_api_client.get(self.image_measurement_url,
                                            format='json')
        self.assertValidJSONResponse(response)
        self.assertEqual(len(self.deserialize(response)['objects']), 3)

        # check that bill can get to the object itself
        response = self.bill_api_client.get(self.image_measurement_url + "3/",
                                            format='json')
        self.assertValidJSONResponse(response)

        # check that bob can not see - now we know tastypie API has correct
        # permission validation
        response = self.bob_api_client.get(self.image_measurement_url,
                                           format='json')

        self.assertValidJSONResponse(response)
        self.assertEqual(len(self.deserialize(response)['objects']), 2)

        # check bob can NOT get to the hidden object
        response = self.bob_api_client.get(self.image_measurement_url + "3/",
                                           format='json')
        self.assertHttpUnauthorized(response)

        #check that anonymous can see public ones as well
        response = self.anon_api_client.get(self.image_measurement_url,
                                            format='json')
        self.assertValidJSONResponse(response)
        self.assertEqual(len(self.deserialize(response)['objects']), 2)

        #check anonymous can NOT get to the hidden object
        response = self.anon_api_client.get(self.image_measurement_url + "3/",
                                            format='json')
        self.assertHttpUnauthorized(response)
开发者ID:acfrmarine,项目名称:squidle,代码行数:49,代码来源:tests.py

示例13: test_render_template

 def test_render_template(self):
     """make sure render do not fail"""
     for i in xrange(5):
         mommy.make_one(User)
     
     template = Template(self._template_content())
     
     dummy_request = DummyRequest()
     setattr(dummy_request, 'user', self.user)
     context = {
         'users': User.objects.all(),
         'request': dummy_request,
     }
     
     template.render(Context(context))
开发者ID:Maxence42,项目名称:balafon,代码行数:15,代码来源:tests.py

示例14: test_filling_DecimalField_with_random_decimal

    def test_filling_DecimalField_with_random_decimal(self):
        self.dummy_decimal_model = mommy.make_one(DummyDecimalModel)
        decimal_field = DummyDecimalModel._meta.get_field('decimal_field')

        self.assertTrue(isinstance(decimal_field, DecimalField))
        self.assertTrue(isinstance(self.dummy_decimal_model.decimal_field,
                                   Decimal))
开发者ID:andrewsmedina,项目名称:model_mommy,代码行数:7,代码来源:test_filling_fields.py

示例15: test_make_one_should_create_one_object

    def test_make_one_should_create_one_object(self):
        from model_mommy import mommy
        from model_mommy.models import Kid

        kid = mommy.make_one(Kid)
        self.assertTrue(isinstance(kid, Kid))
        self.assertEqual(Kid.objects.all().count(), 1)
开发者ID:AMHZR,项目名称:model_mommy,代码行数:7,代码来源:test_mommy.py


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