-
Notifications
You must be signed in to change notification settings - Fork 5
/
test_server.py
78 lines (61 loc) · 2.41 KB
/
test_server.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from os import environ
environ.setdefault("SENDGRIDFROMEMAIL", "[email protected]")
environ.setdefault("SENDGRIDAPIKEY", "testsendgridapikey")
environ.setdefault("RECAPTCHASITEKEY", "testrecaptchasitekey")
environ.setdefault("RECAPTCHASECRETKEY", "testrecaptchasecretkey")
environ.setdefault("NUMBEROFATTACHMENTS", "2")
from datetime import datetime
import server
form = {
'message': 'hello',
'recipient': '[email protected]',
'filename-0': 'file0.txt',
'attachment-0': 'content0',
'filename-1': 'file1.txt',
'attachment-1': 'content1',
}
text, recipient, all_attachments = server.parse_form(form)
assert 'hello' == text
assert '[email protected]' == recipient
assert [
('file0.txt', 'content0'),
('file1.txt', 'content1'),
] == all_attachments
# empty attachment fields are omitted
form['attachment-1'] = ''
text, recipient, all_attachments = server.parse_form(form)
assert [
('file0.txt', 'content0'),
] == all_attachments
assert server.valid_recipient('legal')
assert not server.valid_recipient('nonlegal')
assert 'devcon:2023:01:01:12:00:00:123' == server.get_identifier('devcon', datetime(2023, 1, 1, 12), 123)
toEmail = '[email protected]'
identifier = 'just:some:identifier'
text = 'encrypted_blablabla'
all_attachments = [
('myfile.txt', 'encrypted_file_content'),
]
email = server.create_email(toEmail, identifier, text, all_attachments)
assert server.FROMEMAIL == email.from_email.email
assert toEmail == email.personalizations[0].tos[0]['email']
assert "Secure Form Submission just:some:identifier" == email.subject.subject
assert text == email.contents[0].content
assert 1 == len(email.attachments)
a = email.attachments[0]
assert "myfile.txt.pgp" == a.file_name.file_name
assert "application/pgp-encrypted" == a.file_type.file_type
assert "ZW5jcnlwdGVkX2ZpbGVfY29udGVudA==" == a.file_content.file_content
two_attachments = [
('myfile1.txt', 'encrypted_file_content1'),
('myfile2.txt', 'encrypted_file_content2'),
]
email = server.create_email(toEmail, identifier, text, two_attachments)
a0 = email.attachments[0]
assert "myfile2.txt.pgp" == a0.file_name.file_name
assert "application/pgp-encrypted" == a0.file_type.file_type
assert "ZW5jcnlwdGVkX2ZpbGVfY29udGVudDI=" == a0.file_content.file_content
a1 = email.attachments[1]
assert "myfile1.txt.pgp" == a1.file_name.file_name
assert "application/pgp-encrypted" == a1.file_type.file_type
assert "ZW5jcnlwdGVkX2ZpbGVfY29udGVudDE=" == a1.file_content.file_content