Esempio n. 1
0
    def test_jailtracker_person(self) -> None:
        key_mapping_file = "fixtures/jailtracker_person.yaml"
        key_mapping_file = os.path.join(os.path.dirname(__file__), key_mapping_file)
        extractor = JsonDataExtractor(key_mapping_file)

        expected_result = IngestInfo()
        expected_result.create_person(
            person_id="012345", birthdate="12/12/0001", age="2018", race="WHITE"
        )
        result = extractor.extract_and_populate_data(
            fixtures.as_dict("extractor", "jailtracker_person.json")
        )

        self.assertEqual(result, expected_result)
Esempio n. 2
0
    def test_jailtracker_booking(self) -> None:
        key_mapping_file = "fixtures/jailtracker_booking.yaml"
        key_mapping_file = os.path.join(os.path.dirname(__file__), key_mapping_file)

        extractor = JsonDataExtractor(key_mapping_file)

        expected_result = IngestInfo()
        expected_person = expected_result.create_person()
        expected_person.create_booking(
            booking_id="123098", admission_date="1/1/2001", release_date="1/1/2001"
        )
        expected_person.create_booking(
            booking_id="123099", admission_date="1/1/2002", release_date="1/1/2002"
        )

        result = extractor.extract_and_populate_data(
            fixtures.as_dict("extractor", "jailtracker_booking.json")
        )

        self.assertEqual(result, expected_result)
Esempio n. 3
0
    def test_skip_empty(self) -> None:
        key_mapping_file = os.path.join(
            os.path.dirname(__file__), "fixtures/skip_empty.yaml"
        )
        extractor = JsonDataExtractor(key_mapping_file)

        expected = IngestInfo()
        expected.create_person(
            full_name="skip empty",
            bookings=[
                Booking(
                    custody_status="in custody",
                    booking_id="1",
                    charges=[
                        Charge(
                            name="battery",
                        ),
                        Charge(
                            name="assault",
                            charge_class="misdemeanor",
                        ),
                    ],
                ),
                Booking(
                    booking_id="2",
                    charges=[
                        Charge(
                            name="robbery",
                            charge_class="felony",
                        ),
                    ],
                ),
            ],
        )

        result = extractor.extract_and_populate_data(
            fixtures.as_dict("extractor", "skip_empty.json")
        )
        self.assertEqual(result, expected)
Esempio n. 4
0
    def test_person_with_holds(self) -> None:
        key_mapping_file = "fixtures/person_with_holds.yaml"
        key_mapping_file = os.path.join(os.path.dirname(__file__), key_mapping_file)
        extractor = JsonDataExtractor(key_mapping_file)

        expected_result = IngestInfo()
        expected_person = expected_result.create_person(
            person_id="3245", full_name="AAA AAAB", race="BLACK"
        )
        booking_1 = expected_person.create_booking(
            booking_id="324567", admission_date="1/1/1111"
        )
        booking_1.create_hold(hold_id="345309", jurisdiction_name="jurisdiction name 1")
        booking_1.create_hold(hold_id="894303", jurisdiction_name="jurisdiction name 2")
        booking_2 = expected_person.create_booking(
            booking_id="3245", admission_date="2/2/2222"
        )
        booking_2.create_hold(hold_id="42309", jurisdiction_name="jurisdiction name 3")

        result = extractor.extract_and_populate_data(
            fixtures.as_dict("extractor", "person_with_holds.json")
        )
        self.assertEqual(result, expected_result)
Esempio n. 5
0
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
# =============================================================================
"""Tests for ingest/extractor/json_data_extractor.py"""
import os
import unittest

from recidiviz.ingest.extractor.json_data_extractor import JsonDataExtractor
from recidiviz.ingest.models.ingest_info import Booking, Charge, IngestInfo
from recidiviz.tests.ingest import fixtures

_JT_PERSON = fixtures.as_dict('extractor', 'jailtracker_person.json')
_JT_BOOKING = fixtures.as_dict('extractor', 'jailtracker_booking.json')
_PERSON_WITH_CHARGES = fixtures.as_dict('extractor',
                                        'person_with_charges.json')
_PERSON_WITH_HOLDS = fixtures.as_dict('extractor', 'person_with_holds.json')
_SKIP_EMPTY = fixtures.as_dict('extractor', 'skip_empty.json')


class DataExtractorJsonTest(unittest.TestCase):
    """Tests for extracting data from JSON."""
    def test_jailtracker_person(self):
        key_mapping_file = 'fixtures/jailtracker_person.yaml'
        key_mapping_file = os.path.join(os.path.dirname(__file__),
                                        key_mapping_file)
        extractor = JsonDataExtractor(key_mapping_file)
from unittest import TestCase

from recidiviz.common.ingest_metadata import IngestMetadata
from recidiviz.ingest.direct.regions.\
    us_ma_middlesex.us_ma_middlesex_controller \
    import UsMaMiddlesexController
from recidiviz.ingest.direct.regions.us_ma_middlesex.us_ma_middlesex_parser \
    import UsMaMiddlesexParser
from recidiviz.ingest.models.ingest_info import IngestInfo
from recidiviz.tests.ingest import fixtures
from recidiviz.tests.ingest.direct.direct_ingest_util import \
    build_controller_for_tests
from recidiviz.tests.utils.individual_ingest_test import IndividualIngestTest
from recidiviz.utils import regions

_ROSTER_JSON = fixtures.as_dict('direct/regions/us_ma_middlesex',
                                'roster.json')
_FAKE_START_TIME = datetime.datetime(year=2019, month=1, day=2)


class TestUsMaMiddlesexDirectIngestParser(IndividualIngestTest, TestCase):
    """Tests for the UsMaMiddlesexDirectIngestParser."""

    FIXTURE_PATH_PREFIX = 'direct/regions/us_ma_middlesex'

    def testParse(self):
        region = regions.get_region('us_ma_middlesex', is_direct_ingest=True)
        controller = build_controller_for_tests(UsMaMiddlesexController,
                                                run_async=False)

        metadata = IngestMetadata(region.region_code, region.jurisdiction_id,
                                  _FAKE_START_TIME,