Python model_mommy.mommy.make() Examples
The following are 30
code examples of model_mommy.mommy.make().
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 also want to check out all available functions/classes of the module
model_mommy.mommy
, or try the search function
.
Example #1
Source File: fakes.py From OasisPlatform with BSD 3-Clause "New" or "Revised" License | 6 votes |
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 #2
Source File: model_tests.py From codesy with GNU Affero General Public License v3.0 | 6 votes |
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 #3
Source File: test_views.py From tafseer_api with MIT License | 6 votes |
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 #4
Source File: model_tests.py From codesy with GNU Affero General Public License v3.0 | 6 votes |
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 #5
Source File: __init__.py From codesy with GNU Affero General Public License v3.0 | 6 votes |
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 #6
Source File: __init__.py From codesy with GNU Affero General Public License v3.0 | 6 votes |
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 #7
Source File: model_tests.py From codesy with GNU Affero General Public License v3.0 | 6 votes |
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 #8
Source File: test_views.py From django-admin-view-permission with BSD 2-Clause "Simplified" License | 6 votes |
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 #9
Source File: model_tests.py From codesy with GNU Affero General Public License v3.0 | 6 votes |
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 #10
Source File: test_views.py From call-tracking-django with MIT License | 6 votes |
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 #11
Source File: model_tests.py From codesy with GNU Affero General Public License v3.0 | 6 votes |
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
Source File: model_tests.py From codesy with GNU Affero General Public License v3.0 | 5 votes |
def test_last_offer_returns_none_when_no_offer(self): bid_without_offer = mommy.make(Bid, ask=50) self.assertEqual(None, bid_without_offer.last_offer)
Example #13
Source File: model_tests.py From codesy with GNU Affero General Public License v3.0 | 5 votes |
def test_send_email_to_other_offerers_when_claim_is_made(self, mock_send_mail): # Should be called 3 times: for user2, user3, and user4 mock_send_mail.is_callable().times_called(3) mommy.make( Claim, user=self.user1, issue=self.issue, evidence=self.evidence, created=timezone.now() )
Example #14
Source File: model_tests.py From codesy with GNU Affero General Public License v3.0 | 5 votes |
def setUp(self): 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') url = 'http://test.com/bug/123' issue = mommy.make(Issue, url=url) mommy.make(Bid, user=self.user1, url=url, issue=issue, ask=50) mommy.make(Bid, user=self.user2, url=url, issue=issue, offer=50) mommy.make(Bid, user=self.user3, url=url, issue=issue, offer=50) self.claim = mommy.make(Claim, issue=issue, user=self.user1)
Example #15
Source File: model_tests.py From codesy with GNU Affero General Public License v3.0 | 5 votes |
def test_dont_send_email_on_saving_claim(self, mock_send_mail): mock_send_mail.is_callable().times_called(3) claim = mommy.make( Claim, user=self.user1, issue=self.issue, created=timezone.now() ) claim.evidence = 'http://test.com/updated-evidence' claim.save() claim.status = 'Rejected' claim.save()
Example #16
Source File: model_tests.py From codesy with GNU Affero General Public License v3.0 | 5 votes |
def test_dont_email_self_when_offering_more_than_ask(self, mock_send_mail): mock_send_mail.is_callable().times_called(0) user = mommy.make(settings.AUTH_USER_MODEL) url = 'https://github.com/codesy/codesy/issues/149' offer_bid = mommy.make( Bid, user=user, url=url, offer=100, ask=10 ) offer_bid.save()
Example #17
Source File: model_tests.py From codesy with GNU Affero General Public License v3.0 | 5 votes |
def test_unicode(self): vote = mommy.make(Vote, approved=True) self.assertEqual( str(vote), 'Vote for %s by (%s): %s' % (vote.claim, vote.user, vote.approved) )
Example #18
Source File: model_tests.py From codesy with GNU Affero General Public License v3.0 | 5 votes |
def test_user_ids_who_can_vote(self): user4 = mommy.make(settings.AUTH_USER_MODEL) self.assertTrue( self.user2.id in self.claim.user_ids_who_can_vote() ) self.assertFalse( user4.id in self.claim.user_ids_who_can_vote() )
Example #19
Source File: model_tests.py From codesy with GNU Affero General Public License v3.0 | 5 votes |
def test_save_creates_issue_for_new_url(self): url = 'https://github.com/codesy/codesy/issues/165' mommy.make(Bid, ask=200, offer=5, url=url) issues = Issue.objects.all() self.assertEquals(2, len(issues)) issue = Issue.objects.get(url=url) self.assertEquals(url, issue.url)
Example #20
Source File: model_tests.py From codesy with GNU Affero General Public License v3.0 | 5 votes |
def test_save_assigns_issue_for_existing_url(self): self.bid1 = Bid.objects.get(pk=self.bid1.id) existing_issue = self.bid1.issue new_bid = mommy.make(Bid, ask=200, offer=5, url=existing_issue.url) new_bid = Bid.objects.get(pk=new_bid.id) self.assertIsNotNone(new_bid.issue) issues = Issue.objects.all() self.assertEquals(1, len(issues)) issue = issues[0] self.assertEquals(self.url, issue.url)
Example #21
Source File: model_tests.py From codesy with GNU Affero General Public License v3.0 | 5 votes |
def test_ask_met(self): self.assertFalse(self.bid1.ask_met()) mommy.make(Bid, ask=0, offer=10, url=self.url) self.assertTrue(self.bid1.ask_met())
Example #22
Source File: model_tests.py From codesy with GNU Affero General Public License v3.0 | 5 votes |
def test_mail_contains_text_for_claiming_via_url(self, mock_send_mail): user = mommy.make(settings.AUTH_USER_MODEL) self.bid1.ask_match_sent = timezone.now() self.bid1.save() mock_send_mail.expects_call().with_args( arg.any(), arg.contains(self.bid1.url), arg.any(), ['user2@test.com'] ) mommy.make( Bid, offer=100, user=user, ask=1000, url=self.url )
Example #23
Source File: model_tests.py From codesy with GNU Affero General Public License v3.0 | 5 votes |
def test_save_title(self): ModelsWithURL = ['Bid', 'Claim', 'Issue'] for model_name in ModelsWithURL: model = mommy.make(model_name) retrieve_model = type(model).objects.get(pk=model.id) self.assertEqual(retrieve_model.title, 'Howdy Dammit')
Example #24
Source File: view_tests.py From codesy with GNU Affero General Public License v3.0 | 5 votes |
def test_get_queryset_filters_by_request_user(self): user1, url, issue, claim1 = _make_test_claim() user2 = mommy.make(settings.AUTH_USER_MODEL) mommy.make('auctions.Claim', user=user2) self.viewset.request = fudge.Fake().has_attr(user=user1) qs = self.viewset.get_queryset() self.assertSequenceEqual(qs.order_by('id'), [claim1, ])
Example #25
Source File: view_tests.py From codesy with GNU Affero General Public License v3.0 | 5 votes |
def test_get_queryset_filters_by_request_user(self): user1, url, bid1 = _make_test_bid() user2 = mommy.make(settings.AUTH_USER_MODEL) mommy.make('auctions.Bid', user=user2) mommy.make('auctions.Bid', user=user2) bid4 = mommy.make('auctions.Bid', user=user1) bid5 = mommy.make('auctions.Bid', user=user1) self.viewset.request = fudge.Fake().has_attr(user=user1) qs = self.viewset.get_queryset() self.assertSequenceEqual(qs.order_by('id'), [bid1, bid4, bid5])
Example #26
Source File: view_tests.py From codesy with GNU Affero General Public License v3.0 | 5 votes |
def _make_test_bid(): user = mommy.make(settings.AUTH_USER_MODEL) url = 'http://gh.com/project' issue = mommy.make('auctions.Issue', url=url) bid = mommy.make('auctions.Bid', user=user, url=url, issue=issue) return user, url, bid
Example #27
Source File: view_tests.py From codesy with GNU Affero General Public License v3.0 | 5 votes |
def test_get_object(self): user = mommy.make(settings.AUTH_USER_MODEL) self.view.request = fudge.Fake().has_attr(user=user) obj = self.view.get_object() self.assertEqual(obj, user)
Example #28
Source File: model_tests.py From codesy with GNU Affero General Public License v3.0 | 5 votes |
def test_account_updated(self): account = mommy.make(StripeAccount, account_id='acct_00000000000000') event = mommy.make(StripeEvent, message_text=json.loads('{"id": "evt_1"}')) # replace fake retrieved message event.message_text = account_updated AccountUpdatedProcessor(event=event).process() account = StripeAccount.objects.get(pk=account.id) self.assertEqual(account.fields_needed, ['legal_entity.verification.document'])
Example #29
Source File: model_tests.py From codesy with GNU Affero General Public License v3.0 | 5 votes |
def test_process_not_implemented(self): class test_hook(WebHookProcessor): pass event = mommy.make( StripeEvent, message_text=json.loads(balance_available) ) with self.assertRaises(NotImplementedError): test_hook(event=event).process()
Example #30
Source File: model_tests.py From codesy with GNU Affero General Public License v3.0 | 5 votes |
def test_event_without_userid(self): event = mommy.make( StripeEvent, message_text=json.loads(application_fee_created) ) self.assertTrue(event.verified) self.assertEqual(event.type, 'payment.created') self.assertTrue(event.processed)