diff --git a/back/backend/test_backend.py b/back/backend/test_backend.py index 5cdc076..640ebea 100644 --- a/back/backend/test_backend.py +++ b/back/backend/test_backend.py @@ -527,3 +527,56 @@ class BackendTests(TestCase): 'string':'Some String', 'integer':100 }) + + # Other tests + ############# + + def test_get_files(self): + """ + Test getting files from a report. + """ + # create sample report + report = Report.objects.create( + user_id=self.test_user_1, + title="Report Title", + date_created=timezone.now(), + reference_number="1234" + ) + report.save() + + # create sample section + section_0 = Section.objects.create( + report_id=report, + auto_submit=False, + required=False, + completed=False, + title='Section Zero', + html_description='

Description zero

', + number=0 + ) + section_0.save() + + # create sample fields + field_0 = Field.objects.create( + section_id=section_0, + field_name='file 0', + label='A file', + number=0, + field_type='file', + completed=True, + data_file='uploads/2019/03/01/file0.jpg' + ) + field_0.save() + field_1 = Field.objects.create( + section_id=section_0, + field_name='file 1', + label='A file', + number=1, + field_type='file', + completed=True, + data_file='uploads/2019/03/01/file1.jpg' + ) + field_1.save() + expected = ['uploads/2019/03/01/file0.jpg', 'uploads/2019/03/01/file1.jpg'] + result = get_files(1) + self.assertEqual(result, expected) diff --git a/back/backend/views.py b/back/backend/views.py index d6d95b3..2c1ea73 100644 --- a/back/backend/views.py +++ b/back/backend/views.py @@ -452,6 +452,5 @@ def get_files(report_pk): fields = Field.objects.filter(section_id=section.id, completed=True) for field in fields: if field.field_type == "file": - print("appending {}".format(field.data_file.name)) files.append(field.data_file.name) return files