|
1 | 1 | if __name__ == '__main__' and __package__ is None: |
2 | | - from os import sys, path |
3 | | - sys.path.append(path.dirname(path.dirname(path.abspath(__file__)))) |
| 2 | + from os import sys, path |
| 3 | + sys.path.append(path.dirname(path.dirname(path.abspath(__file__)))) |
4 | 4 | import blockscore |
5 | 5 | import unittest |
6 | 6 | import os, sys |
7 | 7 |
|
8 | 8 | class TestBlockscore(unittest.TestCase): |
9 | 9 |
|
10 | | - def setUp(self): |
11 | | - try: |
12 | | - self.client = blockscore.Client({'api_key': os.environ['BLOCKSCORE_API']}) |
13 | | - except KeyError: |
14 | | - sys.stderr.write("To run tests, you must have a BLOCKSCORE_API environment variable with a test api key\n") |
15 | | - sys.exit(2) |
16 | | - |
17 | | - self.test_identity = { |
18 | | - "name_first": "John", |
19 | | - "name_middle": "Pearce", |
20 | | - "name_last": "Doe", |
21 | | - "birth_day": "23", |
22 | | - "birth_month": "8", |
23 | | - "birth_year": "1980", |
24 | | - "document_type": "ssn", |
25 | | - "document_value": "0000", |
26 | | - "address_street1": "1 Infinite Loop", |
27 | | - "address_street2": "Apt 6", |
28 | | - "address_city": "Cupertino", |
29 | | - "address_subdivision": "CA", |
30 | | - "address_postal_code": "95014", |
31 | | - "address_country_code": "US", |
32 | | - } |
33 | | - def test_create_person(self): |
34 | | - response = self.client.people.create(self.test_identity) |
35 | | - self.assertEqual(response.body['name_first'], self.test_identity['name_first']) |
36 | | - self.assertEqual(response.body['name_last'], self.test_identity['name_last']) |
37 | | - |
38 | | - def test_retrieve_person(self): |
39 | | - verif = self.client.people.create(self.test_identity) |
40 | | - verif_id = verif.body['id'] |
41 | | - verif2 = self.client.people.retrieve(verif_id) |
42 | | - self.assertEqual(verif.body, verif2.body) |
43 | | - |
44 | | - def test_list_people(self): |
45 | | - self.client.people.create(self.test_identity) |
46 | | - self.client.people.create(self.test_identity) |
47 | | - self.client.people.create(self.test_identity) |
48 | | - verif_list = self.client.people.all(count=3) |
49 | | - verif_list = verif_list.body |
50 | | - self.assertTrue(len(verif_list) >= 3) |
51 | | - verif_list2 = self.client.people.all(count=3,offset=3) |
52 | | - verif_list2 = verif_list2.body |
53 | | - self.assertNotEqual(verif_list, verif_list2) |
54 | | - |
55 | | - |
56 | | - |
57 | | - def test_create_questions(self): |
58 | | - verif = self.client.people.create(self.test_identity) |
59 | | - verif = verif.body |
60 | | - verif_id = verif['id'] |
61 | | - qset = self.client.question_sets.create(verif_id) |
62 | | - qset = qset.body |
63 | | - self.assertEqual(qset['person_id'],verif_id) |
64 | | - |
65 | | - def test_score_questions(self): |
66 | | - verif = self.client.people.create(self.test_identity) |
67 | | - verif = verif.body |
68 | | - verif_id = verif['id'] |
69 | | - qset = self.client.question_sets.create(verif_id) |
70 | | - qset = qset.body |
71 | | - qset_id = qset['id'] |
72 | | - score = self.client.question_sets.score(qset_id, [ |
73 | | - {'question_id':1, 'answer_id':1}, |
74 | | - {'question_id':2, 'answer_id':1}, |
75 | | - {'question_id':3, 'answer_id':1}, |
76 | | - {'question_id':4, 'answer_id':1}, |
77 | | - {'question_id':5, 'answer_id':1} |
78 | | - ]) |
79 | | - score = score.body |
80 | | - self.assertEqual(score['id'],qset_id) |
81 | | - self.assertIsInstance(score['score'],float) |
82 | | - |
83 | | - |
84 | | - |
85 | | - # make sure the shuffled sequence does not lose any elements |
86 | | - # random.shuffle(self.seq) |
87 | | - # self.seq.sort() |
88 | | - # self.assertEqual(self.seq, range(10)) |
89 | | - # self.assertEqual(1,1) |
90 | | - |
91 | | - # should raise an exception for an immutable sequence |
92 | | - # self.assertRaises(TypeError, random.shuffle, (1,2,3)) |
93 | | - |
94 | | - # def test_choice(self): |
95 | | - # element = random.choice(self.seq) |
96 | | - # self.assertTrue(element in self.seq) |
97 | | - |
98 | | - # def test_sample(self): |
99 | | - # with self.assertRaises(ValueError): |
100 | | - # random.sample(self.seq, 20) |
101 | | - # for element in random.sample(self.seq, 5): |
102 | | - # self.assertTrue(element in self.seq) |
| 10 | + def setUp(self): |
| 11 | + try: |
| 12 | + self.client = blockscore.Client({'api_key': os.environ['BLOCKSCORE_API']}) |
| 13 | + except KeyError: |
| 14 | + sys.stderr.write("To run tests, you must have a BLOCKSCORE_API environment variable with a test api key\n") |
| 15 | + sys.exit(2) |
| 16 | + |
| 17 | + self.test_identity = { |
| 18 | + "name_first": "John", |
| 19 | + "name_middle": "Pearce", |
| 20 | + "name_last": "Doe", |
| 21 | + "birth_day": "23", |
| 22 | + "birth_month": "8", |
| 23 | + "birth_year": "1980", |
| 24 | + "document_type": "ssn", |
| 25 | + "document_value": "0000", |
| 26 | + "address_street1": "1 Infinite Loop", |
| 27 | + "address_street2": "Apt 6", |
| 28 | + "address_city": "Cupertino", |
| 29 | + "address_subdivision": "CA", |
| 30 | + "address_postal_code": "95014", |
| 31 | + "address_country_code": "US", |
| 32 | + } |
| 33 | + def test_create_person(self): |
| 34 | + response = self.client.people.create(self.test_identity) |
| 35 | + self.assertEqual(response.body['name_first'], self.test_identity['name_first']) |
| 36 | + self.assertEqual(response.body['name_last'], self.test_identity['name_last']) |
| 37 | + |
| 38 | + def test_retrieve_person(self): |
| 39 | + verif = self.client.people.create(self.test_identity) |
| 40 | + verif_id = verif.body['id'] |
| 41 | + verif2 = self.client.people.retrieve(verif_id) |
| 42 | + self.assertEqual(verif.body, verif2.body) |
| 43 | + |
| 44 | + def test_list_people(self): |
| 45 | + self.client.people.create(self.test_identity) |
| 46 | + self.client.people.create(self.test_identity) |
| 47 | + self.client.people.create(self.test_identity) |
| 48 | + verif_list = self.client.people.all(count=3) |
| 49 | + verif_list = verif_list.body |
| 50 | + self.assertTrue(len(verif_list) >= 3) |
| 51 | + verif_list2 = self.client.people.all(count=3,offset=3) |
| 52 | + verif_list2 = verif_list2.body |
| 53 | + self.assertNotEqual(verif_list, verif_list2) |
| 54 | + |
| 55 | + |
| 56 | + |
| 57 | + def test_create_questions(self): |
| 58 | + verif = self.client.people.create(self.test_identity) |
| 59 | + verif = verif.body |
| 60 | + verif_id = verif['id'] |
| 61 | + qset = self.client.question_sets.create(verif_id) |
| 62 | + qset = qset.body |
| 63 | + self.assertEqual(qset['person_id'],verif_id) |
| 64 | + |
| 65 | + def test_score_questions(self): |
| 66 | + verif = self.client.people.create(self.test_identity) |
| 67 | + verif = verif.body |
| 68 | + verif_id = verif['id'] |
| 69 | + qset = self.client.question_sets.create(verif_id) |
| 70 | + qset = qset.body |
| 71 | + qset_id = qset['id'] |
| 72 | + score = self.client.question_sets.score(qset_id, [ |
| 73 | + {'question_id':1, 'answer_id':1}, |
| 74 | + {'question_id':2, 'answer_id':1}, |
| 75 | + {'question_id':3, 'answer_id':1}, |
| 76 | + {'question_id':4, 'answer_id':1}, |
| 77 | + {'question_id':5, 'answer_id':1} |
| 78 | + ]) |
| 79 | + score = score.body |
| 80 | + self.assertEqual(score['id'],qset_id) |
| 81 | + self.assertIsInstance(score['score'],float) |
| 82 | + |
| 83 | + |
| 84 | + |
| 85 | + # make sure the shuffled sequence does not lose any elements |
| 86 | + # random.shuffle(self.seq) |
| 87 | + # self.seq.sort() |
| 88 | + # self.assertEqual(self.seq, range(10)) |
| 89 | + # self.assertEqual(1,1) |
| 90 | + |
| 91 | + # should raise an exception for an immutable sequence |
| 92 | + # self.assertRaises(TypeError, random.shuffle, (1,2,3)) |
| 93 | + |
| 94 | + # def test_choice(self): |
| 95 | + # element = random.choice(self.seq) |
| 96 | + # self.assertTrue(element in self.seq) |
| 97 | + |
| 98 | + # def test_sample(self): |
| 99 | + # with self.assertRaises(ValueError): |
| 100 | + # random.sample(self.seq, 20) |
| 101 | + # for element in random.sample(self.seq, 5): |
| 102 | + # self.assertTrue(element in self.seq) |
103 | 103 |
|
104 | 104 | if __name__ == '__main__': |
105 | | - unittest.main() |
| 105 | + unittest.main() |
106 | 106 |
|
0 commit comments