/
app_test.py
62 lines (40 loc) · 1.78 KB
/
app_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import os
import shutil
from io import BytesIO
from werkzeug.datastructures import FileStorage
from services import fileService
from services.staticStrings import StaticStrings
"""
Test for static response strings
asserts that the proper static string of introduction is returned when "landlord" is selected by the user
"""
def test_static_strings():
string = StaticStrings.chooseFrom(StaticStrings.problem_inquiry_landlord)
assert string in StaticStrings.problem_inquiry_landlord
"""
Test for file services
asserts the functionality of the system for the upload of various files (zip, pdf, png images)
"""
def test_file_service_path():
path = fileService.generate_path(1, 1)
assert path == '{}/conversations/{}/{}'.format(fileService.UPLOAD_FOLDER, 1, 1)
def test_file_service_format():
file = FileStorage(filename='my_file.pdf')
assert fileService.is_accepted_format(file) is True
def test_file_service_format_unsupported():
file = FileStorage(filename='my_file.zip')
assert fileService.is_accepted_format(file) is False
def test_file_service_name_sanitize():
file = FileStorage(filename='some/file/path/my_file.pdf')
assert fileService.sanitize_name(file) == 'some_file_path_my_file.pdf'
def test_file_service_upload():
file_name = 'testfile.png'
with open('test/testfile.png', 'rb') as f:
stream = BytesIO(f.read())
file = FileStorage(stream=stream, filename=file_name)
file_name_sanitized = fileService.sanitize_name(file)
file_path = fileService.generate_path(1, 1, testing=True)
fileService.upload_file(file, file_path, file_name_sanitized)
assert os.path.exists("{}/{}".format(file_path, file_name))
# Delete test upload folder
shutil.rmtree("{}/".format(fileService.UPLOAD_FOLDER_TEST))