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_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()