class TestDashboard(unittest.TestCase): common_filters = [{"object_id": 126, "constraint": {"type": "floating", "from": -3, "to": -1}}] wildcard_filter = { 'attribute': 'label.page.page_name', 'value': 'fake_page' } output_path = './fake_page.pdf' def setUp(self): self.connection = Connection(username, password) self.project = Project(self.connection) self.project.load(test_dashboard_project_id) self.dashboard = Dashboard( self.project, user_id, test_dashboard_id, test_tab_id, test_dashboard_name ) def test_get_execution_context(self): expected_answer = '/gdc/projects/%(project_id)s/users/%(user_id)s/executioncontexts/' % { 'project_id': test_dashboard_project_id, 'user_id': user_id } self.dashboard._get_execution_context(self.common_filters) self.assertIn(expected_answer, self.dashboard.execution_context_response_uri) common_filters = [{"wrong_object_id": 126, "constraint": {"type": "floating", "from": -3, "to": -1}}] self.assertRaises(DashboardExportError, self.dashboard._get_execution_context, common_filters) def test_get_client_export(self): expected_answer = '/gdc/projects/%(project_id)s/clientexport/' % { 'project_id': test_dashboard_project_id } self.dashboard._get_client_export(self.common_filters, self.wildcard_filter) self.assertIn(expected_answer, self.dashboard.client_export_response_uri) def test_poll_for_dashboard_data(self): self.dashboard._poll_for_dashboard_data(self.common_filters, self.wildcard_filter) self.assertIsNotNone(self.dashboard.pdf_data) def test_save_as_pdf(self): self.dashboard.save_as_pdf(self.common_filters, self.wildcard_filter, self.output_path) try: os.remove(self.output_path) except: self.fail('pdf should be found') def test_saved_dashboard_is_empty(self): self.dashboard.save_as_pdf(self.common_filters, self.wildcard_filter, self.output_path) self.dashboard.EMPTY_SIZE = 10 # fake pdf size self.assertFalse(self.dashboard.saved_dashboard_is_empty(self.output_path)) self.dashboard.EMPTY_SIZE = 13109 # real pdf size self.assertTrue(self.dashboard.saved_dashboard_is_empty(self.output_path)) os.remove(self.output_path)
class TestReport(unittest.TestCase): def setUp(self): self.connection = Connection(username, password) self.project = Project(self.connection) self.project.load(report_project_id) def test_exec_report(self): report = Report(self.project, test_report_id) report.execute_report() self.assertTrue(report.exec_result) def test_export_report(self): report = Report(self.project, test_report_id) report.export_report() self.assertTrue(report.export_download_uri) report.exec_result = 'fake' self.assertRaises(ReportExportFailed, report.export_report) def test_get_report(self): report = Report(self.project, test_report_id) report.get_report() self.assertTrue(report.report_content) self.assertFalse(report.report_content[0] == '{') def test_get_empty_report(self): report = Report(self.project, test_empty_report_id) report.get_report() self.assertEquals(report.report_content, '') def test_save_report(self): report = Report(self.project, test_report_id) file_path = './test_report.txt' report.save_report(file_path) try: with open(file_path): pass except IOError: self.fail() os.remove(file_path)