def testAnonymous_GetReport(self): self.SetCurrentUser('') self.assertEqual(None, report_template.GetReport('in-id', [10, 20])) report = report_template.GetReport('ex-id', [10, 20]) self.assertFalse(report['internal']) self.assertEqual(0, len(report['report']['rows'])) self.assertEqual('external', report['name']) self.assertFalse(report['editable']) self.assertEqual([testing_common.EXTERNAL_USER.email()], report['owners'])
def testGetReport_Static(self): self.SetCurrentUser(testing_common.EXTERNAL_USER.email()) report = report_template.GetReport(584630894, ['latest']) self.assertFalse(report['internal']) self.assertEqual('http://exter.nal', report['report']['url']) self.assertEqual('Test:External', report['name']) self.assertFalse(report['editable']) self.assertNotIn('owners', report)
def testInternal_GetReport(self): self.SetCurrentUser(testing_common.INTERNAL_USER.email()) report = report_template.GetReport('in-id', [10, 20]) self.assertTrue(report['internal']) self.assertEqual(0, len(report['report']['rows'])) self.assertEqual('internal', report['name']) self.assertTrue(report['editable']) self.assertEqual([testing_common.INTERNAL_USER.email()], report['owners'])
def testGetReport_Static(self): self.SetCurrentUser(testing_common.EXTERNAL_USER.email()) report = report_template.GetReport('static-id', [10, 20]) self.assertFalse(report['internal']) self.assertEqual('external', report['report']) self.assertEqual('Test:External', report['name']) self.assertFalse(report['editable']) self.assertNotIn('owners', report)
def Post(self): revisions = self.request.get('revisions', None) if revisions is None: raise api_request_handler.BadRequestError try: revisions = [int(r) if r != 'latest' else r for r in revisions.split(',')] except ValueError: raise api_request_handler.BadRequestError try: template_id = int(self.request.get('id')) except ValueError: raise api_request_handler.BadRequestError try: report = report_template.GetReport(template_id, revisions) except AssertionError: # The caller has requested internal-only data but is not authorized. raise api_request_handler.NotFoundError if report is None: raise api_request_handler.NotFoundError return report