def test_double_save(self): """Double save without refresh of an object with a DEFAULTED_ON_CREATE field should not cause a problem. """ oppo = Opportunity(name='test op', stage='Prospecting', close_date=datetime.date.today()) oppo.save() try: oppo.save() finally: oppo.delete()
def test_many2many_relationship(self): """Verify that the related set of Many2Many relationship works Test for issue #55 """ contact = Contact.objects.all()[0] oppo = Opportunity(name='test op', stage='Prospecting', close_date=datetime.date.today()) oppo.save() oc = OpportunityContactRole(opportunity=oppo, contact=contact, role='rolicka') oc.save() oc2 = OpportunityContactRole(opportunity=oppo, contact=contact, role='rolicka') oc2.save() try: qs = contact.opportunities.all() sql, params = qs.query.get_compiler('salesforce').as_sql() self.assertRegexpMatches( sql, 'SELECT .*OpportunityContactRole\.Opportunity\.StageName.* ' 'FROM OpportunityContactRole WHERE OpportunityContactRole.ContactId =' ) self.assertEqual([x.pk for x in qs], 2 * [oppo.pk]) finally: oc2.delete() oc.delete() oppo.delete()
def test_many2many_relationship(self): """Verify that the related set of Many2Many relationship works Test for issue #55 """ contact = Contact.objects.all()[0] oppo = Opportunity(name='test op', stage='Prospecting', close_date=datetime.date.today()) oppo.save() oc = OpportunityContactRole(opportunity=oppo, contact=contact, role='sponsor') oc.save() oc2 = OpportunityContactRole(opportunity=oppo, contact=contact, role='evaluator') oc2.save() try: qs = contact.opportunities.all() sql, params = qs.query.get_compiler('salesforce').as_sql() self.assertRegexpMatches(sql, 'SELECT .*OpportunityContactRole\.Opportunity\.StageName.* ' 'FROM OpportunityContactRole WHERE OpportunityContactRole.ContactId =') self.assertEqual([x.pk for x in qs], 2 * [oppo.pk]) finally: oc2.delete() oc.delete() oppo.delete()
def test_range_lookup(self): """Get the test opportunity record by range condition. """ test_opportunity = Opportunity( name="Example Opportunity", close_date=datetime.date(year=2015, month=7, day=30), stage="Prospecting", amount=130000.00 ) test_opportunity.save() try: # Test date objects start_date = datetime.date(year=2015, month=7, day=29) end_date = datetime.date(year=2015, month=8, day=1) oppy = Opportunity.objects.filter(close_date__range=(start_date, end_date))[0] self.assertEqual(oppy.name, 'Example Opportunity') self.assertEqual(oppy.stage, 'Prospecting') # Test datetime objects (now +- 10 minutes for clock inaccuracy) start_time = timezone.now() - datetime.timedelta(seconds=600) end_time = timezone.now() + datetime.timedelta(seconds=600) opportunities = Opportunity.objects.filter(created_date__range=(start_time, end_time))[:1] self.assertEqual(len(opportunities), 1, "Failed range filter or maybe incorrectly set clock") oppy = opportunities[0] self.assertEqual(oppy.name, 'Example Opportunity') self.assertEqual(oppy.stage, 'Prospecting') # Test DecimalField low_amount, high_amount = 100000.00, 140000.00 oppy = Opportunity.objects.filter(amount__range=(low_amount, high_amount))[0] self.assertEqual(oppy.amount, 130000.00) # Test CharField low_letter, high_letter = 'E', 'G' oppy = Opportunity.objects.filter(name__range=(low_letter, high_letter))[0] self.assertEqual(oppy.name, 'Example Opportunity') finally: test_opportunity.delete()
def test_range_lookup(self): """Get the test opportunity record by range condition. """ test_opportunity = Opportunity(name="Example Opportunity", close_date=datetime.date(year=2015, month=7, day=30), stage="Prospecting", amount=130000.00) test_opportunity.save() try: # Test date objects start_date = datetime.date(year=2015, month=7, day=29) end_date = datetime.date(year=2015, month=8, day=1) oppy = Opportunity.objects.filter(close_date__range=(start_date, end_date))[0] self.assertEqual(oppy.name, 'Example Opportunity') self.assertEqual(oppy.stage, 'Prospecting') # Test datetime objects (now +- 10 minutes for clock inaccuracy) start_time = timezone.now() - datetime.timedelta(seconds=600) end_time = timezone.now() + datetime.timedelta(seconds=600) opportunities = Opportunity.objects.filter( created_date__range=(start_time, end_time))[:1] self.assertEqual( len(opportunities), 1, "Failed range filter or maybe incorrectly set clock") oppy = opportunities[0] self.assertEqual(oppy.name, 'Example Opportunity') self.assertEqual(oppy.stage, 'Prospecting') # Test DecimalField low_amount, high_amount = 100000.00, 140000.00 oppy = Opportunity.objects.filter(amount__range=(low_amount, high_amount))[0] self.assertEqual(oppy.amount, 130000.00) # Test CharField low_letter, high_letter = 'E', 'G' oppy = Opportunity.objects.filter(name__range=(low_letter, high_letter))[0] self.assertEqual(oppy.name, 'Example Opportunity') finally: test_opportunity.delete()