def test_too_long_excerpt(self): """ test that we shorten an excerpt that is too long appropriately """ test_string = ( u"Here is a note about الاستحسان and it is very long - more than the desirable length of 100" u" characters - indeed this should show up but it should trim the characters around in" u" order to show the selected text in bold") test_result = { "content": { "notes": test_string, } } srp = SearchResultProcessor(test_result, u"الاستحسان") test_string_compare = SearchResultProcessor.decorate_matches( test_string, u"الاستحسان") excerpt = srp.excerpt self.assertNotEqual(excerpt, test_string_compare) self.assertIn(u"note about <b>الاستحسان</b> and it is", excerpt) test_string = ( u"Here is a note about stuff and it is very long - more than the desirable length of 100" u" characters - indeed this should show up but it should trim the الاستحسان characters around in" u" order to show the selected text in bold") test_result = { "content": { "notes": test_string, } } srp = SearchResultProcessor(test_result, u"الاستحسان") test_string_compare = SearchResultProcessor.decorate_matches( test_string, u"الاستحسان") excerpt = srp.excerpt self.assertNotEqual(excerpt, test_string_compare) self.assertIn(u"should trim the <b>الاستحسان</b> characters around", excerpt)
def test_excerpt(self): """ test that we return an excerpt """ test_result = { "content": { "notes": u"Here is a الاستحسان about edx", "name": "edX search a lot", } } srp = SearchResultProcessor(test_result, u"الاستحسان") self.assertEqual(srp.excerpt, u"Here is a <b>الاستحسان</b> about edx") srp = SearchResultProcessor(test_result, u"edx") self.assertIn(u"Here is a الاستحسان about <b>edx</b>", srp.excerpt)
def test_excerpt_back(self): """ test that we process correctly when match is at the end of the excerpt """ test_result = { "content": { "notes": "Match upon last word - Dog", } } srp = SearchResultProcessor(test_result, "dog") self.assertEqual(srp.excerpt, "Match upon last word - <b>Dog</b>") test_result = { "content": { "notes": ("The long and winding road " "That leads to your door " "Will never disappear " "I've seen that road before " "It always leads me here " "Lead me to you door " "The wild and windy night " "That the rain washed away " "Has left a pool of tears " "Crying for the day " "Why leave me standing here " "Let me know the way " "Many times I've been alone " "And many times I've cried " "Any way you'll never know " "The many ways I've tried " "But still they lead me back " "To the long winding road " "You left me standing here " "A long long time ago " "Don't leave me waiting here " "Lead me to your door " "But still they lead me back " "To the long winding road " "You left me standing here " "A long long time ago " "Don't leave me waiting here " "Lead me to your door " "Yeah, yeah, yeah, yeah " "Match upon last word - Dog"), } } srp = SearchResultProcessor(test_result, "dog") self.assertEqual(srp.excerpt[-33:], "Match upon last word - <b>Dog</b>")
def test_excerpt_back(self): """ test that we process correctly when match is at the end of the excerpt """ test_result = { "content": { "notes": "Match upon last word - Dog", } } srp = SearchResultProcessor(test_result, "dog") self.assertEqual(srp.excerpt, "Match upon last word - <b>Dog</b>") test_result = { "content": { "notes": ("The long and winding road " "That leads to your door ..." "... Yeah, yeah, yeah, yeah " "Match upon last word - Dog"), } } srp = SearchResultProcessor(test_result, "dog") self.assertEqual(srp.excerpt[-33:], "Match upon last word - <b>Dog</b>")
def test_excerpt_front(self): """ test that we process correctly when match is at the front of the excerpt """ test_result = { "content": { "notes": "Dog - match upon first word", } } srp = SearchResultProcessor(test_result, "dog") self.assertEqual(srp.excerpt, "<b>Dog</b> - match upon first word") test_result = { "content": { "notes": ("Dog - match upon first word " "The long and winding road " "That leads to your door " "Will never disappear ..."), } } srp = SearchResultProcessor(test_result, "dog") self.assertEqual(srp.excerpt[0:34], "<b>Dog</b> - match upon first word")
def test_excerpt_quoted(self, search_phrase, expected_excerpt): test_result = { "content": { "notes": ("The long and winding road " "That leads to your door " "Will never disappear " "I've seen that road before " "It always leads me here " "यह एक हिंदी में लिखा हुआ वाक्य है| इसको search करें| " "Lead me to you door " "The wild and windy night " "That the rain washed away "), } } srp = SearchResultProcessor(test_result, search_phrase) self.assertIn(expected_excerpt, srp.excerpt)