-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_conversions.py
More file actions
166 lines (143 loc) · 7.15 KB
/
test_conversions.py
File metadata and controls
166 lines (143 loc) · 7.15 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# do not pre-load
import json
import unittest
from unittest.mock import MagicMock
from pathlib import Path
from docassemble.base.core import DAObject
from docassemble.AssemblyLine.al_general import ALIndividual
from ..efm_client import ProxyConnection, ApiResponse
from ..conversions import choices_and_map, parse_case_info, parse_service_contacts
class TestConversions(unittest.TestCase):
# Tests conversions.py on the "vars.json" file
def setUp(self):
with open(Path(__file__).parent / "vars.json", "r") as file:
full_json = json.load(file).get("variables")
self.my_var = full_json.get("my_var").get("data")
self.my_service_contacts = full_json.get("my_service_contacts")
self.proxy_conn = ProxyConnection()
self.proxy_conn.get_case = MagicMock(
"get_case", return_value=ApiResponse(200, "", self.my_var)
)
def test_parse_case_info(self):
# Makes sure that participants of the case are parsed fully, needed
case = DAObject("case")
parse_case_info(self.proxy_conn, case, self.my_var, "adams")
self.assertEqual(len(case.participants), 2)
for partip in case.participants:
self.assertIsInstance(partip, ALIndividual)
self.assertIn(partip.person_type, ["ALIndividual", "business"])
self.assertNotEqual(partip.name.first, None)
self.assertNotEqual(partip.tyler_id, None)
if partip.person_type == "ALIndividual":
self.assertNotEqual(partip.name.last, None)
# Make sure the name is title case: first letter is upper, everything else lower
self.assertEqual(partip.name.first[0], partip.name.first[0].upper())
self.assertEqual(partip.name.first[1], partip.name.first[1].lower())
self.assertTrue(hasattr(partip, "address"))
self.assertEqual(partip.address.city, "RADOM")
self.assertEqual(partip.address.zip, "62876")
self.assertFalse(hasattr(partip, "phone_number"))
self.assertFalse(hasattr(partip, "email"))
self.assertTrue(hasattr(partip, "party_type"))
self.assertTrue(hasattr(partip, "party_type_name"))
self.assertTrue(hasattr(partip, "tyler_id"))
self.assertEqual(case.participants[0].instanceName, "case.participants[0]")
self.assertEqual(case.docket_number, "2020SC12")
self.assertEqual(case.category, "6198")
def test_parse_service_contact(self):
no_contacts = parse_service_contacts([])
self.assertEqual(len(no_contacts), 0)
service_contacts = parse_service_contacts(self.my_service_contacts)
self.assertEqual(len(service_contacts), 1)
self.assertEqual(service_contacts[0][0], "6707a4f8-9f4c-4bbb-8498-ed4890208c6d")
self.assertEqual(service_contacts[0][1], "Bryce Willey")
class TestNoneResp(unittest.TestCase):
# Tests with none responses conversions.py on the "vars.json" file
def setUp(self):
with open(Path(__file__).parent / "vars.json", "r") as file:
full_json = json.load(file).get("variables")
self.my_var = full_json.get("my_var").get("data")
self.my_service_contacts = full_json.get("my_service_contacts")
self.proxy_conn = ProxyConnection()
self.proxy_conn.get_case = MagicMock(
"get_case", return_value=ApiResponse(200, "", None)
)
def test_none(self):
# Makes sure that participants of the case are parsed fully, needed
case = DAObject("case")
parse_case_info(self.proxy_conn, case, None, "peoria")
# no throw!
class TestCourtSwitching(unittest.TestCase):
# Tests that if we search a case in a grouped court (say peoria) and
# get back a court from a sub court (peariacr), that the
# court_id from the found case reflects the sub court.
#
# This is necessary, as filings can't be accepted to the grouped court."""
def setUp(self):
with open(Path(__file__).parent / "peoria_to_cr.json", "r") as file:
self.my_var = json.load(file)
self.proxy_conn = ProxyConnection()
self.proxy_conn.get_case = MagicMock(
"get_case", return_value=ApiResponse(200, "", self.my_var)
)
def test_switched_court(self):
# Makes sure that participants of the case are parsed fully, needed
case = DAObject("case")
parse_case_info(self.proxy_conn, case, self.my_var, "peoria")
self.assertEqual(case.court_id, "peoriacr")
self.assertEqual(case.docket_number, "02-CM-02778-1")
self.assertEqual(case.category, "135493")
class TestConversionIgnoreAttorneys(unittest.TestCase):
def setUp(self):
with open(Path(__file__).parent / "temp2.json", "r") as file:
full_json = json.load(file).get("selected_existing_case")
self.first_resp = full_json.get("details")
self.more_details = full_json.get("case_details")
self.proxy_conn = ProxyConnection()
self.proxy_conn.get_case = MagicMock(
"get_case", return_value=ApiResponse(200, "", self.more_details)
)
def test_ignore_attorneys(self):
# Attorneys are just stuck in the middle with normal case participants. You can't attach service contacts to them, so
case = DAObject("case")
parse_case_info(self.proxy_conn, case, self.first_resp, "peoria")
self.assertEqual(len(case.attorneys.keys()), 2)
self.assertTrue("e650827f-3a2b-4550-b76c-f7d22ed479ff" in case.attorneys.keys())
self.assertTrue("7ff43f9b-53ff-4e6d-9253-e393318549d0" in case.attorneys.keys())
class TestChoicesAndMap(unittest.TestCase):
def setUp(self):
self.data = [
{
"code": "169",
"name": "Probate or Mental Health",
"ecfcasetype": "CivilCase",
"procedureremedyinitial": "Not Available",
"procedureremedysubsequent": "Not Available",
"damageamountinitial": "Not Available",
"damageamountsubsequent": "Not Available",
},
{
"code": "7405",
"name": "Adoption",
"ecfcasetype": "CivilCase",
"procedureremedyinitial": "Not Available",
"procedureremedysubsequent": "Not Available",
"damageamountinitial": "Not Available",
"damageamountsubsequent": "Not Available",
},
]
def test_choices_and_map_nones(self):
# As long as nothing throws, we're good.
choices_and_map(None)
choices_and_map([])
choices_and_map([None, None])
choices_and_map(["blah", "blah"])
choices_and_map("blah")
# Note: we still fail on empty dicts in the list. No good fallback for that.
# choices_and_map([{}])
def test_choices_and_map_success(self):
choices, code_map = choices_and_map(self.data)
self.assertEqual(len(choices), 2)
self.assertEqual(len(code_map), 2)
self.assertEqual(choices[0], ("169", "Probate or Mental Health"))
self.assertEqual(code_map["169"]["name"], "Probate or Mental Health")