|
| 1 | +#!/usr/bin/env python |
| 2 | +if __name__ == '__main__' and __package__ is None: |
| 3 | + from os import sys, path |
| 4 | + sys.path.append(path.dirname(path.dirname(path.abspath(__file__)))) |
| 5 | +import blockscore |
| 6 | +import unittest |
| 7 | +import os, sys |
| 8 | +from unittest import skip |
| 9 | +import time |
| 10 | + |
| 11 | +class TestWatchlistsAPI(unittest.TestCase): |
| 12 | + def setUp(self): |
| 13 | + try: |
| 14 | + self.client = blockscore.Client({'api_key': os.environ['BLOCKSCORE_API']}) |
| 15 | + except KeyError: |
| 16 | + sys.stderr.write("To run tests, you must have a BLOCKSCORE_API environment variable with a test api key\n") |
| 17 | + sys.exit(2) |
| 18 | + |
| 19 | + self.test_identity = { |
| 20 | + 'date_of_birth': '1980-01-01', |
| 21 | + 'identification': { |
| 22 | + 'ssn': '0000', |
| 23 | + 'passport': '12315235' |
| 24 | + }, |
| 25 | + 'name': { |
| 26 | + 'first': 'john', |
| 27 | + 'middle': 'a', |
| 28 | + 'last': 'doe' |
| 29 | + }, |
| 30 | + 'address': { |
| 31 | + 'street1': '1 Infinite Loop', |
| 32 | + 'street2': 'Floor 3', |
| 33 | + 'city': 'Palo Alto', |
| 34 | + 'state': 'ca', |
| 35 | + 'postal_code': '94309', |
| 36 | + 'country_code': 'us' |
| 37 | + }, |
| 38 | + 'note': 'test' |
| 39 | + } |
| 40 | + |
| 41 | + def test_create_body(self): |
| 42 | + body = self.client.watchlists._create_body(**self.test_identity) |
| 43 | + self.assertDictEqual({ |
| 44 | + 'ssn': self.test_identity['identification']['ssn'], |
| 45 | + 'date_of_birth': self.test_identity['date_of_birth'], |
| 46 | + 'passport': self.test_identity['identification']['passport'], |
| 47 | + 'name_first': self.test_identity['name']['first'], |
| 48 | + 'name_middle': self.test_identity['name']['middle'], |
| 49 | + 'name_last': self.test_identity['name']['last'], |
| 50 | + 'address_street1': self.test_identity['address']['street1'], |
| 51 | + 'address_street2': self.test_identity['address']['street2'], |
| 52 | + 'address_city': self.test_identity['address']['city'], |
| 53 | + 'address_subdivision': self.test_identity['address']['state'], |
| 54 | + 'address_postal_code': self.test_identity['address']['postal_code'], |
| 55 | + 'address_country_code': self.test_identity['address']['country_code'], |
| 56 | + 'note': self.test_identity['note'] |
| 57 | + }, body) |
| 58 | + |
| 59 | + def test_create_candidate(self): |
| 60 | + candidate = self.client.watchlists.create(**self.test_identity) |
| 61 | + expected_body = self.client.watchlists._create_body(**self.test_identity) |
| 62 | + self.assertDictContainsSubset(expected_body, candidate.body) |
| 63 | + |
| 64 | + def test_edit_candidate(self): |
| 65 | + candidate_id = self.client.watchlists.create(**self.test_identity).body['id'] |
| 66 | + candidate = self.client.watchlists.edit(candidate_id, date_of_birth='1980-01-02') |
| 67 | + self.test_identity['date_of_birth'] = '1980-01-02' |
| 68 | + expected_body = self.client.watchlists._create_body(**self.test_identity) |
| 69 | + expected_body['id'] = candidate_id |
| 70 | + self.assertDictContainsSubset(expected_body, candidate.body) |
| 71 | + |
| 72 | + def test_retrieve_candidate(self): |
| 73 | + candidate_id = self.client.watchlists.create(**self.test_identity).body['id'] |
| 74 | + candidate = self.client.watchlists.retrieve(candidate_id) |
| 75 | + expected_body = self.client.watchlists._create_body(**self.test_identity) |
| 76 | + expected_body['id'] = candidate_id |
| 77 | + self.assertDictContainsSubset(expected_body, candidate.body) |
| 78 | + |
| 79 | + def test_delete_candidate(self): |
| 80 | + candidate_id = self.client.watchlists.create(**self.test_identity).body['id'] |
| 81 | + candidate = self.client.watchlists.delete(candidate_id) |
| 82 | + expected_body = self.client.watchlists._create_body(**self.test_identity) |
| 83 | + expected_body['id'] = candidate_id |
| 84 | + expected_body['deleted'] = True |
| 85 | + self.assertDictContainsSubset(expected_body, candidate.body) |
| 86 | + |
| 87 | + @skip('These tests do not pass consistently because of eventual consistency of candidate list') |
| 88 | + def test_list_candidates_with_params(self): |
| 89 | + candidate = self.client.watchlists.create() |
| 90 | + candidate_list = self.client.watchlists.list(count=1) |
| 91 | + self.assertListEqual([candidate.body], candidate_list.body) |
| 92 | + self.client.watchlists.create() |
| 93 | + candidate_list = self.client.watchlists.list(count=1, offset=1) |
| 94 | + self.assertListEqual([candidate.body], candidate_list.body) |
| 95 | + |
| 96 | + #@skip('These tests do not pass consistently because of eventual consistency of candidate list') |
| 97 | + def test_list_candidates_all(self): |
| 98 | + candidate = self.client.watchlists.create(**self.test_identity) |
| 99 | + expected_body = self.client.watchlists._create_body(**self.test_identity) |
| 100 | + candidate_id = candidate.body['id'] |
| 101 | + time.sleep(5) |
| 102 | + candidate_list = self.client.watchlists.list() |
| 103 | + match = {} |
| 104 | + for c in candidate_list.body['data']: |
| 105 | + if c[u'id'] == candidate_id: |
| 106 | + match = c |
| 107 | + self.assertDictContainsSubset(expected_body, match) |
| 108 | + |
| 109 | + def test_search(self): |
| 110 | + candidate_id = self.client.watchlists.create().body['id'] |
| 111 | + response = self.client.watchlists.search(candidate_id) |
| 112 | + self.assertIn('searched_lists', response.body) |
| 113 | + self.assertIn('matches', response.body) |
0 commit comments