Python model_mommy.mommy.make() Examples

The following are 30 code examples for showing how to use model_mommy.mommy.make(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module model_mommy.mommy , or try the search function .

Example 1
Project: call-tracking-django   Author: TwilioDevEd   File: test_views.py    License: MIT License 6 votes vote down vote up
def test_forward_call(self):
        # Arrange
        lead_source = mommy.make(
            LeadSource,
            incoming_number='+15555555555',
            forwarding_number='+16666666666')

        # Act
        response = self.client.post(
            '/call-tracking/forward-call',
            {'Called': '+15555555555', 'Caller': '+17777777777', 'CallerCity': 'Washington', 'CallerState': 'DC'})

        # Assert
        self.assertEqual(response.status_code, 200)
        self.assertIn('<Dial>+16666666666</Dial>', str(response.content))

        # Check that a new lead was created
        lead = Lead.objects.get(source=lead_source)
        self.assertEqual(lead.city, 'Washington')
        self.assertEqual(lead.state, 'DC') 
Example 2
def test_changelist_view_post_from_user_with_vd_perm_on_model1(self):
        obj = mommy.make('test_app.TestModel1')
        data = {
            'index': ['0'],
            'action': ['delete_selected'],
            'select_across': ['0'],
            '_selected_action': [str(obj.pk)]
        }
        self.client.login(
            username='user_with_vd_perm_on_model1',
            password='simple_user',
        )
        response = self.client.post(
            reverse('admin:%s_%s_changelist' % ('test_app', 'testmodel1')),
            data=data,
        )

        assert response.status_code == 200
        assert response.context['title'] == 'Are you sure?' 
Example 3
Project: OasisPlatform   Author: OasisLMF   File: fakes.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def fake_analysis(**kwargs):
    if isinstance(kwargs.get('input_file'), (six.string_types, six.binary_type)):
        kwargs['input_file'] = fake_related_file(file=kwargs['input_file'])

    if isinstance(kwargs.get('lookup_errors_file'), (six.string_types, six.binary_type)):
        kwargs['lookup_errors_file'] = fake_related_file(file=kwargs['lookup_errors_file'])

    if isinstance(kwargs.get('lookup_success_file'), (six.string_types, six.binary_type)):
        kwargs['lookup_success_file'] = fake_related_file(file=kwargs['lookup_success_file'])

    if isinstance(kwargs.get('lookup_validation_file'), (six.string_types, six.binary_type)):
        kwargs['lookup_validation_file'] = fake_related_file(file=kwargs['lookup_validation_file'])

    if isinstance(kwargs.get('output_file'), (six.string_types, six.binary_type)):
        kwargs['output_file'] = fake_related_file(file=kwargs['output_file'])

    if isinstance(kwargs.get('settings_file'), (six.string_types, six.binary_type)):
        kwargs['settings_file'] = fake_related_file(file=kwargs['settings_file'])

    return mommy.make(Analysis, **kwargs) 
Example 4
Project: tafseer_api   Author: Quran-Tafseer   File: test_views.py    License: MIT License 6 votes vote down vote up
def setUp(self):
        self.sura = mommy.make('quran_text.sura', name='Al-Bakarah', index=2)
        self.ayah = mommy.make('quran_text.ayah', number=1, sura=self.sura,
                               text='بسم الله الرحمن الرحيم')
        self.ayah_2 = mommy.make('quran_text.ayah', number=2, sura=self.sura,
                                 text='الحمد لله رب العالمين')
        self.tafseer = mommy.make('quran_tafseer.Tafseer', name='simple',
                                  language='ar', book_name='simple book',
                                  author='random')
        self.tafseer_text = mommy.make('quran_tafseer.TafseerText',
                                       ayah=self.ayah, tafseer=self.tafseer,
                                       text='بسم الله الرحمن الرحيم')
        self.tafseer_text_2 = mommy.make('quran_tafseer.TafseerText',
                                         ayah=self.ayah_2,
                                         tafseer=self.tafseer,
                                         text='الحمد لله رب العالمين') 
Example 5
Project: codesy   Author: codesy   File: __init__.py    License: GNU Affero General Public License v3.0 6 votes vote down vote up
def setUp(self):
        """
        Set up the following market of Bids for a single bug:
            url: http://github.com/codesy/codesy/issues/37
            user1: ask 50,  offer 0
            user2: ask 100, offer 10
            user3: ask 0,   offer 30
        """
        self.url = 'http://github.com/codesy/codesy/issues/37'
        self.issue = mommy.make(Issue, url=self.url)
        self.user1 = mommy.make(settings.AUTH_USER_MODEL,
                                email='user1@test.com')
        self.user2 = mommy.make(settings.AUTH_USER_MODEL,
                                email='user2@test.com')
        self.user3 = mommy.make(settings.AUTH_USER_MODEL,
                                email='user3@test.com')
        self.bid1 = mommy.make(Bid, user=self.user1,
                               ask=50, offer=0, url=self.url)
        self.bid2 = mommy.make(Bid, user=self.user2,
                               ask=100, offer=10, url=self.url)
        self.bid3 = mommy.make(Bid, user=self.user3,
                               ask=0, offer=30, url=self.url) 
Example 6
Project: codesy   Author: codesy   File: __init__.py    License: GNU Affero General Public License v3.0 6 votes vote down vote up
def setUp(self):
        """
        Set up the following claim senarios
            user1: asks 50
            user2: offers 25
            user3: offers 25
            user1 claims
        """
        self.url = 'http://github.com/codesy/codesy/issues/37'
        self.issue = mommy.make(Issue, url=self.url)

        self.user1 = mommy.make(settings.AUTH_USER_MODEL,
                                email='user1@test.com')
        self.user2 = mommy.make(settings.AUTH_USER_MODEL,
                                email='user2@test.com')
        self.user3 = mommy.make(settings.AUTH_USER_MODEL,
                                email='user3@test.com')
        self.bid1 = mommy.make(Bid, user=self.user1,
                               ask=50, offer=0, url=self.url, issue=self.issue)
        self.bid2 = mommy.make(Bid, user=self.user2,
                               ask=0, offer=25, url=self.url, issue=self.issue)
        self.bid3 = mommy.make(Bid, user=self.user3,
                               ask=0, offer=25, url=self.url, issue=self.issue)
        self.claim = mommy.make(Claim, user=self.user1, issue=self.issue) 
Example 7
Project: codesy   Author: codesy   File: model_tests.py    License: GNU Affero General Public License v3.0 6 votes vote down vote up
def test_save_updates_datetimes(self):
        test_bid = mommy.make(Bid)
        test_bid = Bid.objects.get(pk=test_bid.pk)
        test_bid_created = test_bid.created
        self.assertTrue(
            timezone.now() >= test_bid_created.replace(),
            "Bid.created should be auto-populated."
        )
        time.sleep(1)
        test_bid.ask = 100
        test_bid.offer = 10
        test_bid.save()
        self.assertEqual(test_bid_created, test_bid.created,
                         "Bid.created should stay the same after an update.")
        test_bid_modified = test_bid.modified
        self.assertTrue(test_bid_modified >= test_bid_created,
                        "Bid.modified should be auto-populated on update.")
        self.assertTrue(
            timezone.now() >= test_bid_modified.replace(),
            "Bid.modified should be auto-populated."
        ) 
Example 8
Project: codesy   Author: codesy   File: model_tests.py    License: GNU Affero General Public License v3.0 6 votes vote down vote up
def test_send_mail_to_matching_askers(self, mock_send_mail):
        user = mommy.make(settings.AUTH_USER_MODEL)
        bid1_subject = "[codesy] There's $50 waiting for you!"
        bid2_subject = "[codesy] There's $100 waiting for you!"
        mock_send_mail.expects_call().with_args(
            bid1_subject,
            arg.any(),
            arg.any(),
            ['user1@test.com']
        )
        mock_send_mail.next_call().with_args(
            bid2_subject,
            arg.any(),
            arg.any(),
            ['user2@test.com']
        )

        offer_bid = mommy.make(
            Bid, offer=100, user=user, ask=1000, url=self.url
        )
        offer_bid.save() 
Example 9
Project: codesy   Author: codesy   File: model_tests.py    License: GNU Affero General Public License v3.0 6 votes vote down vote up
def test_only_send_mail_to_unsent_matching_askers(self, mock_send_mail):
        user = mommy.make(settings.AUTH_USER_MODEL)
        self.bid1.ask_match_sent = timezone.now()
        self.bid1.save()
        subject = "[codesy] There's $100 waiting for you!"

        mock_send_mail.expects_call().with_args(
            subject,
            arg.any(),
            arg.any(),
            ['user2@test.com']
        )

        offer_bid = mommy.make(
            Bid, offer=100, user=user, ask=1000, url=self.url
        )
        offer_bid.save() 
Example 10
Project: codesy   Author: codesy   File: model_tests.py    License: GNU Affero General Public License v3.0 6 votes vote down vote up
def setUp(self):
        """
        Add a final bid and a user2 claim to the MarketWithBidsTestCase,
        so the final market for the bug is now:
            url: http://github.com/codesy/codesy/issues/37
            user1: ask 50,  offer 0  (ask is met)
            user2: ask 100, offer 10
            user3: ask 0,   offer 30
            user4: ask 200, offer 10
        And user1 is making the claim
        """
        super(NotifyMatchingOfferersTest, self).setUp()
        self.user4 = mommy.make(settings.AUTH_USER_MODEL,
                                email='user4@test.com')
        self.bid4 = mommy.make(Bid, user=self.user4,
                               ask=200, offer=10, url=self.url)
        self.evidence = ('https://github.com/codesy/codesy/commit/'
                         '4f1bcd014ec735918bebd1c386e2f99a7f83ff64') 
Example 11
Project: codesy   Author: codesy   File: model_tests.py    License: GNU Affero General Public License v3.0 6 votes vote down vote up
def test_save_updates_datetimes(self):
        test_vote = mommy.make(Vote, approved=False)
        test_vote = Vote.objects.get(pk=test_vote.pk)
        test_vote_created = test_vote.created
        self.assertTrue(
            timezone.now() >= test_vote_created.replace(),
            "Vote.created should be auto-populated."
        )
        time.sleep(1)
        test_vote.approved = True
        test_vote.save()
        self.assertEqual(test_vote_created, test_vote.created,
                         "Vote.created should stay the same after an update.")
        test_vote_modified = test_vote.modified
        self.assertTrue(test_vote_modified >= test_vote_created,
                        "Vote.modified should be auto-populated on update.")
        self.assertTrue(
            timezone.now() >= test_vote_modified.replace(),
            "Vote.modified should be auto-populated."
        ) 
Example 12
Project: pythonjobs.ie   Author: kimeraapp   File: test_views.py    License: GNU General Public License v2.0 5 votes vote down vote up
def test_index_list_active_jobs(self):
        mommy.make(Job, status=0)
        response = self.client.get(reverse("job-home"))
        self.assertEquals(len(response.context["jobs"]), 1) 
Example 13
Project: pythonjobs.ie   Author: kimeraapp   File: test_views.py    License: GNU General Public License v2.0 5 votes vote down vote up
def test_show_inactive_job_returns_404(self):
        job = mommy.make(Job, status=0)
        response = self.client.get(reverse("job-show", args=[job.pk]))
        self.assertEquals(response.status_code, 404) 
Example 14
Project: pythonjobs.ie   Author: kimeraapp   File: test_models.py    License: GNU General Public License v2.0 5 votes vote down vote up
def test_external_link_not_required(self):
        mommy.make(Job, external_link="")
        self.assertEquals(len(Job.objects.all()), 1) 
Example 15
Project: pythonjobs.ie   Author: kimeraapp   File: test_models.py    License: GNU General Public License v2.0 5 votes vote down vote up
def test_token_is_unique(self):
        firstjob = mommy.make(Job, token='12345')
        secondjob = mommy.make(Job, token='12345')

        self.assertNotEqual(firstjob.token, secondjob.token) 
Example 16
Project: call-tracking-django   Author: TwilioDevEd   File: test_views.py    License: MIT License 5 votes vote down vote up
def test_home_page_extra_context(self):
        # Arrange
        lead_source = mommy.make(LeadSource, incoming_number='+15555555555')

        # Act
        response = self.client.get('/')

        # Assert
        self.assertEqual(response.status_code, 200)
        self.assertIn('415', str(response.content))
        self.assertEqual(response.context['lead_sources'][0], lead_source) 
Example 17
Project: call-tracking-django   Author: TwilioDevEd   File: test_models.py    License: MIT License 5 votes vote down vote up
def test_str_name(self):
        # Arrange
        lead_source = mommy.make(
            LeadSource,
            name='Downtown billboard',
            incoming_number='+15555555555')

        # Assert
        self.assertEqual(str(lead_source), 'Downtown billboard - +15555555555') 
Example 18
Project: call-tracking-django   Author: TwilioDevEd   File: test_models.py    License: MIT License 5 votes vote down vote up
def test_str_no_name(self):
        # Arrange
        lead_source = mommy.make(
            LeadSource,
            incoming_number='+15555555555')

        # Assert
        self.assertEqual(str(lead_source), '(not yet named) - +15555555555') 
Example 19
Project: call-tracking-django   Author: TwilioDevEd   File: test_models.py    License: MIT License 5 votes vote down vote up
def test_get_leads_per_source(self):
        # Arrange
        lead_source_1 = mommy.make(
            LeadSource,
            name='Downtown billboard',
            incoming_number='+15555555555')

        mommy.make(Lead,
                   source=lead_source_1,
                   phone_number='+16666666666')

        lead_source_2 = mommy.make(
            LeadSource,
            name='Uptown billboard',
            incoming_number='+17777777777')

        mommy.make(Lead,
                   source=lead_source_2,
                   phone_number='+18888888888')

        mommy.make(Lead,
                   source=lead_source_2,
                   phone_number='+19999999999')

        # Act
        data = LeadSource.objects.get_leads_per_source()

        # Assert
        self.assertEqual(data, [{'name': 'Downtown billboard', 'lead__count': 1}, {
                         'name': 'Uptown billboard', 'lead__count': 2}]) 
Example 20
Project: call-tracking-django   Author: TwilioDevEd   File: test_models.py    License: MIT License 5 votes vote down vote up
def test_get_leads_per_city(self):
        # Arrange
        lead_source = mommy.make(
            LeadSource,
            name='Downtown billboard',
            incoming_number='+15555555555')

        mommy.make(Lead,
                   source=lead_source,
                   phone_number='+16666666666',
                   city='Washington')

        mommy.make(Lead,
                   source=lead_source,
                   phone_number='+17777777777',
                   city='Washington')

        mommy.make(Lead,
                   source=lead_source,
                   phone_number='+18888888888',
                   city='San Francisco')

        # Act
        data = Lead.objects.get_leads_per_city()

        # Assert
        self.assertEqual(data, [{'city': 'San Francisco', 'id__count': 1}, {
                         'city': 'Washington', 'id__count': 2}]) 
Example 21
def test_history_view_from_simple_user(self):
        obj = mommy.make('test_app.TestModel1')
        self.client.login(
            username='user_with_v_perm_on_model1',
            password='simple_user',
        )
        response = self.client.get(
            reverse('admin:%s_%s_history' % ('test_app', 'testmodel1'),
                    args=(obj.pk,)),
        )

        assert response.status_code == 200 
Example 22
def test_history_view_from_super_user(self):
        obj = mommy.make('test_app.TestModel1')
        self.client.login(username='super_user', password='super_user')
        response = self.client.get(
            reverse('admin:%s_%s_history' % ('test_app', 'testmodel1'),
                    args=(obj.pk,)),
        )

        assert response.status_code == 200

    # add 
Example 23
def test_change_view_from_simple_user(self):
        obj = mommy.make('test_app.TestModel1')
        self.client.login(
            username='user_with_v_perm_on_model1',
            password='simple_user',
        )
        response = self.client.get(
            reverse('admin:%s_%s_change' % ('test_app', 'testmodel1'),
                    args=(obj.pk,)),
        )

        assert response.status_code == 200 
Example 24
def test_change_view_from_simple_user_translatable(self):
        """
        Smoke test: check if the change view renders for a django-parler model.
        """
        # Ensure parler's templates are registered through INSTALLED_APPS,
        # but only for this test. This mimics the install steps at
        # http://django-parler.readthedocs.io/en/latest/quickstart.html.
        current_installed_apps = settings.INSTALLED_APPS
        installed_apps_with_parler = current_installed_apps + ['parler']

        with override_settings(INSTALLED_APPS=installed_apps_with_parler):
            obj = mommy.make('test_app.TestModelParler')
            self.client.login(
                username='user_with_v_perm_on_model1parler',
                password='simple_user',
            )
            response = self.client.get(
                reverse(
                    'admin:%s_%s_change' % (
                        'test_app', 'testmodelparler'
                    ),
                    args=(obj.pk,)
                ),
            )
            assert response.status_code == 200

            # var4 is a translatable field on this model. Check that it is
            # marked as read only under Django versions supporting it.
            if VERSION[0:2] == (1, 11) or VERSION[0] == 2:
                bs = BeautifulSoup(response.content.decode('utf-8'),
                                   'html.parser')
                var4_tags = bs.select('.field-var4')
                assert len(var4_tags) == 1
                assert len(var4_tags[0].select('.readonly')) == 1 
Example 25
def test_change_view_from_super_user(self):
        obj = mommy.make('test_app.TestModel1')
        self.client.login(username='super_user', password='super_user')
        response = self.client.get(
            reverse('admin:%s_%s_change' % ('test_app', 'testmodel1'),
                    args=(obj.pk, )),
        )

        assert response.status_code == 200

    # delete 
Example 26
def test_delete_view_from_simple_user(self):
        obj = mommy.make('test_app.TestModel1')
        self.client.login(
            username='user_with_v_perm_on_model1',
            password='simple_user',
        )
        response = self.client.get(
            reverse('admin:%s_%s_delete' % ('test_app', 'testmodel1'),
                    args=(obj.pk,)),
        )

        assert response.status_code == 403 
Example 27
def test_delete_view_from_simple_user_unauthorized_post(self):
        obj = mommy.make('test_app.TestModel1')
        self.client.login(
            username='user_with_v_perm_on_model1',
            password='simple_user',
        )
        response = self.client.post(
            reverse('admin:%s_%s_delete' % ('test_app', 'testmodel1'),
                    args=(obj.pk,)),
        )

        obj.refresh_from_db()

        assert response.status_code == 403
        assert obj 
Example 28
def test_delete_view_from_super_user(self):
        obj = mommy.make('test_app.TestModel1')
        self.client.login(username='super_user', password='super_user')
        response = self.client.get(
            reverse('admin:%s_%s_delete' % ('test_app', 'testmodel1'),
                    args=(obj.pk,)),
        )

        assert response.status_code == 200 
Example 29
def create_simple_user(username=None):
    if not username:
        username = SIMPLE_USERNAME

    simple_user = mommy.make(get_user_model(), username=username)
    simple_user.set_password('simple_user')
    # Django 1.8 compatibility
    simple_user.is_staff = True
    simple_user.save()

    return simple_user 
Example 30
def _obj_simple(self, obj_params):
        return mommy.make('test_app.TestModel1', **obj_params)