示例#1
0
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)
示例#2
0
    def setUp(self):
        self.report = ReportEntriesModel()
        self.stats = ReportStats()
        self.plr = PlanetaLudicoReport()
        self.madeira_request = {'name': 'Planeta Ludico demo',
                                'keywords': ["madeira"]}
        self.rb = mock()
        when(self.rb).build_report(self.madeira_request).thenReturn(TestPlanetaLudicoReport.madeira_report)

        self.plr._report_builder = self.rb
示例#3
0
class TestPlanetaLudicoReport(unittest.TestCase):

    madeira_report = MockKimonoPlanetaLudicoAPI.report_json

    def setUp(self):
        self.report = ReportEntriesModel()
        self.stats = ReportStats()
        self.plr = PlanetaLudicoReport()
        self.madeira_request = {'name': 'Planeta Ludico demo',
                                'keywords': ["madeira"]}
        self.rb = mock()
        when(self.rb).build_report(self.madeira_request).thenReturn(TestPlanetaLudicoReport.madeira_report)

        self.plr._report_builder = self.rb

    def test_when_no_entries_report_and_stats_remains_unmodified(self):
        when(self.rb).build_report(self.madeira_request).thenReturn({'madeira': []})

        self.plr.build_report(self.madeira_request, self.report, self.stats)
        self.assertEqual(self.report.size(), 0)
        self.assertEqual(str(self.stats), "0, 0, 0")

    def test_when_two_entries_are_found_return_entries(self):
        self.plr.build_report(self.madeira_request, self.report, self.stats)
        self.assertEqual(self.report.count_entries_in('madeira'), 2)

    def test_when_two_entries_are_found_blog_stats_are_incremented(self):
        self.plr.build_report(self.madeira_request, self.report, self.stats)
        self.assertEqual(str(self.stats), "0, 0, 2")

    def test_all_objects_from_report_are_from_class_(self):
        self.plr.build_report(self.madeira_request, self.report, self.stats)
        for object in self.report.entries_in('madeira'):
            self.assertIsInstance(object, BlogEntry)

    def test_creation_date(self):
        self.plr.build_report(self.madeira_request, self.report, self.stats)
        json = self.report.entries_in('madeira')[0].json()
        date = json['creation_date']
        print json
        self.assertEqual(date, "2 abril, 2014")
示例#4
0
文件: reports.py 项目: javierj/LaPISK
    def _create_empty_report(self, report_request):
        report = ReportEntriesModel()
        if 'name' in report_request:
            report.set_title("Result for report " + report_request['name'])
        else:
            report.set_title("Result for report.")

        now = datetime.now()
        report.set_report_date( str(datetime.date(now)) +", " + str(now.hour) + ":" + str(now.minute) )

        return report
示例#5
0
 def setUp(self):
     self.model = ReportEntriesModel()
示例#6
0
class TestReportEntriesModel(unittest.TestCase):

    def setUp(self):
        self.model = ReportEntriesModel()

    def test_to_json_empty_with_title_and_date(self):
        self.model.set_title("Demo")
        self.model.set_report_date("Demo date")
        json = self.model.json()
        self.assertEqual(json, {'title': "Demo", 'report_date': "Demo date"})

    def test_to_json_empty_with_defailt_title_and_date(self):
        json = self.model.json()
        self.assertEqual(json, {'title': "No title", 'report_date': "No date"})

    def test_to_json_with_thead_and_blog(self):
        thread = ThreadModel({'title':"Demo T"})
        blog = BlogEntry({'title': "Demo B"})
        self.model.add_entry("1", thread)
        self.model.add_entry("2", blog)

        json = self.model.json()
        #self.assertEqual(json, {'title': "", 'report_date': ""})
        self.assertEqual(json['1'], [{'title': "Demo T"}])
        self.assertEqual(json['2'], [{'title': "Demo B"}])
示例#7
0
def transtale_report_into_threads(report_query, report):
    new_report = ReportEntriesModel()
    for kword in report_query['keywords']:
        for thread in report[kword]:
            new_report.add_entry(kword, ThreadModel(thread))
    return new_report
示例#8
0
 def setUp(self):
     # self.report = ReportModel({'Asylum Games':[], 'Banjooli':[], 'Mutinies':[], 'Polis':[]})
     self.report = ReportEntriesModel()
     self.stats = ReportStats()