def test_template_content(self): template = 'snippets/search_list.html' letter = LetterFactory( date=ApproximateDate(1862, 1, 1), writer=CorrespondentFactory(first_names='Francis P.', last_name='Black'), recipient=CorrespondentFactory(first_names='Eveline', last_name='Johnston'), place=PlaceFactory(name='Manassas Junction', state='Virginia')) Sentiment = namedtuple('Sentiment', ['id', 'name']) sentiments = [Sentiment(id=123, name='Positive/negative')] search_results = [(letter, 'sentiment highlight', sentiments, 'sentiment score')] rendered = render_to_string(template, context={'search_results': search_results}) for heading in ['Date', 'Writer', 'Recipient', 'Place']: self.assertIn(heading, rendered, "Heading '{}' should appear in HTML".format(heading)) self.assertIn(letter.list_date(), rendered, 'Letter list_date() should appear in HTML') self.assertIn(str(letter.writer), rendered, 'Letter writer should appear in HTML') self.assertIn(str(letter.recipient), rendered, 'Letter recipient should appear in HTML') self.assertIn(str(letter.place), rendered, 'Letter place should appear in HTML') self.assertIn('123', rendered, 'Sentiment ID should appear in HTML') self.assertIn('Positive/negative', rendered, 'Sentiment name should appear in HTML') self.assertIn('sentiment highlight', rendered, 'Sentiment highlight should appear in HTML') self.assertIn('sentiment score', rendered, 'Sentiment score should appear in HTML')
def test_delete(self, mock_delete_from_elasticsearch): """ Letter.delete() should call delete_from_elasticsearch(letter.pk) """ letter = Letter(pk=1, writer=CorrespondentFactory(), recipient=CorrespondentFactory()) letter_pk = letter.pk letter.delete() args, kwargs = mock_delete_from_elasticsearch.call_args self.assertEqual(args[1], letter_pk, 'Letter.delete() should call delete_from_elasticsearch(letter.pk)')
def setUp(self): self.request = RequestFactory().get('/') self.request.user = AnonymousUser() self.modeladmin = LetterAdmin(Letter, site) self.letter_writer1 = CorrespondentFactory() self.letter1 = LetterFactory(writer=self.letter_writer1) self.letter_writer2 = CorrespondentFactory() self.letter2 = LetterFactory(writer=self.letter_writer2) EnvelopeFactory(writer=CorrespondentFactory())
def test_queryset(self, mock_get_correspondents_of_source): """ queryset() should return all Correspondents associated with a particular DocumentSource by finding out which Correspondents were writers or recipients of Letters, Envelopes, and MiscDocuments with this DocumentSource """ misc_doc_and_letter_source = DocumentSourceFactory() misc_doc_writer = CorrespondentFactory() MiscDocumentFactory(writer=misc_doc_writer, source=misc_doc_and_letter_source) letter_writer = CorrespondentFactory() letter_recipient = CorrespondentFactory() LetterFactory(writer=letter_writer, recipient=letter_recipient, source=misc_doc_and_letter_source) envelope_source = DocumentSourceFactory() envelope_writer = CorrespondentFactory() envelope_recipient = CorrespondentFactory() EnvelopeFactory(writer=envelope_writer, recipient=envelope_recipient, source=envelope_source) parameter = 'source' # When no DocumentSource specified, all Correspondents should be returned filter = CorrespondentSourceFilter(self.request, params={}, model=DocumentSource, model_admin=self.modeladmin) queryset = filter.queryset(self.request, Correspondent.objects.all()) self.assertEqual(mock_get_correspondents_of_source.call_count, 0, "get_correspondents_of_source() shouldn't be called if no DocumentSource specified") self.assertSetEqual(set(queryset), set(Correspondent.objects.all()), 'CorrespondentSourceFilter.queryset() should return all Corresponents if no DocumentSource specified') # When DocumentSource is misc_doc_and_letter_source, misc_doc_writer, letter_writer, # and letter_recipient should be returned mock_get_correspondents_of_source.return_value = set([misc_doc_writer.id, letter_writer.id, letter_recipient.id]) filter = CorrespondentSourceFilter(self.request, params={parameter: misc_doc_and_letter_source.id}, model=DocumentSource, model_admin=self.modeladmin) queryset = filter.queryset(self.request, Correspondent.objects.all()) self.assertEqual(mock_get_correspondents_of_source.call_count, 1, 'get_correspondents_of_source() should be called if DocumentSource specified') mock_get_correspondents_of_source.reset_mock() self.assertSetEqual(set(queryset), set([misc_doc_writer, letter_writer, letter_recipient]), 'CorrespondentSourceFilter.queryset() should return Corresponents for DocumentSource') # When DocumentSource is envelope_source, envelope_writer and envelope_recipient should be returned mock_get_correspondents_of_source.return_value = set([envelope_writer.id, envelope_recipient.id]) filter = CorrespondentSourceFilter(self.request, params={parameter: envelope_source.id}, model=DocumentSource, model_admin=self.modeladmin) queryset = filter.queryset(self.request, Correspondent.objects.all()) self.assertEqual(mock_get_correspondents_of_source.call_count, 1, 'get_correspondents_of_source() should be called if DocumentSource specified') mock_get_correspondents_of_source.reset_mock() self.assertSetEqual(set(queryset), set([envelope_writer, envelope_recipient]), 'CorrespondentSourceFilter.queryset() should return Corresponents for DocumentSource')
def test_get_initial_filter_values(self, mock_get_sentiment_list): mock_get_sentiment_list.return_value = ['Hipster', 'OMG Ponies!!!'] # If there are no letters, start_date and end_date should be empty strings with patch.object(Letter, 'index_date', autospec=True, return_value=''): result = get_initial_filter_values() self.assertEqual( result['start_date'], '', 'If there are no letters, start_date should be empty string') self.assertEqual( result['end_date'], '', 'Ifthere are no letters, end_date should be empty string') mock_get_sentiment_list.reset_mock() doc_source1 = DocumentSourceFactory(name='Document source 1') doc_source2 = DocumentSourceFactory(name='Document source 2') correspondent1 = CorrespondentFactory() correspondent2 = CorrespondentFactory() LetterFactory(source=doc_source1, writer=correspondent1, date='1857-6-15') LetterFactory(source=doc_source2, writer=correspondent2, date='1863-1-1') result = get_initial_filter_values() self.assertEqual( mock_get_sentiment_list.call_count, 1, 'get_initial_filter_values() should call get_sentiment_list()') # If the letters are dated, start_date and end_date should be filled self.assertEqual(result['start_date'], '1857-06-15', 'If letters are dated, start_date should be filled') self.assertEqual(result['end_date'], '1863-01-01', 'If letters are dated, end_date should be filled') self.assertEqual( result['sources'], [doc_source1, doc_source2], 'get_initial_filter_values() should return list of letter sources') self.assertEqual( result['writers'], sorted([correspondent1, correspondent2]), 'get_initial_filter_values() should return list of letter writers') self.assertEqual( result['words'], DEFAULT_STATS_SEARCH_WORDS, 'get_initial_filter_values() should return default stats search words' ) self.assertEqual( result['sentiments'], mock_get_sentiment_list.return_value, 'get_initial_filter_values() should return list of sentiments')
class WriterFilterTestCase(TestCase): """ Test WriterFilter """ def setUp(self): self.request = RequestFactory().get('/') self.request.user = AnonymousUser() self.modeladmin = LetterAdmin(Letter, site) self.letter_writer1 = CorrespondentFactory() self.letter1 = LetterFactory(writer=self.letter_writer1) self.letter_writer2 = CorrespondentFactory() self.letter2 = LetterFactory(writer=self.letter_writer2) EnvelopeFactory(writer=CorrespondentFactory()) def test_lookups(self): """ lookups() should be a list of (writer.id, writer.to_string()) for known writers of the admin document type """ filter = WriterFilter(self.request, params={}, model=Letter, model_admin=self.modeladmin) expected = [(self.letter_writer1.id, self.letter_writer1.to_string()), (self.letter_writer2.id, self.letter_writer2.to_string())] self.assertEqual(sorted(filter.lookup_choices), sorted(expected)) def test_queryset(self): """ queryset() should return all the Letters with the given writer, if specified Otherwise it should return all the Letters """ parameter = 'writer' # When no writer specified, all Letters should be returned filter = WriterFilter(self.request, params={}, model=Letter, model_admin=self.modeladmin) queryset = filter.queryset(self.request, Letter.objects.all()) self.assertSetEqual(set(queryset), set(Letter.objects.all()), 'WriterFilter.queryset() should return all objects if no writer specified') # When writer specified, only Letters with that writer should be returned filter = WriterFilter(self.request, params={parameter: self.letter_writer1.id}, model=Letter, model_admin=self.modeladmin) queryset = filter.queryset(self.request, Letter.objects.all()) self.assertSetEqual(set(queryset), set([self.letter1]), 'WriterFilter.queryset() should return letters with the specified writer')
def test_save(self, mock_create_or_update_in_elasticsearch): """ Letter.save() should call Letter.create_or_update_in_elasticsearch() """ letter = Letter(writer=CorrespondentFactory(), recipient=CorrespondentFactory(), source=DocumentSourceFactory(), place=PlaceFactory()) letter.save() args, kwargs = mock_create_or_update_in_elasticsearch.call_args self.assertIsNone(kwargs['is_new'], 'Letter.save() should call create_or_update_in_elasticsearch(None) on Letter creation') letter.save() args, kwargs = mock_create_or_update_in_elasticsearch.call_args self.assertIsNotNone(kwargs['is_new'], 'Letter.save() should call create_or_update_in_elasticsearch(None) on Letter update')
def create_test_letter(): letter = LetterFactory( date=ApproximateDate(1862, 1, 1), writer=CorrespondentFactory(first_names='Francis P.', last_name='Black'), recipient=CorrespondentFactory(first_names='Eveline', last_name='Johnston'), heading='Januery the 1st / 62', greeting='Miss Evey', body= 'As this is the beginin of a new year I thought as I was a lone to night I would write you ' 'a few lines to let you know that we are not all ded yet.', closing='your friend as every', signature='F.P. Black', ps='p.s. remember me to all') return letter
def test_get_display_string(self, mock_list_date): """ Letter.get_display_string() should return formatted string containing lost_date, writer, and recipient """ mock_list_date.return_value = 'list date' writer = CorrespondentFactory() recipient = CorrespondentFactory() letter = LetterFactory(writer=writer, recipient=recipient) display_string = letter.get_display_string() self.assertIn(str(writer), display_string, 'Letter.get_display_string() should return string containing writer') self.assertIn(str(recipient), display_string, 'Letter.get_display_string() should return string containing recipient') self.assertIn(mock_list_date.return_value, display_string, 'Letter.get_display_string() should return string containing list_date')
def test__lt__(self): """ Letter.__lt__() should return True if self.to_string() comes before other letter.to_string() in alphabetic sorting, otherwise it should return False """ # Letters should be ordered by display string: list_date, writer, recipient writer = CorrespondentFactory() recipient = CorrespondentFactory() letter_from_1862 = LetterFactory(date=ApproximateDate(1862), writer=writer, recipient=recipient) letter_from_1861 = LetterFactory(date=ApproximateDate(1861), writer=writer, recipient=recipient) other_letter_from_1861 = LetterFactory(date=ApproximateDate(1861), writer=writer, recipient=recipient) self.assertTrue(letter_from_1861 < letter_from_1862, '{} should be < {}'.format(letter_from_1861, letter_from_1862)) self.assertFalse(letter_from_1861 < other_letter_from_1861, "{} shouldn't be be < {}".format(letter_from_1861, other_letter_from_1861)) self.assertFalse(letter_from_1862 < letter_from_1861, "{} shouldn't be be < {}".format(letter_from_1862, letter_from_1861))
def test__str__(self, mock_get_display_string): """ Correspondent.__str__() should return Correspondent.get_display_string() """ mock_get_display_string.return_value = 'correspondent str' self.assertEqual( str(CorrespondentFactory()), mock_get_display_string.return_value, 'Correspondent.__str__() should return value of Correspondent.get_display_string()' )
def test_get_display_string(self): """ Envelope.get_display_string() should return description if filled Otherwise it should return formatted string containing writer, recipient, and date if filled """ # If description filled, get_display_string() should return description envelope = EnvelopeFactory( description='Pink envelope that says URGENT! OPEN IMMEDIATELY!') self.assertEqual( envelope.get_display_string(), envelope.description, 'If Envelope.description filled, get_display_string() should return description' ) # If description not filled, get_display_string() should return string containing # writer, recipient, and date if filled # writer and recipient are required fields writer = CorrespondentFactory() recipient = CorrespondentFactory() envelope = EnvelopeFactory(writer=writer, recipient=recipient) display_string = envelope.get_display_string() self.assertIn( str(writer), display_string, 'Correspondent.get_display_string() should return string containing writer' ) self.assertIn( str(recipient), display_string, 'Correspondent.get_display_string() should return string containing recipient' ) # If date filled, Envelope.get_display_string() should return string containing date envelope = EnvelopeFactory(writer=writer, recipient=recipient, date=ApproximateDate(1863, 7, 1)) display_string = envelope.get_display_string() self.assertIn( str(envelope.date), display_string, 'Correspondent.get_display_string() should return string containing date if date filled' )
def test_image_preview(self, mock_get_image_preview): """ Correspondent.image_preview() should return Correspondent.get_image_preview() """ mock_get_image_preview.return_value = 'image_preview' self.assertEqual( CorrespondentFactory().image_preview(), mock_get_image_preview.return_value, 'Correspondent.image_preview() should return value of Correspondent.get_image_preview()' )
def test_get_correspondents_of_source(self): misc_doc_and_letter_source = DocumentSourceFactory() misc_doc_writer = CorrespondentFactory() MiscDocumentFactory(writer=misc_doc_writer, source=misc_doc_and_letter_source) letter_writer = CorrespondentFactory() letter_recipient = CorrespondentFactory() LetterFactory(writer=letter_writer, recipient=letter_recipient, source=misc_doc_and_letter_source) envelope_source = DocumentSourceFactory() envelope_writer = CorrespondentFactory() envelope_recipient = CorrespondentFactory() EnvelopeFactory(writer=envelope_writer, recipient=envelope_recipient, source=envelope_source) # Correspondent not associated with either DocumentSource CorrespondentFactory() # When DocumentSource is misc_doc_and_letter_source, ids for misc_doc_writer, letter_writer, # and letter_recipient should be returned self.assertSetEqual(set(get_correspondents_of_source(misc_doc_and_letter_source.id)), set([misc_doc_writer.id, letter_writer.id, letter_recipient.id]), 'get_correspondents_of_source() should return unique set of ids of Corresponents for DocumentSource') # When DocumentSource is envelope_source, ids for envelope_writer and envelope_recipient # should be returned self.assertSetEqual(set(get_correspondents_of_source(envelope_source.id)), set([envelope_writer.id, envelope_recipient.id]), 'get_correspondents_of_source() should return unique set of ids of Corresponents for DocumentSource')
def test__lt__(self): """ Correspondent.__lt__() should return True if self.to_string() comes before other correspondent.to_string() in alphabetic sorting, otherwise it should return False """ kate_derenberger = CorrespondentFactory(last_name='Derenberger', first_names='Kate') francis_black = CorrespondentFactory(last_name='Black', first_names='Francis P.') other_francis_black = CorrespondentFactory(last_name='Black', first_names='Francis P.') self.assertTrue( francis_black < kate_derenberger, '{} should be < {}'.format(francis_black, kate_derenberger)) self.assertFalse( francis_black < other_francis_black, "{} shouldn't be be < {}".format(francis_black, other_francis_black)) self.assertFalse( kate_derenberger < francis_black, "{} shouldn't be be < {}".format(kate_derenberger, francis_black))
def setUp(self): self.source = DocumentSourceFactory() self.writer = CorrespondentFactory() self.test_document = self.model.objects.create(source=self.source, writer=self.writer)
def test_template_content(self): template = 'snippets/filter.html' source = DocumentSourceFactory( id=123, name='Letters I found in a mysterious locked drawer') writer = CorrespondentFactory() initial_filter_values = get_initial_filter_values() initial_filter_values['sources'] = [source] initial_filter_values['writers'] = [writer] rendered = render_to_string( template, context={'filter_values': initial_filter_values}) # Sources should be in HTML self.assertIn('Sources', rendered, "'Sources' should be in HTML") self.assertIn(str(source.id), rendered, "Source ID from filter should be in HTML") self.assertIn(str(source), rendered, "Source from filter should be in HTML") # Writers should be in HTML self.assertIn('Writers', rendered, "'Writers' should be in HTML") self.assertIn(str(writer.id), rendered, "Writer ID from filter should be in HTML") self.assertIn(str(writer), rendered, "Writer from filter should be in HTML") # Start date should be in HTML self.assertIn('Start date', rendered, "'Start date' should be in HTML") self.assertIn(initial_filter_values.get('start_date'), rendered, "Start date from filter should be in HTML") # End date should be in HTML self.assertIn('End date', rendered, "'End date' should be in HTML") self.assertIn(initial_filter_values.get('end_date'), rendered, "End date from filter should be in HTML") # If show_search_text is True, then 'Search text' should be in HTML and words shouldn't be rendered = render_to_string(template, context={ 'filter_values': initial_filter_values, 'show_search_text': True }) self.assertIn( 'Search text', rendered, "If show_search_text in context, then 'Search text' should be in HTML" ) for word in initial_filter_values.get('words'): self.assertNotIn( word, rendered, "If show_search_text in context, then words shouldn't be shown" ) # If show_words is True, then words should be in HTML and 'Search text' shouldn't be rendered = render_to_string(template, context={ 'filter_values': initial_filter_values, 'show_words': True }) self.assertNotIn( 'Search text', rendered, "If show_words in context, then 'Search text' shouldn't be in HTML" ) for word in initial_filter_values.get('words'): self.assertIn( word, rendered, "If show_words in context, then words should be shown") # If show_sentiment in context, sentiment_dropdown.html should be include # Just spot-check here rendered = render_to_string(template, context={ 'filter_values': initial_filter_values, 'show_sentiment': True }) self.assertIn( 'Sentiments', rendered, "If show_sentiment in context, then 'Sentiments' should be in HTML" ) rendered = render_to_string( template, context={'filter_values': initial_filter_values}) self.assertNotIn( 'Sentiments', rendered, "If show_sentiment not in context, then 'Sentiments' shouldn't be in HTML" ) # If sort_by in context, sort_by_dropdown.html should be include # Just spot-check here rendered = render_to_string(template, context={ 'filter_values': initial_filter_values, 'sort_by': [('DATE', 'Date')] }) self.assertIn( 'Sort by', rendered, "If sort_by in context, then 'Sort by' should be in HTML") rendered = render_to_string( template, context={'filter_values': initial_filter_values}) self.assertNotIn( 'Sort by', rendered, "If sort_by not in context, then 'Sort by' shouldn't be in HTML") # If show_export_button in context, export_text and export_csv buttons should be in HTML rendered = render_to_string(template, context={ 'filter_values': initial_filter_values, 'show_export_button': True }) self.assertIn( 'export_text', rendered, "If show_export_button in context, then 'export_text' button should be in HTML" ) self.assertIn( 'export_csv', rendered, "If show_export_button in context, then 'export_csv' button should be in HTML" ) rendered = render_to_string( template, context={'filter_values': initial_filter_values}) self.assertNotIn( 'export_text', rendered, "If show_export_button not in context, then 'export_text' button shouldn't be in HTML" ) self.assertNotIn( 'export_csv', rendered, "If show_export_button not in context, then 'export_csv' button shouldn't be in HTML" )
def test_to_export_string(self): """ Correspondent.to_export_string() should include last_name, and first_names and suffix, if they're filled """ last_name = 'Waite' first_names = 'Elizabeth A.' married_name = 'Howard' suffix = 'Suffix' correspondent = CorrespondentFactory(last_name=last_name, first_names='') self.assertIn( correspondent.last_name, correspondent.to_export_string(), 'Correspondent.to_export_string() should include last_name if filled' ) correspondent = CorrespondentFactory(last_name=last_name, first_names=first_names) self.assertIn( correspondent.first_names, correspondent.to_export_string(), 'Correspondent.to_export_string() should include first_names if filled' ) correspondent = CorrespondentFactory(last_name=last_name, first_names=first_names, married_name=married_name) self.assertNotIn( correspondent.married_name, correspondent.to_export_string(), "Correspondent.to_export_string() shouldn't include married_name if filled" ) correspondent = CorrespondentFactory(last_name=last_name, first_names=first_names, married_name=married_name, suffix=suffix) self.assertIn( correspondent.suffix, correspondent.to_export_string(), 'Correspondent.to_export_string() should include suffix if filled' ) # def to_export_string(self):
def test_queryset(self, mock_get_correspondents_of_source): """ queryset() should return all DocumentImages associated with a particular DocumentSource by finding out which DocumentImages were images of Letters, Envelopes, and MiscDocuments with this DocumentSource """ letter_source = DocumentSourceFactory() letter_writer = CorrespondentFactory() letter_recipient = CorrespondentFactory() letter = LetterFactory(writer=letter_writer, recipient=letter_recipient, source=letter_source) letter_image = DocumentImageFactory() letter.images.add(letter_image) envelope_source = DocumentSourceFactory() envelope_writer = CorrespondentFactory() envelope_recipient = CorrespondentFactory() envelope = EnvelopeFactory(writer=envelope_writer, recipient=envelope_recipient, source=envelope_source) envelope_image = DocumentImageFactory() envelope.images.add(envelope_image) correspondent_with_image_source = DocumentSourceFactory() correspondent_with_image = CorrespondentFactory() LetterFactory(writer=correspondent_with_image, source=correspondent_with_image_source) correspondent_image = DocumentImageFactory() correspondent_with_image.images.add(correspondent_image) parameter = 'source' # When no DocumentSource specified, all DocumentImages should be returned filter = ImageSourceFilter(self.request, params={}, model=DocumentImage, model_admin=self.modeladmin) queryset = filter.queryset(self.request, DocumentImage.objects.all()) self.assertEqual(mock_get_correspondents_of_source.call_count, 0, "get_correspondents_of_source() shouldn't be called if no DocumentSource specified") self.assertSetEqual(set(queryset), set(DocumentImage.objects.all()), 'ImageSourceFilter.queryset() should return all DocumentImages if no DocumentSource specified') # When DocumentSource is letter_source, letter_image should be returned mock_get_correspondents_of_source.return_value = set([letter_writer.id, letter_recipient.id]) filter = ImageSourceFilter(self.request, params={parameter: letter_source.id}, model=DocumentImage, model_admin=self.modeladmin) queryset = filter.queryset(self.request, DocumentImage.objects.all()) self.assertEqual(mock_get_correspondents_of_source.call_count, 1, 'get_correspondents_of_source() should be called if DocumentSource specified') mock_get_correspondents_of_source.reset_mock() self.assertSetEqual(set(queryset), set([letter_image]), 'ImageSourceFilter.queryset() should return DocumentImages for DocumentSource') # When DocumentSource is envelope_source, envelope_image should be returned mock_get_correspondents_of_source.return_value = set([envelope_writer.id, envelope_recipient.id]) filter = ImageSourceFilter(self.request, params={parameter: envelope_source.id}, model=DocumentImage, model_admin=self.modeladmin) queryset = filter.queryset(self.request, DocumentImage.objects.all()) self.assertEqual(mock_get_correspondents_of_source.call_count, 1, 'get_correspondents_of_source() should be called if DocumentSource specified') mock_get_correspondents_of_source.reset_mock() self.assertSetEqual(set(queryset), set([envelope_image]), 'ImageSourceFilter.queryset() should return DocumentImages for DocumentSource') # When DocumentSource is correspondent_with_image_source, correspondent_image should be returned mock_get_correspondents_of_source.return_value = set([correspondent_with_image.id]) filter = ImageSourceFilter(self.request, params={parameter: correspondent_with_image.id}, model=DocumentImage, model_admin=self.modeladmin) queryset = filter.queryset(self.request, DocumentImage.objects.all()) self.assertEqual(mock_get_correspondents_of_source.call_count, 1, 'get_correspondents_of_source() should be called if DocumentSource specified') mock_get_correspondents_of_source.reset_mock() self.assertSetEqual(set(queryset), set([correspondent_image]), 'ImageSourceFilter.queryset() should return DocumentImages for DocumentSource')
def test_get_display_string(self): """ Correspondent.get_display_string() should return string that contains the following, if they're filled: last_name, first_names, married_name, suffix """ last_name = 'Waite' first_names = 'Elizabeth A.' married_name = 'Howard' suffix = 'Suffix' correspondent = CorrespondentFactory(last_name=last_name, first_names='') self.assertIn( correspondent.last_name, correspondent.get_display_string(), 'Correspondent.get_display_string() should include last_name if filled' ) correspondent = CorrespondentFactory(last_name=last_name, first_names=first_names) self.assertIn( correspondent.first_names, correspondent.get_display_string(), 'Correspondent.get_display_string() should include first_names if filled' ) correspondent = CorrespondentFactory(last_name=last_name, first_names=first_names, married_name=married_name) self.assertIn( correspondent.married_name, correspondent.get_display_string(), 'Correspondent.get_display_string() should include married_name if filled' ) correspondent = CorrespondentFactory(last_name=last_name, first_names=first_names, married_name=married_name, suffix=suffix) self.assertIn( correspondent.suffix, correspondent.get_display_string(), 'Correspondent.get_display_string() should include suffix if filled' )