-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy path__init__.py
More file actions
143 lines (124 loc) · 4.87 KB
/
__init__.py
File metadata and controls
143 lines (124 loc) · 4.87 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import decimal
import json
import os
import datetime
from smtpapi import SMTPAPIHeader
try:
import unittest2 as unittest
except ImportError:
import unittest
class TestSMTPAPI(unittest.TestCase):
def setUp(self):
self.validHeader = json.loads('''{"to":["test@email.com",
"test2@email.com", "test3@email.com"],
"sub":{"subKey":["subValue"],"decimalKey":[1.23456789]},
"section":{"testSection":"sectionValue"},
"category":["testCategory"],
"unique_args":{"testUnique":"uniqueValue"},
"asm_group_id":42,
"send_each_at":[1409348513, 1409348514],
"send_at": 1409348515,
"ip_pool": "testPool",
"filters":{"testFilter":{"settings":{"filter":"filterValue"}}}}''')
self.dropsHeader = json.loads('''{
"sub":{"subKey":["subValue"],"decimalKey":[1.23456789]},
"unique_args":{"testUnique":"uniqueValue"},
"filters":{"testFilter":{"settings":{"filter":"filterValue"}}}}''')
def test_add(self):
header = SMTPAPIHeader()
header.add_to('test@email.com')
header.add_to(['test2@email.com', 'test3@email.com'])
header.add_substitution('subKey', 'subValue')
header.add_substitution('decimalKey', decimal.Decimal("1.23456789"))
header.add_section('testSection', 'sectionValue')
header.add_category('testCategory')
header.add_unique_arg('testUnique', 'uniqueValue')
header.set_asm_group_id(42)
header.add_send_each_at(1409348513)
header.add_send_each_at(1409348514)
header.set_send_at(1409348515)
header.set_ip_pool('testPool')
header.add_filter('testFilter', 'filter', 'filterValue')
self.assertEqual(self.validHeader, json.loads(header.json_string()))
def test_set(self):
header = SMTPAPIHeader()
header.set_tos([
"test@email.com",
"test2@email.com",
"test3@email.com",
])
header.set_substitutions({
"subKey": ["subValue"],
"decimalKey": [decimal.Decimal("1.23456789")]
})
header.set_sections(json.loads('{"testSection":"sectionValue"}'))
header.set_categories(["testCategory"])
header.set_unique_args(json.loads('{"testUnique":"uniqueValue"}'))
header.set_asm_group_id(42)
header.set_send_each_at([1409348513, 1409348514])
header.set_send_at(1409348515)
header.set_ip_pool('testPool')
header.add_filter('testFilter', 'filter', 'filterValue')
self.assertEqual(self.validHeader, json.loads(header.json_string()))
def test_drop_empty(self):
header = SMTPAPIHeader()
header.set_tos([])
header.set_substitutions({
"subKey": ["subValue"],
"decimalKey": [decimal.Decimal("1.23456789")]
})
header.set_sections(json.loads('{}'))
header.set_categories([])
header.set_unique_args(json.loads('{"testUnique":"uniqueValue"}'))
header.set_asm_group_id(None)
header.set_send_each_at([])
header.set_ip_pool(None)
header.add_filter('testFilter', 'filter', 'filterValue')
self.assertEqual(self.dropsHeader, json.loads(header.json_string()))
def test_license_year(self):
LICENSE_FILE = 'LICENSE'
copyright_line = ''
with open(LICENSE_FILE, 'r') as f:
for line in f:
if line.startswith('Copyright'):
copyright_line = line.strip()
break
self.assertEqual(
'Copyright (C) %s, Twilio SendGrid, Inc. <help@twilio.com>'
% datetime.datetime.now().year,
copyright_line
)
class TestRepository(unittest.TestCase):
def setUp(self):
self.required_files = [
'./Dockerfile',
'./.env_sample',
'./PULL_REQUEST_TEMPLATE.md',
'./.gitignore',
'./CHANGELOG.md',
'./CODE_OF_CONDUCT.md',
'./CONTRIBUTING.md',
'./LICENSE',
'./README.rst',
'./TROUBLESHOOTING.md',
'./USAGE.md',
'./VERSION.txt',
]
self.file_not_found_message = 'File "{0}" does not exist in repo!'
def test_repository_files_exists(self):
for file_path in self.required_files:
if isinstance(file_path, list):
# multiple file paths: assert that any one of the files exists
self.assertTrue(
any(os.path.exists(f) for f in file_path),
msg=self.file_not_found_message.format(
'" or "'.join(file_path)
),
)
else:
self.assertTrue(
os.path.exists(file_path),
msg=self.file_not_found_message.format(file_path),
)
if __name__ == '__main__':
unittest.main()