Example #1
0
    def test_admin(self):
        """Test that mainly improves code coverage."""

        # Log in as a superuser
        user = django.contrib.auth.models.User.objects.create_user(
            'fredsu', '*****@*****.**', 'passwd')
        user.is_superuser = True
        user.is_staff = True
        user.save()
        self.client.login(username='******', password='******')

        account = Account(Name='sf_test account')
        account.save()

        response = self.client.get('/')
        response = self.client.get('/search/')
        response = self.client.post('/search/', {'query': 'test account'})
        self.assertIn(b'sf_test account', response.content)
        response = self.client.post('/admin/example/account/')
        response = self.client.post('/admin/example/contact/')
        response = self.client.post('/admin/example/lead/')
        response = self.client.post('/admin/example/pricebook/')
        response = self.client.post('/admin/')
        self.assertIn('PricebookEntries', response.rendered_content)
        account.delete()
        user.delete()
	def test_admin(self):
		"""Test that mainly improves code coverage."""

		# Log in as a superuser
		user = django.contrib.auth.models.User.objects.create_user('fredsu', '*****@*****.**', 'passwd')
		user.is_superuser = True
		user.is_staff = True
		user.save()
		self.client.login(username='******', password='******')

		account = Account(Name = 'sf_test account')
		account.save()

		response = self.client.get('/')
		response = self.client.get('/search/')
		response = self.client.post('/search/', {'query': 'test account'})
		self.assertIn(b'sf_test account', response.content)
		response = self.client.post('/admin/example/account/')
		response = self.client.post('/admin/example/contact/')
		response = self.client.post('/admin/example/lead/')
		response = self.client.post('/admin/example/pricebook/')
		response = self.client.post('/admin/')
		self.assertIn('PricebookEntries', response.rendered_content)
		account.delete()
		user.delete()
	def test_escape_single_quote(self):
		"""
		Test that single quotes in strings used in filtering a QuerySet
		are escaped properly.
		"""
		account_name = '''Dr. Evil's Giant "Laser", LLC'''
		account = Account(Name=account_name)
		account.save()
		try:
			self.assertTrue(Account.objects.filter(Name=account_name).exists())
		finally:
			account.delete()
Example #4
0
    def test_escape_single_quote(self):
        """Test single quotes in strings used in a filter
		
		Verity that they are escaped properly.
		"""
        account_name = '''Dr. Evil's Giant\\' "Laser", LLC'''
        account = Account(Name=account_name)
        account.save()
        try:
            self.assertTrue(Account.objects.filter(Name=account_name).exists())
        finally:
            account.delete()
 def test_foreign_key_column(self):
     """Verify filtering by a column of related parent object.
     """
     test_account = Account(Name='sf_test account')
     test_account.save()
     test_contact = Contact(first_name='sf_test', last_name='my', account=test_account)
     test_contact.save()
     try:
         contacts = Contact.objects.filter(account__Name='sf_test account')
         self.assertEqual(len(contacts), 1)
     finally:
         test_contact.delete()
         test_account.delete()
Example #6
0
    def test_account_insert_delete(self):
        """Test insert and delete an account (normal or personal SF config)
		"""
        if settings.PERSON_ACCOUNT_ACTIVATED:
            test_account = Account(FirstName='IntegrationTest',
                                   LastName='Account')
        else:
            test_account = Account(Name='IntegrationTest Account')
        test_account.save()
        try:
            accounts = Account.objects.filter(Name='IntegrationTest Account')
            self.assertEqual(len(accounts), 1)
        finally:
            test_account.delete()
    def test_escape_single_quote_in_raw_query(self):
        """Test that manual escaping within a raw query is not double escaped.
        """
        account_name = '''Dr. Evil's Giant\\' "Laser", LLC'''
        account = Account(Name=account_name)
        account.save()

        manually_escaped = '''Dr. Evil\\'s Giant\\\\\\' "Laser", LLC'''
        try:
            retrieved_account = Account.objects.raw(
                "SELECT Id, Name FROM Account WHERE Name = '%s'" % manually_escaped)[0]
            self.assertEqual(account_name, retrieved_account.Name)
        finally:
            account.delete()
 def test_account_insert_delete(self):
     """Test insert and delete an account (normal or personal SF config)
     """
     if settings.PERSON_ACCOUNT_ACTIVATED:
         test_account = Account(FirstName='IntegrationTest',
                 LastName='Account')
     else:
         test_account = Account(Name='IntegrationTest Account')
     test_account.save()
     try:
         accounts = Account.objects.filter(Name='IntegrationTest Account')
         self.assertEqual(len(accounts), 1)
     finally:
         test_account.delete()
    def test_bulk_create(self):
        """Create two Contacts by one request in one command and find them.
        """
        account = Account(Name='test bulk')
        account.save()
        try:
            objects = [Contact(last_name='sf_test a', account=account),
                       Contact(last_name='sf_test b', account=account)]
            request_count_0 = salesforce.backend.driver.request_count

            ret = Contact.objects.bulk_create(objects)

            request_count_1 = salesforce.backend.driver.request_count
            self.assertEqual(request_count_1,  request_count_0 + 1)
            self.assertEqual(len(Contact.objects.filter(account=account)), 2)
        finally:
            account.delete()
    def test_bulk_create(self):
        """Create two Contacts by one request in one command and find them.
        """
        account = Account(Name='test bulk')
        account.save()
        try:
            objects = [Contact(last_name='sf_test a', account=account),
                       Contact(last_name='sf_test b', account=account)]
            request_count_0 = salesforce.backend.driver.request_count

            ret = Contact.objects.bulk_create(objects)

            request_count_1 = salesforce.backend.driver.request_count
            self.assertEqual(request_count_1,  request_count_0 + 1)
            self.assertEqual(len(Contact.objects.filter(account=account)), 2)
        finally:
            account.delete()
	def test_insert_date(self):
		"""
		Test inserting a date.
		"""
		self.skipTest("Need to find a suitable *standard* model field to test datetime inserts.")
		
		now = datetime.datetime.now()
		account = Account(
			FirstName = 'Joe',
			LastName = 'Freelancer',
			LastLogin = now,
			IsPersonAccount = False,
		)
		account.save()
		
		saved = Account.objects.get(pk=account.pk)
		self.assertEqual(saved.LastLogin, now)
		self.assertEqual(saved.IsPersonAccount, False)
		
		saved.delete()
 def test_simple_select_related(self):
     """Verify that simple_selct_related does not require additional queries.
     """
     test_account = Account(Name='sf_test account')
     test_account.save()
     test_contact = Contact(first_name='sf_test', last_name='my', account=test_account)
     test_contact.save()
     req_count_0 = salesforce.backend.driver.request_count
     try:
         qs = Contact.objects.filter(account__Name='sf_test account').simple_select_related('account')
         contacts = list(qs)
         req_count_1 = salesforce.backend.driver.request_count
         [x.account.Name for x in contacts]
         req_count_2 = salesforce.backend.driver.request_count
         self.assertEqual(req_count_1, req_count_0 + 2)
         self.assertEqual(req_count_2, req_count_1)
         self.assertGreaterEqual(len(contacts), 1)
     finally:
         test_contact.delete()
         test_account.delete()
Example #13
0
    def test_bulk_create(self):
        """Create two Contacts by one request in one command and find them.
        """
        account = Account(Name='test bulk')
        account.save()
        try:
            objects = [
                Contact(last_name='sf_test a', account=account),
                Contact(last_name='sf_test b', account=account)
            ]
            request_count_0 = salesforce.backend.driver.request_count

            ret = Contact.objects.bulk_create(objects)
            if DJANGO_110_PLUS:
                # test that can return ids from bulk_create
                self.assertTrue(ret and all(x.pk for x in ret))

            request_count_1 = salesforce.backend.driver.request_count
            self.assertEqual(request_count_1, request_count_0 + 1)
            self.assertEqual(len(Contact.objects.filter(account=account)), 2)
        finally:
            account.delete()