示例#1
0
    def test_generic_type_field(self):
        """Test that a generic foreign key can be filtered by type name and
		the type name can be referenced.
		"""
        test_contact = Contact(first_name='sf_test', last_name='my')
        test_contact.save()
        note_1 = Note(title='note for Lead', parent_id=self.test_lead.pk)
        note_2 = Note(title='note for Contact', parent_id=test_contact.pk)
        note_1.save()
        note_2.save()
        try:
            self.assertEqual(
                Note.objects.filter(parent_type='Contact')[0].parent_type,
                'Contact')
            self.assertEqual(
                Note.objects.filter(parent_type='Lead')[0].parent_type, 'Lead')

            note = Note.objects.filter(parent_type='Contact')[0]
            parent_model = getattr(salesforce.testrunner.example.models,
                                   note.parent_type)
            parent_object = parent_model.objects.get(pk=note.parent_id)
            self.assertEqual(parent_object.pk, note.parent_id)
        finally:
            note_1.delete()
            note_2.delete()
            test_contact.delete()
示例#2
0
    def test_default_specified_by_sf(self):
        """Verify insert of object with a field with default value on create by SF.

		(The default is used only for a field unspecified in SF REST API, but
		not for None or any similar value. It was a pain for some unimportant
		foreign keys that don't accept null.)
		"""
        # Verify a smart default is used.
        contact = Contact(first_name='sf_test', last_name='my')
        contact.save()
        try:
            self.assertEqual(refresh(contact).owner.Username, current_user)
        finally:
            contact.delete()
        # Verify that an explicit value is possible for this field.
        other_user_obj = User.objects.exclude(Username=current_user)[0]
        contact = Contact(first_name='sf_test',
                          last_name='your',
                          owner=other_user_obj)
        contact.save()
        try:
            self.assertEqual(
                refresh(contact).owner.Username, other_user_obj.Username)
        finally:
            contact.delete()
示例#3
0
    def test_insert_date(self):
        """Test inserting a date.
		"""
        now = timezone.now().replace(microsecond=0)
        contact = Contact(first_name='Joe',
                          last_name='Freelancer',
                          email_bounced_date=now)
        contact.save()
        try:
            self.assertEqual(refresh(contact).email_bounced_date, now)
        finally:
            contact.delete()
示例#4
0
    def test_insert_date(self):
        """
		Test inserting a date.
		"""
        now = round_datetime_utc(datetime.datetime.utcnow())
        contact = Contact(FirstName='Joe',
                          LastName='Freelancer',
                          EmailBouncedDate=now.replace(tzinfo=pytz.utc))
        contact.save()
        try:
            self.assertEqual(refresh(contact).EmailBouncedDate, now)
        finally:
            contact.delete()
 def test_foreign_key(self):
     """Verify that the owner of an Contact is the currently logged admin.
     """
     current_sf_user = User.objects.get(Username=current_user)
     test_contact = Contact(first_name='sf_test', last_name='my')
     test_contact.save()
     try:
         contact = Contact.objects.filter(owner=current_sf_user)[0]
         user = contact.owner
         # This user can be e.g. '[email protected]'.
         self.assertEqual(user.Username, current_user)
     finally:
         test_contact.delete()
示例#6
0
    def test_foreign_key(self):
        """Verify that the owner of an Contact is the currently logged admin.
		"""
        current_sf_user = User.objects.get(Username=current_user)
        test_contact = Contact(first_name='sf_test', last_name='my')
        test_contact.save()
        try:
            contact = Contact.objects.filter(owner=current_sf_user)[0]
            user = contact.owner
            # This user can be e.g. '[email protected]'.
            self.assertEqual(user.Username, current_user)
        finally:
            test_contact.delete()
 def test_insert_date(self):
     """Test inserting a date.
     """
     now = timezone.now().replace(microsecond=0)
     contact = Contact(
             first_name='Joe',
             last_name='Freelancer',
             email_bounced_date=now)
     contact.save()
     try:
         self.assertEqual(refresh(contact).email_bounced_date, now)
     finally:
         contact.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()
	def test_update_date(self):
		"""
		Test updating a date.
		"""
		now = timezone.now().replace(microsecond=0)
		contact = Contact(first_name = 'sf_test', last_name='my')
		contact.save()
		contact = refresh(contact)
		try:
			contact.email_bounced_date = now
			contact.save()
			self.assertEqual(refresh(contact).email_bounced_date, now)
		finally:
			contact.delete()
    def test_not_null_related(self):
        """Verify conditions `isnull` for foreign keys: filter(Account=None)

        filter(Account__isnull=True) and nested in Q(...) | Q(...).
        """
        test_contact = Contact(first_name='sf_test', last_name='my')
        test_contact.save()
        try:
            contacts = Contact.objects.filter(Q(account__isnull=True) |
                    Q(account=None), account=None, account__isnull=True,
                    first_name='sf_test')
            self.assertEqual(len(contacts), 1)
        finally:
            test_contact.delete()
	def test_insert_date(self):
		"""
		Test inserting a date.
		"""
		now = round_datetime_utc(datetime.datetime.utcnow())
		contact = Contact(
				FirstName = 'Joe',
				LastName = 'Freelancer',
				EmailBouncedDate=now.replace(tzinfo=pytz.utc))
		contact.save()
		try:
			self.assertEqual(refresh(contact).EmailBouncedDate, now)
		finally:
			contact.delete()
示例#12
0
    def test_update_date(self):
        """Test updating a date.
		"""
        # removed microseconds only for easy compare in the test, no problem
        now = timezone.now().replace(microsecond=0)
        contact = Contact(first_name='sf_test', last_name='my')
        contact.save()
        contact = refresh(contact)
        try:
            contact.email_bounced_date = now
            contact.save()
            self.assertEqual(refresh(contact).email_bounced_date, now)
        finally:
            contact.delete()
	def test_not_null_related(self):
		"""
		Verify conditions `isnull` for foreign keys: filter(Account=None)
		filter(Account__isnull=True) and nested in Q(...) | Q(...).
		"""
		test_contact = Contact(first_name='sf_test', last_name='my')
		test_contact.save()
		try:
			contacts = Contact.objects.filter(Q(account__isnull=True) |
					Q(account=None), account=None, account__isnull=True,
					first_name='sf_test')
			self.assertEqual(len(contacts), 1)
		finally:
			test_contact.delete()
	def test_date_comparison(self):
		"""
		Test that date comparisons work properly.
		"""
		today = round_datetime_utc(datetime.datetime(2013, 8, 27))
		yesterday = today - datetime.timedelta(days=1)
		tomorrow = today + datetime.timedelta(days=1)
		contact = Contact(FirstName='sf_test', LastName='date',
				EmailBouncedDate=today)
		contact.save()
		try:
			contacts1 = Contact.objects.filter(EmailBouncedDate__gt=yesterday)
			self.assertEqual(len(contacts1), 1)
			contacts2 = Contact.objects.filter(EmailBouncedDate__gt=tomorrow)
			self.assertEqual(len(contacts2), 0)
		finally:
			contact.delete()
 def test_date_comparison(self):
     """Test that date comparisons work properly.
     """
     today = datetime.datetime(2013, 8, 27)
     if settings.USE_TZ:
         today = timezone.make_aware(today, pytz.utc)
     yesterday = today - datetime.timedelta(days=1)
     tomorrow = today + datetime.timedelta(days=1)
     contact = Contact(first_name='sf_test' + uid, last_name='date',
             email_bounced_date=today)
     contact.save()
     try:
         contacts1 = Contact.objects.filter(email_bounced_date__gt=yesterday, first_name='sf_test' + uid)
         self.assertEqual(len(contacts1), 1)
         contacts2 = Contact.objects.filter(email_bounced_date__gt=tomorrow, first_name='sf_test' + uid)
         self.assertEqual(len(contacts2), 0)
     finally:
         contact.delete()
示例#16
0
    def test_date_comparison(self):
        """
		Test that date comparisons work properly.
		"""
        today = round_datetime_utc(datetime.datetime(2013, 8, 27))
        yesterday = today - datetime.timedelta(days=1)
        tomorrow = today + datetime.timedelta(days=1)
        contact = Contact(FirstName='sf_test',
                          LastName='date',
                          EmailBouncedDate=today)
        contact.save()
        try:
            contacts1 = Contact.objects.filter(EmailBouncedDate__gt=yesterday)
            self.assertEqual(len(contacts1), 1)
            contacts2 = Contact.objects.filter(EmailBouncedDate__gt=tomorrow)
            self.assertEqual(len(contacts2), 0)
        finally:
            contact.delete()
示例#17
0
 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()
 def test_multiple_sf_databases(self):
     """Test a connection to two sf sandboxes of the same organization.
     """
     other_db = [db for db in sf_databases if db != sf_alias][0]
     c1 = Contact(last_name='sf_test 1')
     c2 = Contact(last_name='sf_test 2')
     c1.save()
     c2.save(using=other_db)
     try:
         user1 = refresh(c1).owner
         user2 = refresh(c2).owner
         username1 = user1.Username
         username2 = user2.Username
         # Verify different usernames, like it is usual in sandboxes
         self.assertNotEqual(user1._state.db, user2._state.db)
         self.assertNotEqual(username1, username2)
         expected_user2 = connections[other_db].settings_dict['USER']
         self.assertEqual(username1, current_user)
         self.assertEqual(username2, expected_user2)
     finally:
         c1.delete()
         c2.delete()
示例#19
0
    def test_multiple_sf_databases(self):
        """Test a connection to two sf sandboxes of the same organization.
		"""
        other_db = [db for db in sf_databases if db != sf_alias][0]
        c1 = Contact(last_name='sf_test 1')
        c2 = Contact(last_name='sf_test 2')
        c1.save()
        c2.save(using=other_db)
        try:
            user1 = refresh(c1).owner
            user2 = refresh(c2).owner
            username1 = user1.Username
            username2 = user2.Username
            # Verify different usernames, like it is usual in sandboxes
            self.assertNotEqual(user1._state.db, user2._state.db)
            self.assertNotEqual(username1, username2)
            expected_user2 = connections[other_db].settings_dict['USER']
            self.assertEqual(username1, current_user)
            self.assertEqual(username2, expected_user2)
        finally:
            c1.delete()
            c2.delete()
    def test_generic_type_field(self):
        """Test that a generic foreign key can be filtered by type name and
        the type name can be referenced.
        """
        test_contact = Contact(first_name='sf_test', last_name='my')
        test_contact.save()
        note_1 = Note(title='note for Lead', parent_id=self.test_lead.pk)
        note_2 = Note(title='note for Contact', parent_id=test_contact.pk)
        note_1.save()
        note_2.save()
        try:
            self.assertEqual(Note.objects.filter(parent_type='Contact')[0].parent_type, 'Contact')
            self.assertEqual(Note.objects.filter(parent_type='Lead')[0].parent_type, 'Lead')

            note = Note.objects.filter(parent_type='Contact')[0]
            parent_model = getattr(salesforce.testrunner.example.models, note.parent_type)
            parent_object = parent_model.objects.get(pk=note.parent_id)
            self.assertEqual(parent_object.pk, note.parent_id)
        finally:
            note_1.delete()
            note_2.delete()
            test_contact.delete()
	def test_multiple_sf_databases(self):
		"""
		Test a connection to two sf databases with the same user.
		(with sandboxes of the same organization)
		"""
		other_db = [db for db in sf_databases if db != sf_alias][0]
		c1 = Contact(last_name='sf_test 1')
		c2 = Contact(last_name='sf_test 2')
		c1.save()
		c2.save(using=other_db)
		try:
			user1 = refresh(c1).owner
			user2 = refresh(c2).owner
			username1 = user1.Username
			username2 = user2.Username
			# Verify different, but similar usernames like usual in sandboxes
			self.assertNotEqual(user1._state.db, user2._state.db)
			self.assertNotEqual(username1, username2)
			self.assertEqual(username1.split('@')[0], username2.split('@')[0])
		finally:
			c1.delete()
			c2.delete()
    def test_multiple_sf_databases(self):
        """
		Test a connection to two sf databases with the same user.
		(with sandboxes of the same organization)
		"""
        other_db = [db for db in sf_databases if db != sf_alias][0]
        c1 = Contact(last_name='sf_test 1')
        c2 = Contact(last_name='sf_test 2')
        c1.save()
        c2.save(using=other_db)
        try:
            user1 = refresh(c1).owner
            user2 = refresh(c2).owner
            username1 = user1.Username
            username2 = user2.Username
            # Verify different, but similar usernames like usual in sandboxes
            self.assertNotEqual(user1._state.db, user2._state.db)
            self.assertNotEqual(username1, username2)
            self.assertEqual(username1.split('@')[0], username2.split('@')[0])
        finally:
            c1.delete()
            c2.delete()
	def test_default_specified_by_sf(self):
		"""
		Verify that an object with a field with default value specified by some
		Salesforce code can be inserted. (The default is used only for a field
		unspecified in SF REST API, but not for None or any similar value.
		It was a pain for some unimportant foreign keys that don't accept null.
		"""
		# Verify a smart default is used.
		contact = Contact(FirstName = 'sf_test', LastName='my')
		contact.save()
		try:
			self.assertEqual(refresh(contact).Owner.Username, current_user)
		finally:
			contact.delete()
		# Verify that an explicit value is possible for this field.
		other_user_obj = User.objects.exclude(Username=current_user)[0]
		contact = Contact(FirstName = 'sf_test', LastName='your',
				Owner=other_user_obj)
		contact.save()
		try:
			self.assertEqual(
					refresh(contact).Owner.Username, other_user_obj.Username)
		finally:
			contact.delete()