예제 #1
0
class TestReportService(unittest.TestCase):

    def create_report_stat(self):
        report_stats = ReportStats()
        report_stats.inc_msgs()
        report_stats.inc_threads()
        return report_stats

    def setUp(self):
        self.col = mock()
        self.mongo = mock()
        when(self.mongo).report_stats_collection().thenReturn(self.col)
        self.service = ReportService(self.mongo)
        self.service._builder = mock()
        self.service._now = MockDatetime()
        self.empty_report_request = {'name':'report', 'keywords':[]}
        self.expected_stats_report = {'name':'report', 'stats':[
            {'date':'2014-1-1', 'threads':'1', 'msgs':'1', 'blogs':'0'}]}

    def test_when_creates_a_service_it_includes_the_report_builder(self):
        self.service = ReportService(self.mongo)
        self.assertIsInstance(self.service._builder, ReportBuilder)

    def test_when_generating_a_report_report_builder_is_called(self):
        self.service.build_report(self.empty_report_request)
        verify(self.service._builder, 1).build_report(self.empty_report_request)

    def test_when_building_repot_a_report_and_stats_are_returned(self):
        result = self.service.build_report(self.empty_report_request)
        self.assertIsInstance(result, ReportResult)

    def test_building_a_report_stats_are_saved(self):
        when(self.col).find_one('name', 'report').thenReturn(None)
        self.service.build_report(self.empty_report_request)
        verify(self.col).save(any())
예제 #2
0
class TestGenerateReports(unittest.TestCase):
    def setUp(self):
        self.report = ReportService(MongoDB(col="labsk_merge"))
        self.presenter = ReportPresenter()
        self.presenter.set_builder(self.report)

    def test_find_zacatrus_thread_in_report(self):
        result = self.report.build_report(PreGeneratedReports.tienda_zacatrus)
        found = False
        # print "X"
        for thread in result.report["zacatrus"]:
            if thread["link"] == "http://labsk.net/index.php?topic=129533.0":
                found = True
                break
        self.assertTrue(found)

    def test_find_zacatrus_with_presenter(self):
        result = self.presenter.report_and_stats(PreGeneratedReports.tienda_zacatrus)
        found = False
        # print "X"
        for thread in result.report["zacatrus"]:
            if thread["link"] == "http://labsk.net/index.php?topic=129533.0":
                found = True
                break
        self.assertTrue(found)

    def test_find_finplay_thread_in_report(self):
        result = self.report.build_report(PreGeneratedReports.tienda_finplay)
        found = False
        # print "X"
        for thread in result.report["finplay"]:
            if thread["link"] == "http://labsk.net/index.php?topic=121033.0":
                found = True
                break
        self.assertTrue(found)

    def test_find_finplay_with_presenter(self):
        result = self.presenter.report_and_stats(PreGeneratedReports.tienda_finplay)
        found = False
        # print "X"
        for thread in result.report["finplay"]:
            if thread["link"] == "http://labsk.net/index.php?topic=121033.0":
                found = True
                break
        self.assertTrue(found)

    def test_find_finplay_with_presenter_filtering_2013(self):
        result = self.presenter.report_and_stats(PreGeneratedReports.tienda_finplay, filter_year="2013")
        found = False
        # print "X"
        for thread in result.report["finplay"]:
            if thread["link"] == "http://labsk.net/index.php?topic=121033.0":
                found = True
                break
        self.assertTrue(found)

    """
예제 #3
0
 def setUp(self):
     self.col = mock()
     self.mongo = mock()
     when(self.mongo).report_stats_collection().thenReturn(self.col)
     self.service = ReportService(self.mongo)
     self.service._builder = mock()
     self.service._now = MockDatetime()
     self.empty_report_request = {'name':'report', 'keywords':[]}
     self.expected_stats_report = {'name':'report', 'stats':[
         {'date':'2014-1-1', 'threads':'1', 'msgs':'1', 'blogs':'0'}]}
예제 #4
0
 def setUp(self):
     self.report = ReportService(MongoDB(col="labsk_merge"))
     self.presenter = ReportPresenter()
     self.presenter.set_builder(self.report)
예제 #5
0
 def test_when_creates_a_service_it_includes_the_report_builder(self):
     self.service = ReportService(self.mongo)
     self.assertIsInstance(self.service._builder, ReportBuilder)