def setUp(self): self.service = SortService() self.report = {'name': "TestReport", 'keywords': ['key', 'word']} self.thread = {'title': (self.report['keywords'][0]), 'msgs': []}.copy() self.keyword = self.report['keywords'][0]
class TestSortingService(unittest.TestCase): """ This test suite test the sorting in the report builder. Nor the sorting has moved to a comlete service """ def title(self, report, index): return report.entries_in('key')[index].title() def report_append(self, report_obj, enttry_json): report_obj.add_entry('key', BlogEntry(enttry_json)) def setUp(self): self.service = SortService() self.report = {'name': "TestReport", 'keywords': ['key', 'word']} self.thread = {'title': (self.report['keywords'][0]), 'msgs': []}.copy() self.keyword = self.report['keywords'][0] def test_sorts_threads_by_creation_date_and_hour(self): report = {'key': [ {'title':'b', 'msgs': [{'date': u' 21 de Noviembre de 2012, 10:18:38 am \xbb'}]}, {'title':'a', 'msgs': [{'date': u' 21 de Noviembre de 2012, 10:28:38 am \xbb'}]}]} report_obj = transtale_report_into_threads({'keywords':['key']}, report) self.service.sort_report(['key'], report_obj) self.assertEqual(self.title(report_obj, 0), "a") self.assertEqual(self.title(report_obj, 1), "b") def test_sorts_threads_by_second(self): report = {'key': [{'title': 'b', 'msgs': [{'date': u' 21 de Noviembre de 2012, 10:28:36 am \xbb'}]}, {'title': 'a', 'msgs': [{'date': u' 21 de Noviembre de 2012, 10:28:37 am \xbb'}]}]} report_obj = transtale_report_into_threads({'keywords':['key']}, report) self.service.sort_report(['key'], report_obj) self.assertGoesFirst(report_obj, "a") self.assertEqual(self.title(report_obj, 1), "b") def test_sorts_threads_by_creation_date_and_moth(self): report = {'key': [{'title': 'b', 'msgs': [{'date': u' 21 de Noviembre de 2012, 10:28:38 am \xbb'}]}, {'title': 'a', 'msgs': [{'date': u' 21 de Diciembre de 2012, 10:18:38 am \xbb'}]}]} report_obj = transtale_report_into_threads({'keywords':['key']}, report) self.service.sort_report(['key'], report_obj) self.assertGoesFirst(report_obj, "a") self.assertEqual(self.title(report_obj, 1), "b") def test_sorts_threads_by_creation_date_year(self): report = {'key': [{'title': 'b', 'msgs':[{'date':u' 21 de Diciembre de 2011, 10:28:38 am \xbb'}]}, {'title': 'a', 'msgs':[{'date':u' 21 de Noviembre de 2012, 10:18:38 am \xbb'}]}]} report_obj = transtale_report_into_threads({'keywords':['key']}, report) self.service.sort_report(['key'], report_obj) self.assertGoesFirst(report_obj, "a") self.assertEqual(self.title(report_obj, 1).title(), "B") def test_sorts_threads_by_creation_date_without_date(self): report = {'key': [ {'title':'b', 'msgs':[{'date':u' 21 de Diciembre de 2011, 10:28:38 am \xbb'}], 'link': "Test data"}, {'title':'a', 'msgs':[{'date':u' 21 de Noviembre de 2012, 10:18:38 am \xbb'}]}]} report_obj = transtale_report_into_threads({'keywords':['key']}, report) self.service.sort_report(['key'], report_obj) self.assertGoesFirst(report_obj, "a") self.assertEqual(self.title(report_obj, 1), "b") # Test con entradas de blog def test_sorts_threads_and_blog_entry_goes_first(self): report = {'key': [ {'title':'b', 'msgs':[{'date':u' 21 de Diciembre de 2011, 10:28:38 am \xbb'}], 'link': "Test data"}, {'title':'a', 'msgs':[{'date':u' 21 de Noviembre de 2012, 10:18:38 am \xbb'}]}]} report_obj = transtale_report_into_threads({'keywords':['key']}, report) self.report_append(report_obj, {'date':'23 Noviembre, 2012'}) self.service.sort_report(['key'], report_obj) self.assertEqual(self.title(report_obj, 1), "a") self.assertEqual(self.title(report_obj, 2), "b") def test_sorts_threads_and_blog_entry_goes_last(self): report = {'key': [ {'title':'b', 'msgs':[{'date':u' 21 de Diciembre de 2011, 10:28:38 am \xbb'}], 'link': "Test data"}, {'title':'a', 'msgs':[{'date':u' 21 de Noviembre de 2012, 10:18:38 am \xbb'}]}]} report_obj = transtale_report_into_threads({'keywords':['key']}, report) report_obj.add_entry('key', BlogEntry({'date':'23 Noviembre, 2010'})) self.service.sort_report(['key'], report_obj) self.assertGoesFirst(report_obj, "a") self.assertEqual(self.title(report_obj, 1), "b") def test_sorts_threads_and_blog_entry_goes_in_the_middle(self): report = {'key': [ {'title': 'b', 'msgs': [{'date': u' 21 de Diciembre de 2011, 10:28:38 am \xbb'}], 'link': "Test data"}, {'title':'a', 'msgs':[{'date':u' 21 de Noviembre de 2012, 10:18:38 am \xbb'}]}]} report_obj = transtale_report_into_threads({'keywords':['key']}, report) self.report_append(report_obj, {'date':'23 Enero, 2012'}) self.service.sort_report(['key'], report_obj) self.assertGoesFirst(report_obj, "a") self.assertEqual(self.title(report_obj, 2), "b") def assertGoesFirst(self, report, title): self.assertEqual(self.title(report, 0), title)