Пример #1
0
    def test_ok(self):
        logger = logging.getLogger("test_logger")
        with patch.object(logger, "error") as mock_logger:
            fp = self._get_testdata_fp("doctor_session_ok")
            instance = Log(fp, logger=logger)
            instance.doctor()

            mock_logger.assert_not_called()
Пример #2
0
def dispatch(
    log: Log, parser: ArgumentParser, cli_args: Namespace, cfg: ConfigParser
) -> None:
    """
    Dispatch request to Log instance based on CLI arguments and
    configuration values.
    """
    if cli_args.subcmd == wc.SUBCMD_SESSION:
        if cli_args.type in [wc.TOKEN_START, wc.TOKEN_STOP]:
            log.commit(
                wc.TOKEN_SESSION,
                cli_args.type,
                cli_args.offset_minutes,
                cli_args.time,
                force=cli_args.force,
            )
    elif cli_args.subcmd == wc.SUBCMD_TASK:
        if cli_args.type in [wc.TOKEN_START, wc.TOKEN_STOP]:
            if cli_args.type == wc.TOKEN_START and cli_args.auto_stop:
                commit_dt = calc_log_time(cli_args.offset_minutes, cli_args.time)
                log.stop_active_tasks(commit_dt)
            log.commit(
                wc.TOKEN_TASK,
                cli_args.type,
                cli_args.offset_minutes,
                cli_args.time,
                identifier=cli_args.id,
            )
        elif cli_args.type == "list":
            log.list_tasks()
        elif cli_args.type == "report":
            log.task_report(cli_args.id)
    elif cli_args.subcmd == wc.SUBCMD_STATUS:
        hours_target = float(cfg.get("workday", "hours_target"))
        hours_max = float(cfg.get("workday", "hours_max"))
        fmt = cli_args.fmt
        query_date = date.today()
        if cli_args.yesterday:
            query_date -= timedelta(days=1)
        elif cli_args.date:
            query_date = cli_args.date.date()
        log.status(hours_target, hours_max, query_date=query_date, fmt=fmt)
    elif cli_args.subcmd == wc.SUBCMD_DOCTOR:
        log.doctor()
    elif cli_args.subcmd == wc.SUBCMD_LOG:
        n = cli_args.number
        no_pager_max_entries = int(cfg.get("worklog", "no_pager_max_entries"))
        use_pager = not cli_args.no_pager and (cli_args.all or n > no_pager_max_entries)
        categories = cli_args.category
        if not cli_args.all:
            log.log(cli_args.number, use_pager, categories)
        else:
            log.log(-1, use_pager, categories)
    elif cli_args.subcmd == wc.SUBCMD_REPORT:
        log.report(cli_args.date_from, cli_args.date_to)
Пример #3
0
    def test_wrong_order(self):
        logger = logging.getLogger("test_logger")
        with patch.object(logger, "error") as mock_logger:
            fp = self._get_testdata_fp("doctor_session_wrong_order")
            instance = Log(fp, logger=logger)
            instance.doctor()

            calls = (call(
                ErrMsg.WRONG_SESSION_ORDER.value.format(date="2020-01-01")), )

            mock_logger.assert_has_calls(calls)
Пример #4
0
    def test_stop_entry_missing_single(self):
        logger = logging.getLogger("test_logger")
        with patch.object(logger, "error") as mock_logger:
            fp = self._get_testdata_fp("doctor_session_stop_missing_single")
            instance = Log(fp, logger=logger)
            instance.doctor()

            calls = (call(
                ErrMsg.MISSING_SESSION_ENTRY.value.format(
                    type=wc.TOKEN_STOP, date="2020-01-01")), )

            mock_logger.assert_has_calls(calls)
Пример #5
0
    def test_task_start_entry_missing(self):
        logger = logging.getLogger("test_logger")
        with patch.object(logger, "error") as mock_logger:
            fp = self._get_testdata_fp("doctor_task_start_missing")
            instance = Log(fp, logger=logger)
            instance.doctor()

            calls = (call(
                ErrMsg.MISSING_TASK_ENTRY.value.format(type=wc.TOKEN_START,
                                                       date="2020-01-01",
                                                       task_id="task1")), )

            mock_logger.assert_has_calls(calls)