This repository has been archived by the owner on Jan 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlistsort_test.py
57 lines (43 loc) · 1.81 KB
/
listsort_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
import os
import listsort
import unittest
from mock import patch
import tempfile
@patch('listsort.LDAPInterface')
class ListsortTestCase(unittest.TestCase):
def setUp(self):
self.greylist_fd, listsort.app.config['GREYLISTFILE'] = tempfile.mkstemp()
listsort.app.config['LDAP_WHITE_DN'] = 'foo'
listsort.app.config['LDAP_BLACK_DN'] = 'bar'
self.app = listsort.app.test_client()
def tearDown(self):
os.close(self.greylist_fd)
os.unlink(listsort.app.config['GREYLISTFILE'])
def test_add_empty_domain_to_list(self,MockLDAPInterface):
rv = listsort.domain_to_list('','bu')
assert rv == False
def test_sanitize_mail(self,MockLDAPInterface):
rv = listsort.sanitize_entry('[email protected]')
assert rv == 'foo.bar'
def test_sanitize_utf8_mail(self,MockLDAPInterface):
rv = listsort.sanitize_entry(u'name@fo\xc3.bar')
assert rv == 'fo.bar'
def test_sanitize_domain(self,MockLDAPInterface):
rv = listsort.sanitize_entry('foo.bar')
assert rv == 'foo.bar'
def test_greylist_writeread(self,MockLDAPInterface):
listsort.save_greylist(['foo.bar','bar.foo'])
rv = listsort.load_greylist()
assert rv == ['bar.foo','foo.bar']
def test_greylist_cleandomainadd(self,MockLDAPInterface):
listsort.save_greylist(['foo.bar','bar.foo'])
listsort.domain_to_list('example.com','grey')
rv = listsort.load_greylist()
assert rv == ['bar.foo','example.com','foo.bar']
def test_greylist_mailadd(self,MockLDAPInterface):
listsort.save_greylist(['foo.bar','bar.foo'])
listsort.domain_to_list('[email protected]','grey')
rv = listsort.load_greylist()
assert rv == ['bar.foo','example.com','foo.bar']
if __name__ == '__main__':
unittest.main()