From bec11980eb589b4a8b0b56a6253b16ff2c6829cf Mon Sep 17 00:00:00 2001 From: Carlos Lopez Date: Sun, 31 May 2020 22:00:52 -0600 Subject: [PATCH] Fixing broken test by using proper FileSchema --- crc/models/study.py | 2 +- crc/services/study_service.py | 1 - tests/test_study_api.py | 39 +++++++++++++++++------------------ 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/crc/models/study.py b/crc/models/study.py index 1e1cf440..540ee018 100644 --- a/crc/models/study.py +++ b/crc/models/study.py @@ -151,7 +151,7 @@ class StudySchema(ma.Schema): hsr_number = fields.String(allow_none=True) sponsor = fields.String(allow_none=True) ind_number = fields.String(allow_none=True) - files = fields.List(fields.Nested(SimpleFileSchema), dump_only=True) + files = fields.List(fields.Nested(FileSchema), dump_only=True) approvals = fields.List(fields.Nested('ApprovalSchema'), dump_only=True) class Meta: diff --git a/crc/services/study_service.py b/crc/services/study_service.py index 5807fb24..e6ef5291 100644 --- a/crc/services/study_service.py +++ b/crc/services/study_service.py @@ -56,7 +56,6 @@ class StudyService(object): study = Study.from_model(study_model) study.categories = StudyService.get_categories() workflow_metas = StudyService.__get_workflow_metas(study_id) - study.files = FileService.get_files_for_study(study.id) approvals = ApprovalService.get_approvals_for_study(study.id) study.approvals = [Approval.from_model(approval_model) for approval_model in approvals] diff --git a/tests/test_study_api.py b/tests/test_study_api.py index 10f4cb6e..61e42543 100644 --- a/tests/test_study_api.py +++ b/tests/test_study_api.py @@ -72,28 +72,27 @@ class TestStudyApi(BaseTest): def test_get_study_has_details_about_files(self): - # # Set up the study and attach a file to it. - # self.load_example_data() - # self.create_reference_document() - # workflow = self.create_workflow('file_upload_form') - # processor = WorkflowProcessor(workflow) - # task = processor.next_task() - # irb_code = "UVACompl_PRCAppr" # The first file referenced in pb required docs. - # FileService.add_workflow_file(workflow_id=workflow.id, - # name="anything.png", content_type="png", - # binary_data=b'1234', irb_doc_code=irb_code) - # - # api_response = self.app.get('/v1.0/study/%i' % workflow.study_id, - # headers=self.logged_in_headers(), content_type="application/json") - # self.assert_success(api_response) - # study = StudySchema().loads(api_response.get_data(as_text=True)) - # self.assertEquals(1, len(study.files)) - # self.assertEquals("UVA Compliance/PRC Approval", study.files[0]["category"]) - # self.assertEquals("Cancer Center's PRC Approval Form", study.files[0]["description"]) - # self.assertEquals("UVA Compliance/PRC Approval.png", study.files[0]["download_name"]) + # Set up the study and attach a file to it. + self.load_example_data() + self.create_reference_document() + workflow = self.create_workflow('file_upload_form') + processor = WorkflowProcessor(workflow) + task = processor.next_task() + irb_code = "UVACompl_PRCAppr" # The first file referenced in pb required docs. + FileService.add_workflow_file(workflow_id=workflow.id, + name="anything.png", content_type="png", + binary_data=b'1234', irb_doc_code=irb_code) + + api_response = self.app.get('/v1.0/study/%i' % workflow.study_id, + headers=self.logged_in_headers(), content_type="application/json") + self.assert_success(api_response) + study = StudySchema().loads(api_response.get_data(as_text=True)) + self.assertEquals(1, len(study.files)) + self.assertEquals("UVA Compliance/PRC Approval", study.files[0]["category"]) + self.assertEquals("Cancer Center's PRC Approval Form", study.files[0]["description"]) + self.assertEquals("UVA Compliance/PRC Approval.png", study.files[0]["download_name"]) # TODO: WRITE A TEST FOR STUDY FILES - pass def test_get_study_has_details_about_approvals(self): # TODO: WRITE A TEST FOR STUDY APPROVALS