Beispiel #1
0
    def test_get_diff_should_return_timedelta_if_valid_request(self) -> None:
        # ARRANGE
        first_date: date = date(2001, 1, 1)
        second_date: date = date(2003, 1, 1)
        expected_timedelta: timedelta = first_date - second_date

        # ACT
        ret_actual: timedelta = DateUtils.get_diff(first_date, second_date)

        # ASSERT
        self.assertEqual(expected_timedelta, ret_actual)
Beispiel #2
0
    def test_get_diff_should_return_none_if_invalid_request(self) -> None:
        # ARRANGE
        normal_date: date = date(2001, 1, 1)
        none_first_date: date = None
        none_second_date: date = None
        invalid_type_first_date: int = 1
        invalid_type_second_date: int = 1

        # ACT
        ret_both_none_case: date = DateUtils.get_diff(none_first_date,
                                                      none_second_date)
        ret_first_none_case: date = DateUtils.get_diff(none_first_date,
                                                       normal_date)
        ret_second_none_case: date = DateUtils.get_diff(
            normal_date, none_second_date)
        ret_both_invalid_type_case: date = DateUtils.get_diff(
            invalid_type_first_date, invalid_type_second_date)
        ret_invalid_type_first_case: date = DateUtils.get_diff(
            invalid_type_first_date, normal_date)
        ret_invalid_type_second_case: date = DateUtils.get_diff(
            normal_date, invalid_type_second_date)

        # ASSERT
        self.assertIsNone(ret_both_none_case)
        self.assertIsNone(ret_first_none_case)
        self.assertIsNone(ret_second_none_case)
        self.assertIsNone(ret_invalid_type_first_case)
        self.assertIsNone(ret_invalid_type_second_case)
Beispiel #3
0
 def set_readonly_props(self) -> None:
     if not hasattr(self, 'start_date') \
             or not hasattr(self, 'end_date') \
             or not hasattr(self, 'start_price') \
             or not hasattr(self, 'end_price') \
             or not hasattr(self, 'no_of_shares') \
             or not hasattr(self, 'action'):
         return
     delta: timedelta = DateUtils.get_diff(self._end_date, self._start_date)
     if self._action == AppConsts.ACTION_BUY:
         self._net_change_in_price = NumberUtils.round(self._end_price -
                                                       self._start_price)
     elif self._action == AppConsts.ACTION_SELL:
         self._net_change_in_price = NumberUtils.round(self._start_price -
                                                       self._end_price)
     self._year = self._end_date.year
     self._quarter = DateUtils.get_quarter(self._end_date.month)
     self._month = self._end_date.month
     self._hold_length_days = delta.days if delta else 0
     self._change_in_capital = NumberUtils.round(self._net_change_in_price *
                                                 self._no_of_shares)
     self._has_profit = (self._change_in_capital > 0)