class TestLaBSKReport(unittest.TestCase): def setUp(self): # self.report = ReportModel({'Asylum Games':[], 'Banjooli':[], 'Mutinies':[], 'Polis':[]}) self.report = ReportEntriesModel() self.stats = ReportStats() def test_all_objects_from_report_are_from_class_(self): rb = mock() when(rb).build_report(Reports.asylum_report_request).thenReturn(Reports.asylum) l_report = LaBSKReportBuilder(rb) l_report.build_report(Reports.asylum_report_request, self.report, self.stats) # print report self.assertGreater(self.report.count_entries_in("Polis"), 0) for object in self.report.entries_in("Polis"): self.assertIsInstance(object, ThreadModel) def test_inc_stats_right(self): rb = mock() when(rb).build_report(Reports.asylum_report_request).thenReturn(Reports.asylum) l_report = LaBSKReportBuilder(rb) self.stats.inc_threads() self.stats.inc_msgs(2) l_report.build_report(Reports.asylum_report_request, self.report, self.stats) # print report.json()['Polis'] thread = ThreadModel(Reports.asylum["Polis"][0]) self.assertEqual(5, thread.msg_count()) thread = ThreadModel(Reports.asylum["Asylum Games"][0]) self.assertEqual(1, thread.msg_count()) thread = ThreadModel(Reports.asylum["Banjooli"][0]) self.assertEqual(1, thread.msg_count()) self.assertEquals(10, self.stats._msgs) self.assertEquals(self.stats._threads, 5)
def _generateStats(self, report_request, report_json): result = ReportStats() report_obj = ReportModel(report_json) for key in report_request['keywords']: for thread_obj in report_obj.threads_in(key): result.inc_threads() result.inc_msgs( thread_obj.msg_count() ) return result
def build_report(self, report_request, report_obj, stats): """ This mehtods search for ocurrences of the key words y reporr reest in the information from PlanetaLudico blogs and tores them in report updatind stats object """ report_result = self._report_builder.build_report(report_request) new_stats = ReportStats() for keyword in report_request['keywords']: #print report_result[keyword] for entry in report_result[keyword]: report_obj.add_entry(keyword, BlogEntry(entry)) new_stats.inc_blogs(len(report_result[keyword])) # Merge stats stats.merge(new_stats)
def test_reports_for_hootboardgame(self): stats = ReportStats() stats.inc_msgs() self.assertEqual(stats.json(), {'threads': '0', 'msgs': '1', 'blogs': '0'}) stats.inc_threads() stats.inc_threads() self.assertEqual(stats.json(), {'threads': '2', 'msgs': '1', 'blogs': '0'})
def build_report(self, report_request, report_obj, stats): """ Should return a set of thread objects. Este codigo tiene pinta de estar muy, muy mal. """ #report_obj = ReportModel(report) report_result = self._report_builder.build_report(report_request) new_stats = ReportStats() for keyword in report_request['keywords']: for entry_json in report_result[keyword]: report_obj.add_entry(keyword, ThreadModel(entry_json)) result = ReportStats() for key in report_request['keywords']: for thread_obj in report_obj.entries_in(key): result.inc_threads() result.inc_msgs( thread_obj.msg_count() ) stats.merge(result)
def test_merge_stats_no_empty(self): stats_acum = ReportStats() stats_acum.inc_threads() stats_acum.inc_msgs(3) stats_acum.inc_blogs(3) stats = ReportStats() stats.inc_threads() stats.inc_msgs(2) stats.inc_blogs(4) stats_acum.merge(stats) self.assertEqual(str(stats_acum), "2, 5, 7") self.assertEqual(str(stats), "1, 2, 4")
def test_merge_stats_both_empty(self): stats_acum = ReportStats() stats = ReportStats() stats_acum.merge(stats) self.assertEqual(str(stats_acum), "0, 0, 0") self.assertEqual(str(stats), "0, 0, 0")
def test_blog_increment(self): stats = ReportStats() stats.inc_blogs() self.assertEqual(stats.json(), {'threads': '0', 'msgs': '0', 'blogs': '1'}) stats.inc_blogs(2) self.assertEqual(stats.json(), {'threads': '0', 'msgs': '0', 'blogs': '3'})
def test_json(self): stats = ReportStats() result = stats.json() self.assertEqual(result, {'threads':'0', 'msgs':'0', 'blogs':'0'})
def create_report_stat(self): report_stats = ReportStats() report_stats.inc_msgs() report_stats.inc_threads() return report_stats
def setUp(self): # self.report = ReportModel({'Asylum Games':[], 'Banjooli':[], 'Mutinies':[], 'Polis':[]}) self.report = ReportEntriesModel() self.stats = ReportStats()