Exemple #1
0
 def test_lead_conversion(self):
     """
     Create a Lead object within Salesforce and try to
     convert it, convert/merge it with the information from a duplicit Lead,
     then clean all the generated objects.
     """
     lead = Lead(FirstName="Foo",
                 LastName="Bar",
                 Company="django-salesforce",
                 Street='Test Avenue 45')
     lead.save()
     lead2 = Lead(FirstName="Foo",
                  LastName="Bar",
                  Company="django-salesforce",
                  Phone='123456789')
     lead2.save()
     ret = None
     try:
         # convert the first Lead
         ret = convert_lead(lead, doNotCreateOpportunity=True)
         # print("Response from convertLead: " +
         #       ', '.join('%s: %s' % (k, v) for k, v in sorted(ret.items())))
         expected_names = set(('accountId', 'contactId', 'leadId',
                               'opportunityId', 'success'))
         self.assertEqual(set(ret), expected_names)
         self.assertEqual(ret['success'], 'true')
         # merge the new Account with the second Lead
         ret2 = convert_lead(lead2,
                             doNotCreateOpportunity=True,
                             accountId=ret['accountId'])
         account = Account.objects.get(pk=ret['accountId'])
         # verify that account is merged
         self.assertEqual(ret2['accountId'], account.pk)
         self.assertEqual(account.BillingStreet, 'Test Avenue 45')
         self.assertEqual(account.Phone, '123456789')
     finally:
         # Cleaning up...
         if ret:
             # Deleting the Account object will also delete the related Contact
             # and Opportunity objects.
             try:
                 account = Account.objects.get(pk=ret['accountId'])
             except Exception:  # pylint:disable=broad-except
                 # this allows to recycle the account even if the queryset code is broken
                 account = Account(pk=ret['accountId'])
                 account._state.db = lead._state.db
             account.delete()
         lead.delete()  # FYI, ret['leadId'] == lead.pk
         lead2.delete()
Exemple #2
0
    def test_filter_by_more_fk_to_the_same_model_subquery(self):
        """Test a filter with more relations to the same model.
		
		Verify that aliases are correctly decoded in the query compiler.
		"""
        test_lead = Lead(Company='sf_test lead', LastName='name')
        test_lead.save()
        test_task = Task(who=test_lead)
        test_task.save()
        try:
            qs = Task.objects.filter(who__in=Lead.objects.filter(
                pk=test_lead.pk,
                owner__Username=current_user,
                last_modified_by__Username=current_user))
            sql, params = qs.query.get_compiler('salesforce').as_sql()
            self.assertRegexpMatches(
                sql,
                'SELECT Task.Id, .* FROM Task WHERE Task.WhoId IN \(SELECT ')
            self.assertIn('Lead.Owner.Username = %s', sql)
            self.assertIn('Lead.LastModifiedBy.Username = %s', sql)
            refreshed_lead = qs[:1]
            self.assertEqual(len(refreshed_lead), 1)
        finally:
            test_task.delete()
            test_lead.delete()
    def test_lead_conversion(self):
        """
        Create a Lead object within Salesforce and try to
        convert it, then clean all the generated objects.
        """
        lead = Lead(FirstName="Foo", LastName="Bar", Company="django-salesforce")
        lead.save()

        # Get a status name setting for converted Leads
        cur = connections['salesforce'].cursor()
        cur.execute("SELECT MasterLabel FROM LeadStatus WHERE IsConverted=true")
        converted_status = cur.fetchone()['MasterLabel']

        ret = convert_lead(lead, converted_status=converted_status)
        print("Response from convertLead: " +
                ', '.join('%s: %s' % (k, v) for k, v in sorted(ret.items())))
        expected_names = set(('accountId', 'contactId', 'leadId', 'opportunityId', 'success'))
        self.assertEqual(set(ret), expected_names)
        self.assertEqual(ret['success'], 'true')

        # Cleaning up...
        # Deleting the Account object will also delete the related Contact
        # and Opportunity objects.
        account = Account.objects.get(pk=ret['accountId'])
        account.delete()

        lead.delete()   # FYI, ret['leadId'] == lead.pk
    def test_delete(self):
        """Create a lead record, then delete it, and make sure it's gone.
        """
        test_lead = Lead(FirstName="User", LastName="Unittest Deletes",
                Email='*****@*****.**',
                Company="Some company")
        test_lead.save()
        test_lead.delete()

        self.assertRaises(Lead.DoesNotExist, Lead.objects.get, Email='*****@*****.**')
 def test_insert(self):
     """Create a lead record, and make sure it ends up with a valid Salesforce ID.
     """
     test_lead = Lead(FirstName="User", LastName="Unittest Inserts",
             Email='*****@*****.**',
             Company="Some company")
     test_lead.save()
     try:
         self.assertEqual(len(test_lead.pk), 18)
     finally:
         test_lead.delete()
 def test_unicode(self):
     """Make sure weird unicode breaks properly.
     """
     test_lead = Lead(FirstName=u'\u2603', LastName="Unittest Unicode",
             Email='*****@*****.**',
             Company="Some company")
     test_lead.save()
     try:
         self.assertEqual(refresh(test_lead).FirstName, u'\u2603')
     finally:
         test_lead.delete()
Exemple #7
0
    def setUp(self):
        """
		Create our test lead record.
		"""
        self.test_lead = Lead(
            FirstName="User",
            LastName="Unittest General",
            Email=test_email,
            Status='Open',
            Company="Some company, Ltd.",
        )
        self.test_lead.save()
    def test_lead_conversion(self):
        """
        Create a Lead object within Salesforce and try to
        convert it, then clean all the generated objects.
        """
        lead = Lead(FirstName="Foo",
                    LastName="Bar",
                    Company="django-salesforce")
        lead.save()
        r = convert_lead(lead)
        print("Response from convertLead: " + str(r))
        print("Account ID: " + str(r[0]))
        print("Contact ID: " + str(r[1]))
        print("Opportunity ID: " + str(r[3]))

        # Cleaning up...
        # Deleting the Account object will also delete the related Contact
        # and Opportunity objects.
        account = Account.objects.get(pk=str(r[0]))
        account.delete()

        lead.delete()  # FYI, r[2] == lead.pk
    def setUp(self):
        """
		Create our test lead record.
		"""
        def add_obj(obj):
            obj.save()
            self.objs.append(obj)

        #
        self.test_lead = Lead(
            FirstName="User",
            LastName="Unittest General",
            Email=test_email,
            Status='Open',
            Company="Some company, Ltd.",
        )
        self.objs = []
        self.test_lead.save()
        if not default_is_sf:
            add_obj(Contact(LastName='Test contact 1'))
            add_obj(Contact(LastName='Test contact 2'))
            add_obj(User(Username=current_user))
Exemple #10
0
    def test_filter_by_more_fk_to_the_same_model(self):
        """Test a filter with more relations to the same model.
		
		Verify that aliases are correctly decoded in the query compiler.
		"""
        test_lead = Lead(Company='sf_test lead', LastName='name')
        test_lead.save()
        try:
            qs = Lead.objects.filter(pk=test_lead.pk,
                                     owner__Username=current_user,
                                     last_modified_by__Username=current_user)
            # Verify that a coplicated analysis is not performed on old Django
            # so that the query can be at least somehow simply compiled to SOQL
            # without exceptions, in order to prevent regressions.
            sql, params = qs.query.get_compiler('salesforce').as_sql()
            # Verify expected filters in SOQL compiled by new Django
            self.assertIn('Lead.Owner.Username = %s', sql)
            self.assertIn('Lead.LastModifiedBy.Username = %s', sql)
            # verify validity for SFDC, verify results
            refreshed_lead = qs.get()
            self.assertEqual(refreshed_lead.pk, test_lead.pk)
        finally:
            test_lead.delete()
 def setUp(self):
     """Create our test lead record.
     """
     def add_obj(obj):
         obj.save()
         self.objs.append(obj)
     #
     self.test_lead = Lead(
         FirstName="User" + uid,
         LastName="Unittest General",
         Email=test_email,
         Status='Open',
         Company="Some company, Ltd.",
     )
     self.objs = []
     self.test_lead.save()
     # This is only for demonstration that some test can be run even with
     # non SFDC database SALESFORCE_DB_ALIAS, even if the test expects some
     # contacts and the current user, but most of tests can pass only on SFDC.
     if not default_is_sf:
         add_obj(Contact(last_name='Test contact 1'))
         add_obj(Contact(last_name='Test contact 2'))
         add_obj(User(Username=current_user))