-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_list.py
77 lines (56 loc) · 1.74 KB
/
test_list.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
import ballotgen
import pytest
test_members = [
{
'email': u'[email protected]',
'name': u'Example User'
},
{
'email': u'[email protected]',
'name': u''
}
]
test_members_emails = set([u'[email protected]', u'[email protected]'])
test_users = [
{
'email': u'[email protected]',
'name': u'Example User'
},
{
'email': u'[email protected]',
'name': u''
}
]
mapping = {
'email': {
},
'org': {
'example.com': 'user',
},
}
def test_get_gov_list():
with pytest.raises(IOError):
ballotgen.get_gov_list('badpass')
def test_parse_gov_list():
soup = ballotgen.get_gov_list_file("tests/data/test-members.html")
assert test_members == ballotgen.parse_gov_list(soup)
def test_users_file():
data = ballotgen.get_users_file("tests/data/test-users.yaml")
assert test_users == data
def test_build_set():
assert test_members_emails == ballotgen.build_set(test_members, 'email')
with pytest.raises(KeyError):
ballotgen.build_set(test_members, 'nonexistant')
def test_voters():
expected = set(['[email protected]', '[email protected]'])
found = ballotgen.find_voters(test_members, test_users, mapping)
assert expected == found
bad_mapping = {'email': {'[email protected]': 'nonexistant'}}
with pytest.raises(ValueError):
ballotgen.find_voters(test_members, test_users, bad_mapping)
def test_reduce_org():
bad_mapping = {'org': {'example.com': 'nonexistant'}}
with pytest.raises(ValueError):
ballotgen.reduce_org(test_members_emails, bad_mapping)
assert set(['[email protected]']) == ballotgen.reduce_org(test_members_emails, mapping)