def get_saved_exports(self): exports = CaseExportSchema.get_stale_exports(self.domain) new_exports = get_case_export_instances(self.domain) exports += new_exports if not self.has_deid_view_permissions: exports = filter(lambda x: not x.is_safe, exports) return sorted(exports, key=lambda x: x.name)
def test_edit_daily_saved_export_filters(self, _): # Create an export # Update the filters # confirm that the filters on the export have been updated appropriately export_post_data = json.dumps({ "doc_type": "CaseExportInstance", "domain": self.domain.name, "xmlns": "http://openrosa.org/formdesigner/237B85C0-78B1-4034-8277-5D37E3EA7FD1", "last_updated": None, "legacy_saved_export_schema_id": None, "is_daily_saved_export": True, "tables": [], "transform_dates": True, "last_accessed": None, "app_id": "6a48b8838d06febeeabb28c8c9516ab6", "is_deidentified": False, "split_multiselects": False, "external_blobs": {}, "export_format": "csv", "include_errors": False, "type": "form", "name": "A Villager's Health > Registrationaa > Reg form: 2016-06-27" }) resp = self.client.post( reverse(CreateNewDailySavedCaseExport.urlname, args=[self.domain.name]), export_post_data, content_type="application/json", follow=True ) self.assertEqual(resp.status_code, 200) exports = get_case_export_instances(self.domain.name) self.assertEqual(len(exports), 1) export = exports[0] filter_form_data = { "emwf_case_filter": [], "type_or_group": "group", "date_range": "range", "start_date": "1992-01-30", "end_date": "2016-10-01", } resp = self.client.post( reverse(DailySavedExportListView.urlname, args=[self.domain.name]), json.dumps({ "export": {"id": export._id}, "form_data": filter_form_data }), content_type="application/json", HTTP_X_REQUESTED_WITH="XMLHttpRequest", HTTP_DJNG_REMOTE_METHOD='commit_filters', ) self.assertEqual(resp.status_code, 200) response_content = json.loads(resp.content) self.assertFalse("error" in response_content, response_content.get("error")) export = CaseExportInstance.get(export._id) self.assertEqual(export.filters.date_period.period_type, 'range')
def test_edit_daily_saved_export_filters(self, _): # Create an export # Update the filters # confirm that the filters on the export have been updated appropriately export_post_data = json.dumps({ "doc_type": "CaseExportInstance", "domain": self.domain.name, "xmlns": "http://openrosa.org/formdesigner/237B85C0-78B1-4034-8277-5D37E3EA7FD1", "last_updated": None, "legacy_saved_export_schema_id": None, "is_daily_saved_export": True, "tables": [], "transform_dates": True, "last_accessed": None, "app_id": "6a48b8838d06febeeabb28c8c9516ab6", "is_deidentified": False, "split_multiselects": False, "external_blobs": {}, "export_format": "csv", "include_errors": False, "type": "form", "name": "A Villager's Health > Registrationaa > Reg form: 2016-06-27" }) resp = self.client.post( reverse(CreateNewDailySavedCaseExport.urlname, args=[self.domain.name]), export_post_data, content_type="application/json", follow=True ) self.assertEqual(resp.status_code, 200) exports = get_case_export_instances(self.domain.name) self.assertEqual(len(exports), 1) export = exports[0] filter_form_data = { "emwf_case_filter": [], "date_range": "range", "start_date": "1992-01-30", "end_date": "2016-10-01", } resp = self.client.post( reverse('commit_filters', args=[self.domain.name]), { "export_id": export._id, "model_type": "case", "form_data": json.dumps(filter_form_data), }, ) self.assertEqual(resp.status_code, 200) response_content = json.loads(resp.content) self.assertFalse("error" in response_content, response_content.get("error")) export = CaseExportInstance.get(export._id) self.assertEqual(export.filters.date_period.period_type, 'range')
def test_edit_case_export(self): export_post_data = json.dumps({ "doc_type": "CaseExportInstance", "domain": self.domain.name, "xmlns": "http://openrosa.org/formdesigner/237B85C0-78B1-4034-8277-5D37E3EA7FD1", "last_updated": None, "legacy_saved_export_schema_id": None, "is_daily_saved_export": False, "tables": [], "transform_dates": True, "last_accessed": None, "app_id": "6a48b8838d06febeeabb28c8c9516ab6", "is_deidentified": False, "split_multiselects": False, "external_blobs": {}, "export_format": "csv", "include_errors": False, "type": "form", "name": "A Villager's Health > Registrationaa > Reg form: 2016-06-27" }) resp = self.client.post(reverse(CreateNewCustomCaseExportView.urlname, args=[self.domain.name]), export_post_data, content_type="application/json", follow=True) self.assertEqual(resp.status_code, 200) exports = get_case_export_instances(self.domain.name) self.assertEqual(len(exports), 1) export = exports[0] resp = self.client.post( reverse(EditNewCustomCaseExportView.urlname, args=[self.domain.name, export._id]), export_post_data, content_type="application/json", ) self.assertEqual(resp.status_code, 200)
def test_edit_case_export(self): export_post_data = json.dumps({ "doc_type": "CaseExportInstance", "domain": self.domain.name, "xmlns": "http://openrosa.org/formdesigner/237B85C0-78B1-4034-8277-5D37E3EA7FD1", "last_updated": None, "legacy_saved_export_schema_id": None, "is_daily_saved_export": False, "tables": [], "transform_dates": True, "last_accessed": None, "app_id": "6a48b8838d06febeeabb28c8c9516ab6", "is_deidentified": False, "split_multiselects": False, "external_blobs": {}, "export_format": "csv", "include_errors": False, "type": "form", "name": "A Villager's Health > Registrationaa > Reg form: 2016-06-27" }) resp = self.client.post( reverse(CreateNewCustomCaseExportView.urlname, args=[self.domain.name]), export_post_data, content_type="application/json", follow=True ) self.assertEqual(resp.status_code, 200) exports = get_case_export_instances(self.domain.name) self.assertEqual(len(exports), 1) export = exports[0] resp = self.client.post( reverse( EditNewCustomCaseExportView.urlname, args=[self.domain.name, export._id] ), export_post_data, content_type="application/json", ) self.assertEqual(resp.status_code, 200)
def test_get_case_export_instances_wrong_domain(self): instances = get_case_export_instances('wrong') self.assertEqual(len(instances), 0)
def test_get_case_export_instances(self): instances = get_case_export_instances(self.domain) self.assertEqual(len(instances), 2)