def test_insert(self): report = Report(self.env) report.title = "The report" report.description = "The description" report.query = "SELECT 1" report.insert() self.assertEqual(9, report.id)
def test_update_report(self): Report(self.env).insert() req = MockRequest(self.env, method='POST', args={ 'action': 'edit', 'id': '1', 'title': "New Report edited", 'query': "SELECT 2", 'description': "The description edited" }) self.assertRaises(RequestDone, self.report_module.process_request, req) report = Report(self.env, 1) self.assertEqual("New Report edited", report.title) self.assertEqual("SELECT 2", report.query) self.assertEqual("The description edited", report.description) self.assertIn("Your changes have been saved.", req.chrome['notices'])
def test_create(self): report = Report(self.env, 4) self.assertTrue(report.exists) self.assertEqual(4, report.id) self.assertEqual("Accepted, Active Tickets by Owner", report.title) self.assertEqual( "List accepted tickets, group by ticket owner, " "sorted by priority.\n", report.description) self.assertIn("SELECT p.value AS __color__,", report.query)
def getReports(self, req): """ Get a list of available reports """ reports = list(Report.select(self.env)) return [{ "id": r.id, "title": r.title, "description": r.description } for r in reports]
def test_update(self): report = Report(self.env, 1) title, description, query = \ report.title, report.description, report.query report.title = "The report" report.description = "The description" report.query = "SELECT 1" report.update() report = Report(self.env, 1) self.assertNotEqual(title, report.title) self.assertNotEqual(description, report.description) self.assertNotEqual(query, report.query) self.assertEqual("The report", report.title) self.assertEqual("The description", report.description) self.assertEqual("SELECT 1", report.query)
def test_select(self): reports = list(Report.select(self.env)) self.assertEqual(1, reports[0].id) self.assertEqual('Active Tickets', reports[0].title) self.assertEqual( " * List all active tickets by priority.\n" " * Color each row based on priority.\n", reports[0].description) self.assertIn("SELECT p.value AS __color__", reports[0].query) self.assertEqual(8, len(reports)) self.assertEqual(1, reports[0].id) self.assertEqual(8, reports[-1].id)
def test_delete_report_cancel(self): req = MockRequest(self.env, method='POST', args={ 'action': 'delete', 'cancel': True, 'id': '1'}) self.assertRaises(RequestDone, self.report_module.process_request, req) self.assertTrue(Report(self.env, 1).exists) self.assertNotIn("The report {1} has been deleted.", req.chrome['notices']) self.assertEqual('http://example.org/trac.cgi/report/1', req.headers_sent['Location'])
def test_update_report_cancel(self): Report(self.env).insert() req = MockRequest(self.env, method='POST', args={ 'action': 'edit', 'cancel': True, 'id': '1', 'title': "New Report edited", 'query': "SELECT 2", 'description': "The description edited" }) self.assertRaises(RequestDone, self.report_module.process_request, req) report = Report(self.env, 1) self.assertEqual("Active Tickets", report.title) self.assertEqual( " * List all active tickets by priority.\n" " * Color each row based on priority.\n", report.description) self.assertIn("SELECT p.value AS __color__", report.query) self.assertNotIn("Your changes have been saved.", req.chrome['notices'])
def test_create_report(self): req = MockRequest(self.env, method='POST', args={ 'action': 'new', 'title': "New Report", 'query': "SELECT 1", 'description': "The description"}) self.assertRaises(RequestDone, self.report_module.process_request, req) self.assertTrue(Report(self.env, 9).exists) self.assertIn("The report has been created.", req.chrome['notices']) self.assertEqual('http://example.org/trac.cgi/report/9', req.headers_sent['Location'])
def test_execute_paginated_report_legacy_signature(self): """`execute_paginated_report` returns the same results with and without the deprecated `db` argument.""" id = 1 attrs = dict(reporter='joe', component='component1', version='1.0', milestone='milestone1', type='defect', owner='joe') self._generate_tickets(('status', 'priority'), self.REPORT_1_DATA, attrs) mod = self.report_module req = MockRequest(self.env) sql = Report(self.env, id).query rv1 = mod.execute_paginated_report(req, id, sql, {}) with self.env.db_query as db: rv2 = mod.execute_paginated_report(req, db, id, sql, {}) self.assertEqual(rv2, rv1)
def getReport(self, req, rid): """ Get report detail and matching tickets """ rid = int(rid) rm = ReportModule(self.env) r = Report(self.env, rid) title, description, sql = r.title, r.description, r.query cols, rows, do_, not_, care = rm.execute_paginated_report( req, rid, sql, {}, 0, 0) tickets = [] if 'ticket' in cols: for i in rows: tickets.append(i[cols.index('ticket')]) return { "report": { "id": r.id, "title": r.title, "description": r.description }, "tickets": tickets }
def test_delete_not_exists(self): report = Report(self.env) self.assertRaises(AssertionError, report.delete)
def test_select_sort_desc(self): reports = list(Report.select(self.env, asc=False)) self.assertEqual(8, len(reports)) self.assertEqual(8, reports[0].id) self.assertEqual(1, reports[-1].id)
def test_insert_existing_report(self): report = Report(self.env, 1) self.assertRaises(AssertionError, report.insert)
def test_repr(self): Report(self.env).insert() self.assertEqual("<Report 1>", repr(Report(self.env, 1))) self.assertEqual("<Report None>", repr(Report(self.env)))
def test_select_order_by_title(self): reports = list(Report.select(self.env, sort='title')) self.assertEqual(8, len(reports)) self.assertEqual(4, reports[0].id) self.assertEqual(7, reports[-1].id)
def _execute_report(self, id, args=None): mod = self.report_module req = MockRequest(self.env) report = Report(self.env, id) return mod.execute_paginated_report(req, id, report.query, args or {})
def test_delete(self): report = Report(self.env, 1) report.delete() self.assertFalse(report.exists) self.assertRaises(ResourceNotFound, Report, self.env, 1)