def testSetSentencesOnSentenceGroup_NoSentences(self): """Tests that the hydrated StateIncarcerationSentences and StateSupervisionSentences are set on the StateSentenceGroup.""" sentence_group = StateSentenceGroup.new_with_defaults( incarceration_sentences=[], supervision_sentences=[]) person_and_entities = ({ 'incarceration_sentences': [], 'supervision_sentences': [], 'sentence_groups': [sentence_group] }) expected_sentence_group = StateSentenceGroup.new_with_defaults( incarceration_sentences=[], supervision_sentences=[]) test_pipeline = TestPipeline() output = ( test_pipeline | beam.Create([(12345, person_and_entities)]) | 'Set Incarceration and Supervision Sentences on SentenceGroups' >> beam.ParDo(entity_hydration_utils.SetSentencesOnSentenceGroup())) assert_that(output, equal_to([(12345, expected_sentence_group)])) test_pipeline.run()
def testSetSentencesOnSentenceGroup_NoSentences(self): """Tests that the hydrated StateIncarcerationSentences and StateSupervisionSentences are set on the StateSentenceGroup.""" sentence_group = StateSentenceGroup.new_with_defaults( state_code="US_XX", status=StateSentenceStatus.PRESENT_WITHOUT_INFO, incarceration_sentences=[], supervision_sentences=[], ) person_and_entities = { "incarceration_sentences": [], "supervision_sentences": [], "sentence_groups": [sentence_group], } expected_sentence_group = StateSentenceGroup.new_with_defaults( state_code="US_XX", status=StateSentenceStatus.PRESENT_WITHOUT_INFO, incarceration_sentences=[], supervision_sentences=[], ) test_pipeline = TestPipeline() output = ( test_pipeline | beam.Create([(12345, person_and_entities)]) | "Set Incarceration and Supervision Sentences on SentenceGroups" >> beam.ParDo(entity_hydration_utils.SetSentencesOnSentenceGroup())) assert_that(output, equal_to([(12345, expected_sentence_group)])) test_pipeline.run()
def testSetSentencesOnSentenceGroup(self): """Tests that the hydrated StateIncarcerationSentences and StateSupervisionSentences are set on the StateSentenceGroup.""" incarceration_sentence_id = 123 supervision_sentence_id = 456 hydrated_incarceration_sentence = StateIncarcerationSentence.new_with_defaults( incarceration_sentence_id=incarceration_sentence_id, start_date=date(2000, 1, 1), charges=[StateCharge.new_with_defaults(ncic_code='1234')], incarceration_periods=[ StateIncarcerationPeriod.new_with_defaults( admission_date=date(2000, 3, 2)) ]) hydrated_supervision_sentence = StateSupervisionSentence.new_with_defaults( supervision_sentence_id=supervision_sentence_id, start_date=date(2000, 1, 1), charges=[StateCharge.new_with_defaults(ncic_code='1234')], incarceration_periods=[ StateIncarcerationPeriod.new_with_defaults( admission_date=date(2000, 3, 2)) ]) sentence_group = StateSentenceGroup.new_with_defaults( incarceration_sentences=[ StateIncarcerationSentence.new_with_defaults( incarceration_sentence_id=incarceration_sentence_id) ], supervision_sentences=[ StateSupervisionSentence.new_with_defaults( supervision_sentence_id=supervision_sentence_id) ]) person_and_entities = ({ 'incarceration_sentences': [hydrated_incarceration_sentence], 'supervision_sentences': [hydrated_supervision_sentence], 'sentence_groups': [sentence_group] }) hydrated_incarceration_sentence_with_group = StateIncarcerationSentence.new_with_defaults( incarceration_sentence_id=incarceration_sentence_id, start_date=date(2000, 1, 1), charges=[StateCharge.new_with_defaults(ncic_code='1234')], incarceration_periods=[ StateIncarcerationPeriod.new_with_defaults( admission_date=date(2000, 3, 2)) ]) hydrated_supervision_sentence_with_group = StateSupervisionSentence.new_with_defaults( supervision_sentence_id=supervision_sentence_id, start_date=date(2000, 1, 1), charges=[StateCharge.new_with_defaults(ncic_code='1234')], incarceration_periods=[ StateIncarcerationPeriod.new_with_defaults( admission_date=date(2000, 3, 2)) ]) expected_sentence_group = StateSentenceGroup.new_with_defaults( incarceration_sentences=[ hydrated_incarceration_sentence_with_group ], supervision_sentences=[hydrated_supervision_sentence_with_group]) hydrated_incarceration_sentence_with_group.sentence_group = expected_sentence_group hydrated_supervision_sentence_with_group.sentence_group = expected_sentence_group test_pipeline = TestPipeline() output = ( test_pipeline | beam.Create([(12345, person_and_entities)]) | 'Set Incarceration and Supervision Sentences on SentenceGroups' >> beam.ParDo(entity_hydration_utils.SetSentencesOnSentenceGroup())) assert_that(output, equal_to([(12345, expected_sentence_group)])) test_pipeline.run()
def testSetSentencesOnSentenceGroup(self): """Tests that the hydrated StateIncarcerationSentences and StateSupervisionSentences are set on the StateSentenceGroup.""" incarceration_sentence_id = 123 supervision_sentence_id = 456 hydrated_incarceration_sentence = StateIncarcerationSentence.new_with_defaults( state_code="US_XX", incarceration_sentence_id=incarceration_sentence_id, start_date=date(2000, 1, 1), status=StateSentenceStatus.PRESENT_WITHOUT_INFO, charges=[ StateCharge.new_with_defaults( state_code="US_XX", status=ChargeStatus.PRESENT_WITHOUT_INFO, ncic_code="1234", ) ], incarceration_periods=[ StateIncarcerationPeriod.new_with_defaults( state_code="US_XX", admission_date=date(2000, 3, 2), status=StateIncarcerationPeriodStatus.PRESENT_WITHOUT_INFO, ) ], ) hydrated_supervision_sentence = StateSupervisionSentence.new_with_defaults( state_code="US_XX", supervision_sentence_id=supervision_sentence_id, start_date=date(2000, 1, 1), charges=[ StateCharge.new_with_defaults( state_code="US_XX", status=ChargeStatus.PRESENT_WITHOUT_INFO, ncic_code="1234", ) ], incarceration_periods=[ StateIncarcerationPeriod.new_with_defaults( state_code="US_XX", admission_date=date(2000, 3, 2), status=StateIncarcerationPeriodStatus.PRESENT_WITHOUT_INFO, ) ], status=StateSentenceStatus.PRESENT_WITHOUT_INFO, ) sentence_group = StateSentenceGroup.new_with_defaults( state_code="US_XX", status=StateSentenceStatus.PRESENT_WITHOUT_INFO, incarceration_sentences=[ StateIncarcerationSentence.new_with_defaults( state_code="US_XX", incarceration_sentence_id=incarceration_sentence_id, status=StateSentenceStatus.PRESENT_WITHOUT_INFO, ) ], supervision_sentences=[ StateSupervisionSentence.new_with_defaults( state_code="US_XX", supervision_sentence_id=supervision_sentence_id, status=StateSentenceStatus.PRESENT_WITHOUT_INFO, ) ], ) person_and_entities = { "incarceration_sentences": [hydrated_incarceration_sentence], "supervision_sentences": [hydrated_supervision_sentence], "sentence_groups": [sentence_group], } hydrated_incarceration_sentence_with_group = ( StateIncarcerationSentence.new_with_defaults( state_code="US_XX", incarceration_sentence_id=incarceration_sentence_id, start_date=date(2000, 1, 1), status=StateSentenceStatus.PRESENT_WITHOUT_INFO, charges=[ StateCharge.new_with_defaults( state_code="US_XX", status=ChargeStatus.PRESENT_WITHOUT_INFO, ncic_code="1234", ) ], incarceration_periods=[ StateIncarcerationPeriod.new_with_defaults( state_code="US_XX", admission_date=date(2000, 3, 2), status=StateIncarcerationPeriodStatus. PRESENT_WITHOUT_INFO, ) ], )) hydrated_supervision_sentence_with_group = ( StateSupervisionSentence.new_with_defaults( state_code="US_XX", supervision_sentence_id=supervision_sentence_id, start_date=date(2000, 1, 1), charges=[ StateCharge.new_with_defaults( state_code="US_XX", status=ChargeStatus.PRESENT_WITHOUT_INFO, ncic_code="1234", ) ], incarceration_periods=[ StateIncarcerationPeriod.new_with_defaults( state_code="US_XX", admission_date=date(2000, 3, 2), status=StateIncarcerationPeriodStatus. PRESENT_WITHOUT_INFO, ) ], status=StateSentenceStatus.PRESENT_WITHOUT_INFO, )) expected_sentence_group = StateSentenceGroup.new_with_defaults( state_code="US_XX", status=StateSentenceStatus.PRESENT_WITHOUT_INFO, incarceration_sentences=[ hydrated_incarceration_sentence_with_group ], supervision_sentences=[hydrated_supervision_sentence_with_group], ) hydrated_incarceration_sentence_with_group.sentence_group = ( expected_sentence_group) hydrated_supervision_sentence_with_group.sentence_group = ( expected_sentence_group) test_pipeline = TestPipeline() output = ( test_pipeline | beam.Create([(12345, person_and_entities)]) | "Set Incarceration and Supervision Sentences on SentenceGroups" >> beam.ParDo(entity_hydration_utils.SetSentencesOnSentenceGroup())) assert_that(output, equal_to([(12345, expected_sentence_group)])) test_pipeline.run()
def testSetSentencesOnSentenceGroupMultipleSGs(self): """Tests that the hydrated StateIncarcerationSentences and StateSupervisionSentences are set on the appropriate StateSentenceGroup.""" incarceration_sentence_id_1 = 123 incarceration_sentence_id_2 = 456 supervision_sentence_id = 789 hydrated_incarceration_sentence_1 = ( StateIncarcerationSentence.new_with_defaults( state_code="US_XX", incarceration_sentence_id=incarceration_sentence_id_1, start_date=date(2000, 1, 1), status=StateSentenceStatus.PRESENT_WITHOUT_INFO, charges=[ StateCharge.new_with_defaults( state_code="US_XX", status=ChargeStatus.PRESENT_WITHOUT_INFO, ncic_code="1234", ) ], )) hydrated_incarceration_sentence_2 = ( StateIncarcerationSentence.new_with_defaults( state_code="US_XX", incarceration_sentence_id=incarceration_sentence_id_2, start_date=date(2000, 1, 1), status=StateSentenceStatus.PRESENT_WITHOUT_INFO, charges=[ StateCharge.new_with_defaults( state_code="US_XX", status=ChargeStatus.PRESENT_WITHOUT_INFO, ncic_code="5678", ) ], incarceration_periods=[ StateIncarcerationPeriod.new_with_defaults( state_code="US_XX", admission_date=date(2000, 3, 2), status=StateIncarcerationPeriodStatus. PRESENT_WITHOUT_INFO, ) ], )) hydrated_supervision_sentence = StateSupervisionSentence.new_with_defaults( state_code="US_XX", supervision_sentence_id=supervision_sentence_id, start_date=date(2000, 1, 1), charges=[ StateCharge.new_with_defaults( state_code="US_XX", status=ChargeStatus.PRESENT_WITHOUT_INFO, ncic_code="1234", ) ], incarceration_periods=[ StateIncarcerationPeriod.new_with_defaults( state_code="US_XX", admission_date=date(2000, 3, 2), status=StateIncarcerationPeriodStatus.PRESENT_WITHOUT_INFO, ) ], status=StateSentenceStatus.PRESENT_WITHOUT_INFO, ) sentence_group_1 = StateSentenceGroup.new_with_defaults( state_code="US_XX", sentence_group_id=111, status=StateSentenceStatus.PRESENT_WITHOUT_INFO, incarceration_sentences=[ StateIncarcerationSentence.new_with_defaults( state_code="US_XX", incarceration_sentence_id=incarceration_sentence_id_1, status=StateSentenceStatus.PRESENT_WITHOUT_INFO, ) ], ) sentence_group_2 = StateSentenceGroup.new_with_defaults( state_code="US_XX", sentence_group_id=222, status=StateSentenceStatus.PRESENT_WITHOUT_INFO, incarceration_sentences=[ StateIncarcerationSentence.new_with_defaults( state_code="US_XX", incarceration_sentence_id=incarceration_sentence_id_2, status=StateSentenceStatus.PRESENT_WITHOUT_INFO, ) ], supervision_sentences=[ StateSupervisionSentence.new_with_defaults( state_code="US_XX", supervision_sentence_id=supervision_sentence_id, status=StateSentenceStatus.PRESENT_WITHOUT_INFO, ) ], ) person_and_entities = { "incarceration_sentences": [ hydrated_incarceration_sentence_1, hydrated_incarceration_sentence_2, ], "supervision_sentences": [hydrated_supervision_sentence], "sentence_groups": [sentence_group_1, sentence_group_2], } hydrated_incarceration_sentence_1_with_group = attr.evolve( hydrated_incarceration_sentence_1) hydrated_incarceration_sentence_2_with_group = attr.evolve( hydrated_incarceration_sentence_2) hydrated_supervision_sentence_with_group = attr.evolve( hydrated_supervision_sentence) expected_sentence_group_1 = attr.evolve( sentence_group_1, incarceration_sentences=[ hydrated_incarceration_sentence_1_with_group ], ) expected_sentence_group_2 = attr.evolve( sentence_group_2, incarceration_sentences=[ hydrated_incarceration_sentence_2_with_group ], supervision_sentences=[hydrated_supervision_sentence_with_group], ) hydrated_incarceration_sentence_1_with_group.sentence_group = ( expected_sentence_group_1) hydrated_incarceration_sentence_2_with_group.sentence_group = ( expected_sentence_group_2) hydrated_supervision_sentence_with_group.sentence_group = ( expected_sentence_group_2) test_pipeline = TestPipeline() output = ( test_pipeline | beam.Create([(12345, person_and_entities)]) | "Set Incarceration and Supervision Sentences on SentenceGroups" >> beam.ParDo(entity_hydration_utils.SetSentencesOnSentenceGroup())) assert_that( output, equal_to([(12345, expected_sentence_group_1), (12345, expected_sentence_group_2)]), ) test_pipeline.run()