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 get_month_supervision_type( any_date_in_month: date, supervision_sentences: List[StateSupervisionSentence], incarceration_sentences: List[StateIncarcerationSentence], supervision_period: StateSupervisionPeriod ) -> StateSupervisionPeriodSupervisionType: """Supervision type can change over time even if the period does not change. This function calculates the supervision type that a given supervision period represents during the month that |any_date_in_month| falls in. The objects / info we use to determine supervision type may be state-specific. Args: any_date_in_month: (date) Any day in the month to consider supervision_period: (StateSupervisionPeriod) The supervision period we want to associate a supervision type with supervision_sentences: (List[StateSupervisionSentence]) All supervision sentences for a given person. """ if supervision_period.state_code == 'US_MO': return us_mo_get_month_supervision_type(any_date_in_month, supervision_sentences, incarceration_sentences, supervision_period) if supervision_period.state_code == 'US_ID': return (supervision_period.supervision_period_supervision_type if supervision_period.supervision_period_supervision_type else StateSupervisionPeriodSupervisionType.INTERNAL_UNKNOWN) return get_month_supervision_type_default(any_date_in_month, supervision_sentences, incarceration_sentences, supervision_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 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_month_supervision_type_supervision_ends_middle_of_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)), 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_period.start_date, status=StateSentenceStatus.PRESENT_WITHOUT_INFO, ), supervision_type_spans=[ SupervisionTypeSpan( start_date=supervision_period.start_date, 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_month_supervision_type_no_sentences(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))) # Act supervision_period_supervision_type = \ us_mo_get_month_supervision_type(self.end_of_month_date, supervision_sentences=[], incarceration_sentences=[], supervision_period=supervision_period) # Assert self.assertEqual( supervision_period_supervision_type, StateSupervisionPeriodSupervisionType.INTERNAL_UNKNOWN)
def test_month_supervision_type_no_sentences(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, ) # Act supervision_period_supervision_type = us_mo_get_month_supervision_type( self.end_of_month_date, supervision_sentences=[], incarceration_sentences=[], supervision_period=supervision_period, ) # Assert self.assertEqual( supervision_period_supervision_type, StateSupervisionPeriodSupervisionType.INTERNAL_UNKNOWN, )