Created test for get_files().
This commit is contained in:
parent
2bac984496
commit
1fe1149cf8
2 changed files with 53 additions and 1 deletions
|
@ -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='<p>Description zero</p>',
|
||||
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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue