Repository navigation
Expand file tree
/
Copy pathwatchlists.py
More file actions
113 lines (103 loc) · 4.62 KB
/
Copy pathwatchlists.py
File metadata and controls
113 lines (103 loc) · 4.62 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
#!/usr/bin/env python
if __name__ == '__main__' and __package__ is None:
from os import sys, path
sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))
import blockscore
import unittest
import os, sys
from unittest import skip
import time
class TestWatchlistsAPI(unittest.TestCase):
def setUp(self):
try:
self.client = blockscore.Client({'api_key': os.environ['BLOCKSCORE_API']})
except KeyError:
sys.stderr.write("To run tests, you must have a BLOCKSCORE_API environment variable with a test api key\n")
sys.exit(2)
self.test_identity = {
'date_of_birth': '1980-01-01',
'identification': {
'ssn': '0000',
'passport': '12315235'
},
'name': {
'first': 'john',
'middle': 'a',
'last': 'doe'
},
'address': {
'street1': '1 Infinite Loop',
'street2': 'Floor 3',
'city': 'Palo Alto',
'state': 'ca',
'postal_code': '94309',
'country_code': 'us'
},
'note': 'test'
}
def test_create_body(self):
body = self.client.watchlists._create_body(**self.test_identity)
self.assertDictEqual({
'ssn': self.test_identity['identification']['ssn'],
'date_of_birth': self.test_identity['date_of_birth'],
'passport': self.test_identity['identification']['passport'],
'name_first': self.test_identity['name']['first'],
'name_middle': self.test_identity['name']['middle'],
'name_last': self.test_identity['name']['last'],
'address_street1': self.test_identity['address']['street1'],
'address_street2': self.test_identity['address']['street2'],
'address_city': self.test_identity['address']['city'],
'address_subdivision': self.test_identity['address']['state'],
'address_postal_code': self.test_identity['address']['postal_code'],
'address_country_code': self.test_identity['address']['country_code'],
'note': self.test_identity['note']
}, body)
def test_create_candidate(self):
candidate = self.client.watchlists.create(**self.test_identity)
expected_body = self.client.watchlists._create_body(**self.test_identity)
self.assertDictContainsSubset(expected_body, candidate.body)
def test_edit_candidate(self):
candidate_id = self.client.watchlists.create(**self.test_identity).body['id']
candidate = self.client.watchlists.edit(candidate_id, date_of_birth='1980-01-02')
self.test_identity['date_of_birth'] = '1980-01-02'
expected_body = self.client.watchlists._create_body(**self.test_identity)
expected_body['id'] = candidate_id
self.assertDictContainsSubset(expected_body, candidate.body)
def test_retrieve_candidate(self):
candidate_id = self.client.watchlists.create(**self.test_identity).body['id']
candidate = self.client.watchlists.retrieve(candidate_id)
expected_body = self.client.watchlists._create_body(**self.test_identity)
expected_body['id'] = candidate_id
self.assertDictContainsSubset(expected_body, candidate.body)
def test_delete_candidate(self):
candidate_id = self.client.watchlists.create(**self.test_identity).body['id']
candidate = self.client.watchlists.delete(candidate_id)
expected_body = self.client.watchlists._create_body(**self.test_identity)
expected_body['id'] = candidate_id
expected_body['deleted'] = True
self.assertDictContainsSubset(expected_body, candidate.body)
@skip('These tests do not pass consistently because of eventual consistency of candidate list')
def test_list_candidates_with_params(self):
candidate = self.client.watchlists.create()
candidate_list = self.client.watchlists.list(count=1)
self.assertListEqual([candidate.body], candidate_list.body)
self.client.watchlists.create()
candidate_list = self.client.watchlists.list(count=1, offset=1)
self.assertListEqual([candidate.body], candidate_list.body)
#@skip('These tests do not pass consistently because of eventual consistency of candidate list')
def test_list_candidates_all(self):
candidate = self.client.watchlists.create(**self.test_identity)
expected_body = self.client.watchlists._create_body(**self.test_identity)
candidate_id = candidate.body['id']
time.sleep(5)
candidate_list = self.client.watchlists.list()
match = {}
for c in candidate_list.body['data']:
if c[u'id'] == candidate_id:
match = c
self.assertDictContainsSubset(expected_body, match)
def test_search(self):
candidate_id = self.client.watchlists.create().body['id']
response = self.client.watchlists.search(candidate_id)
self.assertIn('searched_lists', response.body)
self.assertIn('matches', response.body)