def test_usMo_getPreIncarcerationSupervisionType(self): incarceration_period = StateIncarcerationPeriod.new_with_defaults( incarceration_period_id=1, admission_reason=StateIncarcerationPeriodAdmissionReason. PAROLE_REVOCATION, external_id='ip1', state_code='US_MO', admission_date=self.REVOCATION_DATE) supervision_sentence_parole = FakeUsMoSupervisionSentence.fake_sentence_from_sentence( StateSupervisionSentence.new_with_defaults( supervision_sentence_id=1, external_id=self.PAROLE_SENTENCE_EXTERNAL_ID, start_date=datetime.date(2017, 2, 1), supervision_type=StateSupervisionType.PROBATION), supervision_type=StateSupervisionType.PAROLE) # Even though the supervision type of the sentence is PROBATION, we find that it's actually a PAROLE # sentence from the statuses. self.assertEqual( StateSupervisionPeriodSupervisionType.PAROLE, us_mo_get_pre_incarceration_supervision_type( incarceration_sentences=[], supervision_sentences=[supervision_sentence_parole], incarceration_period=incarceration_period))
def test_usMo_getPreIncarcerationSupervisionType(self): incarceration_period = StateIncarcerationPeriod.new_with_defaults( incarceration_period_id=1, admission_reason=StateIncarcerationPeriodAdmissionReason. PAROLE_REVOCATION, external_id='ip1', state_code='US_MO', admission_date=datetime.date(year=2019, month=9, day=13)) supervision_sentence_parole = FakeUsMoSupervisionSentence.fake_sentence_from_sentence( StateSupervisionSentence.new_with_defaults( supervision_sentence_id=1, external_id='1167633-20171012-2', start_date=datetime.date(2017, 2, 1), supervision_type=StateSupervisionType.PROBATION), supervision_type_spans=[ SupervisionTypeSpan( start_date=datetime.date(2017, 2, 1), end_date=None, supervision_type=StateSupervisionType.PAROLE) ]) # Even though the supervision type of the sentence is PROBATION, we find that it's actually a PAROLE # sentence from the statuses. self.assertEqual( StateSupervisionPeriodSupervisionType.PAROLE, us_mo_get_pre_incarceration_supervision_type( incarceration_sentences=[], supervision_sentences=[supervision_sentence_parole], incarceration_period=incarceration_period))
def test_month_supervision_type_no_supervision_all_month(self): # Arrange supervision_period = StateSupervisionPeriod.new_with_defaults( supervision_period_id=1234, external_id='sp1', state_code='US_MO', start_date=(self.end_of_month_date - datetime.timedelta(days=60))) supervision_sentence = FakeUsMoSupervisionSentence.fake_sentence_from_sentence( StateSupervisionSentence.new_with_defaults( external_id='ss1', state_code='US_MO', start_date=supervision_period.start_date), supervision_type_spans=[ SupervisionTypeSpan( start_date=supervision_period.start_date, end_date=self.start_of_month_date, supervision_type=StateSupervisionType.PROBATION), # Incarcerated / suspended since start of month SupervisionTypeSpan(start_date=self.start_of_month_date, end_date=None, supervision_type=None) ]) # Act supervision_period_supervision_type = \ us_mo_get_month_supervision_type(self.end_of_month_date, supervision_sentences=[supervision_sentence], incarceration_sentences=[], supervision_period=supervision_period) # Assert self.assertEqual( supervision_period_supervision_type, StateSupervisionPeriodSupervisionType.INTERNAL_UNKNOWN)
def test_usMo_getPreIncarcerationSupervisionType_ignoreOutOfDateSentences( self): incarceration_period = StateIncarcerationPeriod.new_with_defaults( incarceration_period_id=1, admission_reason=StateIncarcerationPeriodAdmissionReason. PAROLE_REVOCATION, external_id='ip1', state_code='US_MO', admission_date=self.REVOCATION_DATE) supervision_sentence_parole = FakeUsMoSupervisionSentence.fake_sentence_from_sentence( StateSupervisionSentence.new_with_defaults( supervision_sentence_id=1, external_id=self.PAROLE_SENTENCE_EXTERNAL_ID, start_date=datetime.date(2017, 2, 1), supervision_type=StateSupervisionType.PROBATION), supervision_type=StateSupervisionType.PAROLE) old_incarceration_sentence = FakeUsMoIncarcerationSentence.fake_sentence_from_sentence( StateIncarcerationSentence.new_with_defaults( incarceration_sentence_id=1, external_id='US_MO', start_date=datetime.date(2017, 2, 1), completion_date=datetime.date(2017, 3, 4), status=StateSentenceStatus.COMPLETED), supervision_type=None # Terminated already ) self.assertEqual( StateSupervisionPeriodSupervisionType.PAROLE, us_mo_get_pre_incarceration_supervision_type( [old_incarceration_sentence], [supervision_sentence_parole], incarceration_period))
def test_get_month_supervision_type_sentence_supervision_ends_different_days( self): # Arrange supervision_period = StateSupervisionPeriod.new_with_defaults( supervision_period_id=1234, external_id='sp1', state_code='US_MO', start_date=(self.end_of_month_date - datetime.timedelta(days=60))) mid_month_date = self.end_of_month_date - datetime.timedelta(days=10) second_to_last_month_date = self.end_of_month_date - datetime.timedelta( days=1) incarceration_sentence = FakeUsMoIncarcerationSentence.fake_sentence_from_sentence( StateIncarcerationSentence.new_with_defaults( external_id='ss1', state_code='US_MO', start_date=supervision_period.start_date), supervision_type_spans=[ SupervisionTypeSpan( start_date=supervision_period.start_date, end_date=second_to_last_month_date, supervision_type=StateSupervisionType.PAROLE), SupervisionTypeSpan(start_date=second_to_last_month_date, end_date=None, supervision_type=None) ]) supervision_sentence = FakeUsMoSupervisionSentence.fake_sentence_from_sentence( StateSupervisionSentence.new_with_defaults( external_id='ss1', state_code='US_MO', start_date=supervision_period.start_date), supervision_type_spans=[ # Probation sentence starts after parole sentence ends SupervisionTypeSpan( start_date=supervision_period.start_date, end_date=mid_month_date, supervision_type=StateSupervisionType.PROBATION), SupervisionTypeSpan(start_date=mid_month_date, end_date=None, supervision_type=None) ]) # Act supervision_period_supervision_type = \ us_mo_get_month_supervision_type(self.end_of_month_date, supervision_sentences=[supervision_sentence], incarceration_sentences=[incarceration_sentence], supervision_period=supervision_period) # Assert # Since the probation sentence ends before the parole sentence, the last valid supervision type is PAROLE self.assertEqual(supervision_period_supervision_type, StateSupervisionPeriodSupervisionType.PAROLE)
def test_get_month_supervision_type_dual_ends_mid_month(self): # Arrange supervision_period = StateSupervisionPeriod.new_with_defaults( supervision_period_id=1234, external_id='sp1', state_code='US_MO', start_date=(self.end_of_month_date - datetime.timedelta(days=60))) second_to_last_month_date = self.end_of_month_date - datetime.timedelta( days=1) incarceration_sentence = FakeUsMoIncarcerationSentence.fake_sentence_from_sentence( StateIncarcerationSentence.new_with_defaults( external_id='ss1', state_code='US_MO', start_date=supervision_period.start_date), supervision_type_spans=[ SupervisionTypeSpan( start_date=supervision_period.start_date, end_date=second_to_last_month_date, supervision_type=StateSupervisionType.PAROLE), SupervisionTypeSpan(start_date=second_to_last_month_date, end_date=None, supervision_type=None) ]) supervision_sentence = FakeUsMoSupervisionSentence.fake_sentence_from_sentence( StateSupervisionSentence.new_with_defaults( external_id='ss1', state_code='US_MO', start_date=supervision_period.start_date), supervision_type_spans=[ # Probation sentence starts after parole sentence ends SupervisionTypeSpan( start_date=supervision_period.start_date, end_date=second_to_last_month_date, supervision_type=StateSupervisionType.PROBATION), SupervisionTypeSpan(start_date=second_to_last_month_date, end_date=None, supervision_type=None) ]) # Act supervision_period_supervision_type = \ us_mo_get_month_supervision_type(self.end_of_month_date, supervision_sentences=[supervision_sentence], incarceration_sentences=[incarceration_sentence], supervision_period=supervision_period) # Assert # Even though both sentences are terminated before the last day, we still return DUAL self.assertEqual(supervision_period_supervision_type, StateSupervisionPeriodSupervisionType.DUAL)
def _sup_sentence_with_type( self, supervision_type: Optional[StateSupervisionType] ) -> UsMoSupervisionSentence: base_sentence = StateSupervisionSentence.new_with_defaults( external_id=f'164735-20120627-{self.sentence_id_counter}', state_code='US_MO', start_date=datetime.date(year=2012, month=6, day=27)) mo_sentence = FakeUsMoSupervisionSentence.fake_sentence_from_sentence( base_sentence, supervision_type=supervision_type) self.sentence_id_counter += 1 return mo_sentence
def test_month_supervision_type_supervision_ends_middle_of_month(self) -> None: # Arrange supervision_start = self.end_of_month_date - datetime.timedelta(days=60) supervision_period = StateSupervisionPeriod.new_with_defaults( supervision_period_id=1234, external_id="sp1", state_code="US_MO", start_date=supervision_start, status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO, ) supervision_end_date_middle_of_month = ( self.start_of_month_date + datetime.timedelta(days=5) ) supervision_sentence = FakeUsMoSupervisionSentence.fake_sentence_from_sentence( StateSupervisionSentence.new_with_defaults( external_id="ss1", state_code="US_MO", start_date=supervision_start, status=StateSentenceStatus.PRESENT_WITHOUT_INFO, ), supervision_type_spans=[ SupervisionTypeSpan( start_date=supervision_start, end_date=supervision_end_date_middle_of_month, supervision_type=StateSupervisionType.PROBATION, ), # Incarcerated / suspended since middle of month SupervisionTypeSpan( start_date=supervision_end_date_middle_of_month, end_date=None, supervision_type=None, ), ], ) # Act supervision_period_supervision_type = us_mo_get_month_supervision_type( self.end_of_month_date, supervision_sentences=[supervision_sentence], incarceration_sentences=[], supervision_period=supervision_period, ) # Assert self.assertEqual( supervision_period_supervision_type, StateSupervisionPeriodSupervisionType.PROBATION, )
def test_get_month_supervision_type_parole_transitions_to_probation(self): # Arrange supervision_period = StateSupervisionPeriod.new_with_defaults( supervision_period_id=1234, external_id='sp1', state_code='US_MO', start_date=(self.end_of_month_date - datetime.timedelta(days=60))) parole_end_date_middle_of_month = self.start_of_month_date + datetime.timedelta( days=5) incarceration_sentence = FakeUsMoIncarcerationSentence.fake_sentence_from_sentence( StateIncarcerationSentence.new_with_defaults( external_id='ss1', state_code='US_MO', start_date=supervision_period.start_date), supervision_type_spans=[ SupervisionTypeSpan( start_date=supervision_period.start_date, end_date=parole_end_date_middle_of_month, supervision_type=StateSupervisionType.PAROLE), # Parole finishes middle of month SupervisionTypeSpan(start_date=parole_end_date_middle_of_month, end_date=None, supervision_type=None) ]) supervision_sentence = FakeUsMoSupervisionSentence.fake_sentence_from_sentence( StateSupervisionSentence.new_with_defaults( external_id='ss1', state_code='US_MO', start_date=parole_end_date_middle_of_month), supervision_type_spans=[ # Probation sentence starts after parole sentence ends SupervisionTypeSpan( start_date=parole_end_date_middle_of_month, end_date=None, supervision_type=StateSupervisionType.PROBATION) ]) # Act supervision_period_supervision_type = \ us_mo_get_month_supervision_type(self.end_of_month_date, supervision_sentences=[supervision_sentence], incarceration_sentences=[incarceration_sentence], supervision_period=supervision_period) # Assert self.assertEqual(supervision_period_supervision_type, StateSupervisionPeriodSupervisionType.PROBATION)
def test_get_month_supervision_type_dual(self): # Arrange supervision_period = StateSupervisionPeriod.new_with_defaults( supervision_period_id=1234, external_id='sp1', state_code='US_MO', start_date=(self.end_of_month_date - datetime.timedelta(days=60))) incarceration_sentence = FakeUsMoIncarcerationSentence.fake_sentence_from_sentence( StateIncarcerationSentence.new_with_defaults( external_id='ss1', state_code='US_MO', start_date=supervision_period.start_date), supervision_type_spans=[ SupervisionTypeSpan( start_date=supervision_period.start_date, end_date=self.start_of_next_month_date, supervision_type=StateSupervisionType.PAROLE), SupervisionTypeSpan(start_date=self.start_of_next_month_date, end_date=None, supervision_type=None) ]) supervision_sentence = FakeUsMoSupervisionSentence.fake_sentence_from_sentence( StateSupervisionSentence.new_with_defaults( external_id='ss1', state_code='US_MO', start_date=supervision_period.start_date), supervision_type_spans=[ SupervisionTypeSpan( start_date=supervision_period.start_date, end_date=self.start_of_next_month_date, supervision_type=StateSupervisionType.PROBATION), SupervisionTypeSpan(start_date=self.start_of_next_month_date, end_date=None, supervision_type=None) ]) # Act supervision_period_supervision_type = \ us_mo_get_month_supervision_type(self.end_of_month_date, supervision_sentences=[supervision_sentence], incarceration_sentences=[incarceration_sentence], supervision_period=supervision_period) # Assert self.assertEqual(supervision_period_supervision_type, StateSupervisionPeriodSupervisionType.DUAL)
def test_usMo_getPreIncarcerationSupervisionType_ignoreOutOfDateSentences( self): incarceration_period = StateIncarcerationPeriod.new_with_defaults( incarceration_period_id=1, admission_reason=StateIncarcerationPeriodAdmissionReason. PAROLE_REVOCATION, external_id='ip1', state_code='US_MO', admission_date=datetime.date(year=2019, month=9, day=13)) supervision_sentence_parole = FakeUsMoSupervisionSentence.fake_sentence_from_sentence( StateSupervisionSentence.new_with_defaults( supervision_sentence_id=1, external_id='1167633-20171012-2', start_date=datetime.date(2017, 2, 1), supervision_type=StateSupervisionType.PROBATION), supervision_type_spans=[ SupervisionTypeSpan( start_date=datetime.date(2017, 2, 1), end_date=None, supervision_type=StateSupervisionType.PAROLE) ]) old_incarceration_sentence = FakeUsMoIncarcerationSentence.fake_sentence_from_sentence( StateIncarcerationSentence.new_with_defaults( incarceration_sentence_id=1, external_id='US_MO', start_date=datetime.date(2017, 2, 1), completion_date=datetime.date(2017, 3, 4), status=StateSentenceStatus.COMPLETED), supervision_type_spans=[ SupervisionTypeSpan( start_date=datetime.date(2017, 2, 1), end_date=datetime.date(2017, 3, 4), supervision_type=StateSupervisionType.PAROLE), SupervisionTypeSpan(start_date=datetime.date(2017, 3, 4), end_date=None, supervision_type=None) ] # Terminated by revocation date ) self.assertEqual( StateSupervisionPeriodSupervisionType.PAROLE, us_mo_get_pre_incarceration_supervision_type( [old_incarceration_sentence], [supervision_sentence_parole], incarceration_period))
def test_usMo_getPostIncarcerationSupervisionType(self) -> None: incarceration_period = StateIncarcerationPeriod.new_with_defaults( incarceration_period_id=1, admission_reason=StateIncarcerationPeriodAdmissionReason.PAROLE_REVOCATION, external_id="ip1", state_code="US_MO", admission_date=datetime.date(year=2019, month=9, day=13), release_date=datetime.date(year=2020, month=1, day=11), status=StateIncarcerationPeriodStatus.PRESENT_WITHOUT_INFO, ) supervision_sentence_parole = ( FakeUsMoSupervisionSentence.fake_sentence_from_sentence( StateSupervisionSentence.new_with_defaults( state_code="US_MO", supervision_sentence_id=1, external_id="1167633-20171012-2", start_date=datetime.date(year=2020, month=1, day=11), supervision_type=StateSupervisionType.PROBATION, status=StateSentenceStatus.PRESENT_WITHOUT_INFO, ), supervision_type_spans=[ SupervisionTypeSpan( start_date=datetime.date(year=2020, month=1, day=11), end_date=None, supervision_type=StateSupervisionType.PAROLE, ) ], ) ) # Even though the supervision type of the sentence is PROBATION, we find that it's actually a PAROLE # sentence from the statuses. self.assertEqual( StateSupervisionPeriodSupervisionType.PAROLE, us_mo_get_post_incarceration_supervision_type( incarceration_sentences=[], supervision_sentences=[supervision_sentence_parole], incarceration_period=incarceration_period, ), )
def _sup_sentence_with_type( self, supervision_type: Optional[StateSupervisionType] ) -> UsMoSupervisionSentence: start_date = datetime.date(year=2012, month=6, day=27) base_sentence = StateSupervisionSentence.new_with_defaults( external_id=f"164735-20120627-{self.sentence_id_counter}", state_code="US_MO", start_date=datetime.date(year=2012, month=6, day=27), status=StateSentenceStatus.PRESENT_WITHOUT_INFO, ) mo_sentence = FakeUsMoSupervisionSentence.fake_sentence_from_sentence( base_sentence, supervision_type_spans=[ SupervisionTypeSpan( start_date=start_date, end_date=None, supervision_type=supervision_type, ) ], ) self.sentence_id_counter += 1 return mo_sentence
def test_get_month_supervision_type_sentence_supervision_ends_different_days( self, ) -> None: # Arrange supervision_start = self.end_of_month_date - datetime.timedelta(days=60) supervision_period = StateSupervisionPeriod.new_with_defaults( supervision_period_id=1234, external_id="sp1", state_code="US_MO", start_date=supervision_start, status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO, ) mid_month_date = self.end_of_month_date - datetime.timedelta(days=10) second_to_last_month_date = self.end_of_month_date - datetime.timedelta(days=1) incarceration_sentence = ( FakeUsMoIncarcerationSentence.fake_sentence_from_sentence( StateIncarcerationSentence.new_with_defaults( external_id="ss1", state_code="US_MO", start_date=supervision_period.start_date, status=StateSentenceStatus.PRESENT_WITHOUT_INFO, ), supervision_type_spans=[ SupervisionTypeSpan( start_date=supervision_start, end_date=second_to_last_month_date, supervision_type=StateSupervisionType.PAROLE, ), SupervisionTypeSpan( start_date=second_to_last_month_date, end_date=None, supervision_type=None, ), ], ) ) supervision_sentence = FakeUsMoSupervisionSentence.fake_sentence_from_sentence( StateSupervisionSentence.new_with_defaults( external_id="ss1", state_code="US_MO", start_date=supervision_period.start_date, status=StateSentenceStatus.PRESENT_WITHOUT_INFO, ), supervision_type_spans=[ # Probation sentence starts after parole sentence ends SupervisionTypeSpan( start_date=supervision_start, end_date=mid_month_date, supervision_type=StateSupervisionType.PROBATION, ), SupervisionTypeSpan( start_date=mid_month_date, end_date=None, supervision_type=None ), ], ) # Act supervision_period_supervision_type = us_mo_get_month_supervision_type( self.end_of_month_date, supervision_sentences=[supervision_sentence], incarceration_sentences=[incarceration_sentence], supervision_period=supervision_period, ) # Assert # Since the probation sentence ends before the parole sentence, the last valid supervision type is PAROLE self.assertEqual( supervision_period_supervision_type, StateSupervisionPeriodSupervisionType.PAROLE, )
def test_usMo_getPreIncarcerationSupervisionType_ignoreOutOfDateSentences( self, ) -> None: incarceration_period = StateIncarcerationPeriod.new_with_defaults( incarceration_period_id=1, admission_reason=StateIncarcerationPeriodAdmissionReason.PAROLE_REVOCATION, external_id="ip1", state_code="US_MO", admission_date=datetime.date(year=2019, month=9, day=13), status=StateIncarcerationPeriodStatus.PRESENT_WITHOUT_INFO, ) supervision_sentence_parole = ( FakeUsMoSupervisionSentence.fake_sentence_from_sentence( StateSupervisionSentence.new_with_defaults( state_code="US_MO", supervision_sentence_id=1, external_id="1167633-20171012-2", start_date=datetime.date(2017, 2, 1), supervision_type=StateSupervisionType.PROBATION, status=StateSentenceStatus.PRESENT_WITHOUT_INFO, ), supervision_type_spans=[ SupervisionTypeSpan( start_date=datetime.date(2017, 2, 1), end_date=None, supervision_type=StateSupervisionType.PAROLE, ) ], ) ) old_incarceration_sentence = ( FakeUsMoIncarcerationSentence.fake_sentence_from_sentence( StateIncarcerationSentence.new_with_defaults( state_code="US_MO", incarceration_sentence_id=1, external_id="is1", start_date=datetime.date(2017, 2, 1), completion_date=datetime.date(2017, 3, 4), status=StateSentenceStatus.COMPLETED, ), supervision_type_spans=[ SupervisionTypeSpan( start_date=datetime.date(2017, 2, 1), end_date=datetime.date(2017, 3, 4), supervision_type=StateSupervisionType.PAROLE, ), SupervisionTypeSpan( start_date=datetime.date(2017, 3, 4), end_date=None, supervision_type=None, ), ], # Terminated by revocation date ) ) self.assertEqual( StateSupervisionPeriodSupervisionType.PAROLE, us_mo_get_pre_incarceration_supervision_type( [old_incarceration_sentence], [supervision_sentence_parole], incarceration_period, ), )
def test_get_month_supervision_type_dual_ends_mid_month(self) -> None: # Arrange supervision_start = self.end_of_month_date - datetime.timedelta(days=60) supervision_period = StateSupervisionPeriod.new_with_defaults( supervision_period_id=1234, external_id="sp1", state_code="US_MO", start_date=supervision_start, status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO, ) second_to_last_month_date = self.end_of_month_date - datetime.timedelta(days=1) incarceration_sentence = ( FakeUsMoIncarcerationSentence.fake_sentence_from_sentence( StateIncarcerationSentence.new_with_defaults( external_id="ss1", state_code="US_MO", start_date=supervision_start, status=StateSentenceStatus.PRESENT_WITHOUT_INFO, ), supervision_type_spans=[ SupervisionTypeSpan( start_date=supervision_start, end_date=second_to_last_month_date, supervision_type=StateSupervisionType.PAROLE, ), SupervisionTypeSpan( start_date=second_to_last_month_date, end_date=None, supervision_type=None, ), ], ) ) supervision_sentence = FakeUsMoSupervisionSentence.fake_sentence_from_sentence( StateSupervisionSentence.new_with_defaults( external_id="ss1", state_code="US_MO", start_date=supervision_start, status=StateSentenceStatus.PRESENT_WITHOUT_INFO, ), supervision_type_spans=[ # Probation sentence starts after parole sentence ends SupervisionTypeSpan( start_date=supervision_start, end_date=second_to_last_month_date, supervision_type=StateSupervisionType.PROBATION, ), SupervisionTypeSpan( start_date=second_to_last_month_date, end_date=None, supervision_type=None, ), ], ) # Act supervision_period_supervision_type = us_mo_get_month_supervision_type( self.end_of_month_date, supervision_sentences=[supervision_sentence], incarceration_sentences=[incarceration_sentence], supervision_period=supervision_period, ) # Assert # Even though both sentences are terminated before the last day, we still return DUAL self.assertEqual( supervision_period_supervision_type, StateSupervisionPeriodSupervisionType.DUAL, )
def test_get_month_supervision_type_parole_transitions_to_probation(self) -> None: # Arrange start_date = self.end_of_month_date - datetime.timedelta(days=60) supervision_period = StateSupervisionPeriod.new_with_defaults( supervision_period_id=1234, external_id="sp1", state_code="US_MO", start_date=start_date, status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO, ) parole_end_date_middle_of_month = self.start_of_month_date + datetime.timedelta( days=5 ) incarceration_sentence = FakeUsMoIncarcerationSentence.fake_sentence_from_sentence( StateIncarcerationSentence.new_with_defaults( external_id="ss1", state_code="US_MO", start_date=start_date, status=StateSentenceStatus.PRESENT_WITHOUT_INFO, ), supervision_type_spans=[ SupervisionTypeSpan( start_date=start_date, end_date=parole_end_date_middle_of_month, supervision_type=StateSupervisionType.PAROLE, ), # Parole finishes middle of month SupervisionTypeSpan( start_date=parole_end_date_middle_of_month, end_date=None, supervision_type=None, ), ], ) supervision_sentence = FakeUsMoSupervisionSentence.fake_sentence_from_sentence( StateSupervisionSentence.new_with_defaults( external_id="ss1", state_code="US_MO", start_date=parole_end_date_middle_of_month, status=StateSentenceStatus.PRESENT_WITHOUT_INFO, ), supervision_type_spans=[ # Probation sentence starts after parole sentence ends SupervisionTypeSpan( start_date=parole_end_date_middle_of_month, end_date=None, supervision_type=StateSupervisionType.PROBATION, ) ], ) # Act supervision_period_supervision_type = us_mo_get_month_supervision_type( self.end_of_month_date, supervision_sentences=[supervision_sentence], incarceration_sentences=[incarceration_sentence], supervision_period=supervision_period, ) # Assert self.assertEqual( supervision_period_supervision_type, StateSupervisionPeriodSupervisionType.PROBATION, )
def test_most_recent_supervision_type_two_sentences_same_transition_day_one_different( self, ) -> None: # Arrange start_date = self.upper_bound_date - datetime.timedelta(days=5) transition_date_1 = self.upper_bound_date - datetime.timedelta(days=3) transition_date_2 = self.upper_bound_date - datetime.timedelta(days=1) incarceration_sentence = ( FakeUsMoIncarcerationSentence.fake_sentence_from_sentence( StateIncarcerationSentence.new_with_defaults( external_id="ss1", state_code="US_MO", start_date=start_date, status=StateSentenceStatus.PRESENT_WITHOUT_INFO, ), supervision_type_spans=[ SupervisionTypeSpan( start_date=start_date, end_date=transition_date_2, supervision_type=StateSupervisionType.PAROLE, ), SupervisionTypeSpan( start_date=transition_date_2, end_date=None, supervision_type=None, ), ], ) ) supervision_sentence_1 = ( FakeUsMoSupervisionSentence.fake_sentence_from_sentence( StateSupervisionSentence.new_with_defaults( external_id="ss1", state_code="US_MO", start_date=start_date, status=StateSentenceStatus.PRESENT_WITHOUT_INFO, ), supervision_type_spans=[ SupervisionTypeSpan( start_date=start_date, end_date=transition_date_1, supervision_type=StateSupervisionType.PROBATION, ), SupervisionTypeSpan( start_date=transition_date_1, end_date=None, supervision_type=None, ), ], ) ) supervision_sentence_2 = ( FakeUsMoSupervisionSentence.fake_sentence_from_sentence( StateSupervisionSentence.new_with_defaults( external_id="ss1", state_code="US_MO", start_date=start_date, status=StateSentenceStatus.PRESENT_WITHOUT_INFO, ), supervision_type_spans=[ SupervisionTypeSpan( start_date=start_date, end_date=transition_date_2, supervision_type=StateSupervisionType.PROBATION, ), SupervisionTypeSpan( start_date=transition_date_2, end_date=None, supervision_type=StateSupervisionType.PAROLE, ), ], ) ) # Act supervision_period_supervision_type = us_mo_get_most_recent_supervision_period_supervision_type_before_upper_bound_day( upper_bound_exclusive_date=self.upper_bound_date, lower_bound_inclusive_date=None, supervision_sentences=[supervision_sentence_1, supervision_sentence_2], incarceration_sentences=[incarceration_sentence], ) # Assert # Since the probation sentence ends before the parole sentence, the last valid supervision type is PAROLE self.assertEqual( supervision_period_supervision_type, StateSupervisionPeriodSupervisionType.PAROLE, )
def test_get_month_supervision_type_dual(self): # Arrange supervision_period = StateSupervisionPeriod.new_with_defaults( supervision_period_id=1234, external_id="sp1", state_code="US_MO", start_date=(self.end_of_month_date - datetime.timedelta(days=60)), status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO, ) incarceration_sentence = ( FakeUsMoIncarcerationSentence.fake_sentence_from_sentence( StateIncarcerationSentence.new_with_defaults( external_id="ss1", state_code="US_MO", start_date=supervision_period.start_date, status=StateSentenceStatus.PRESENT_WITHOUT_INFO, ), supervision_type_spans=[ SupervisionTypeSpan( start_date=supervision_period.start_date, end_date=self.start_of_next_month_date, supervision_type=StateSupervisionType.PAROLE, ), SupervisionTypeSpan( start_date=self.start_of_next_month_date, end_date=None, supervision_type=None, ), ], )) supervision_sentence = FakeUsMoSupervisionSentence.fake_sentence_from_sentence( StateSupervisionSentence.new_with_defaults( external_id="ss1", state_code="US_MO", start_date=supervision_period.start_date, status=StateSentenceStatus.PRESENT_WITHOUT_INFO, ), supervision_type_spans=[ SupervisionTypeSpan( start_date=supervision_period.start_date, end_date=self.start_of_next_month_date, supervision_type=StateSupervisionType.PROBATION, ), SupervisionTypeSpan( start_date=self.start_of_next_month_date, end_date=None, supervision_type=None, ), ], ) # Act supervision_period_supervision_type = us_mo_get_month_supervision_type( self.end_of_month_date, supervision_sentences=[supervision_sentence], incarceration_sentences=[incarceration_sentence], supervision_period=supervision_period, ) # Assert self.assertEqual( supervision_period_supervision_type, StateSupervisionPeriodSupervisionType.DUAL, )