예제 #1
0
    def test_report(self, mock_log, mock_parser, mock_cfg):
        date_from = datetime(2020, 1, 1, tzinfo=timezone.utc)
        date_to = datetime(2020, 1, 2, tzinfo=timezone.utc)
        ns = Namespace(subcmd="report", date_from=date_from, date_to=date_to)
        dispatch(mock_log, mock_parser, ns, mock_cfg)

        mock_log.report.assert_called_once_with(date_from, date_to)
예제 #2
0
파일: __init__.py 프로젝트: dotcs/worklog
def run() -> None:
    """ Main method """
    logger = configure_logger()
    parser = get_arg_parser()

    cli_args = parser.parse_args()
    log_level = wc.LOG_LEVELS[min(cli_args.verbosity, len(wc.LOG_LEVELS) - 1)]
    logger.setLevel(log_level)

    logger.debug(f"Parsed CLI arguments: {cli_args}")
    logger.debug(f"Path to config files: {wc.CONFIG_FILES}")

    if cli_args.subcmd is None:
        parser.print_help()
        return

    cfg = ConfigParser()
    cfg.read(wc.CONFIG_FILES)

    with StringIO() as ss:
        cfg.write(ss)
        ss.seek(0)
        logger.debug(f"Config content:\n{ss.read()}\nEOF")

    worklog_fp = os.path.expanduser(cfg.get("worklog", "path"))
    log = Log(worklog_fp)

    limits = json.loads(cfg.get("workday", "auto_break_limit_minutes"))
    durations = json.loads(cfg.get("workday", "auto_break_duration_minutes"))
    log.auto_break = AutoBreak(limits, durations)

    dispatch(log, parser, cli_args, cfg)
예제 #3
0
    def test_log_all(self, mock_log, mock_parser, mock_cfg):
        mock_cfg.get.side_effect = ["10"]  # worklog.no_pager_max_entries
        ns = Namespace(subcmd="log",
                       no_pager=False,
                       all=True,
                       category=None,
                       number=5)
        dispatch(mock_log, mock_parser, ns, mock_cfg)

        mock_log.log.assert_called_once_with(-1, True, None)
예제 #4
0
    def test_log_large_n(self, mock_log, mock_parser, mock_cfg):
        """It should automatically use pager if number > no_pager_max_entries"""
        mock_cfg.get.side_effect = ["10"]  # worklog.no_pager_max_entries
        ns = Namespace(subcmd="log",
                       no_pager=False,
                       all=False,
                       category=None,
                       number=20)
        dispatch(mock_log, mock_parser, ns, mock_cfg)

        mock_log.log.assert_called_once_with(20, True, None)
예제 #5
0
    def test_status_yesterday(self, mock_log, mock_parser, mock_cfg):
        mock_cfg.get.side_effect = ["8.0", "10.0"]
        ns = Namespace(subcmd="status", fmt=None, yesterday=True, date=None)
        dispatch(mock_log, mock_parser, ns, mock_cfg)

        expected_query_date = datetime.today().date() - timedelta(days=1)

        mock_log.status.assert_called_once_with(8.0,
                                                10.0,
                                                fmt=None,
                                                query_date=expected_query_date)
예제 #6
0
    def test_invalid(self, mock_log, mock_parser, mock_cfg):
        ns = Namespace(
            subcmd="session",
            type="invalid_value",
            offset_minutes=0,
            time=None,
            force=False,
        )
        dispatch(mock_log, mock_parser, ns, mock_cfg)

        mock_log.commit.assert_not_called()
예제 #7
0
    def test_start_with_offset(self, mock_log, mock_parser, mock_cfg):
        ns = Namespace(subcmd="session",
                       type="stop",
                       offset_minutes=-11,
                       time=None,
                       force=False)
        dispatch(mock_log, mock_parser, ns, mock_cfg)

        mock_log.commit.assert_called_once_with("session",
                                                "stop",
                                                -11,
                                                None,
                                                force=False)
예제 #8
0
    def test_start_forced(self, mock_log, mock_parser, mock_cfg):
        ns = Namespace(
            subcmd="session",
            type="stop",
            offset_minutes=0,
            time=None,
            force=True,
        )
        dispatch(mock_log, mock_parser, ns, mock_cfg)

        mock_log.commit.assert_called_once_with("session",
                                                "stop",
                                                0,
                                                None,
                                                force=True)
예제 #9
0
    def test_status_fixed_date(self, mock_log, mock_parser, mock_cfg):
        mock_cfg.get.side_effect = ["8.0", "10.0"]
        ns = Namespace(
            subcmd="status",
            fmt=None,
            yesterday=False,
            date=datetime(2020, 1, 1, tzinfo=timezone.utc),
        )
        dispatch(mock_log, mock_parser, ns, mock_cfg)

        expected_query_date = date(2020, 1, 1)

        mock_log.status.assert_called_once_with(8.0,
                                                10.0,
                                                fmt=None,
                                                query_date=expected_query_date)
예제 #10
0
    def test_start_with_time(self, mock_log, mock_parser, mock_cfg):
        ns = Namespace(
            subcmd="session",
            type="stop",
            offset_minutes=0,
            time=datetime(2020, 1, 1, tzinfo=timezone.utc),
            force=False,
        )
        dispatch(mock_log, mock_parser, ns, mock_cfg)

        mock_log.commit.assert_called_once_with("session",
                                                "stop",
                                                0,
                                                datetime(2020,
                                                         1,
                                                         1,
                                                         tzinfo=timezone.utc),
                                                force=False)
예제 #11
0
    def test_stop(self, mock_log, mock_parser, mock_cfg):
        """It should be possible to stop a task"""
        ns = Namespace(
            subcmd="task",
            type="stop",
            auto_stop=False,
            offset_minutes=0,
            time=None,
            id="foobar",
        )
        dispatch(mock_log, mock_parser, ns, mock_cfg)

        mock_log.stop_active_tasks.assert_not_called()
        mock_log.commit.assert_called_once_with("task",
                                                "stop",
                                                0,
                                                None,
                                                identifier="foobar")
예제 #12
0
    def test_start_with_auto_stop(self, mock_log, mock_parser, mock_cfg):
        """
        It should be possible to start a new task and auto stop all
        currently runnning tasks.
        """
        ns = Namespace(
            subcmd="task",
            type="start",
            auto_stop=True,
            offset_minutes=0,
            time=None,
            id="foobar",
        )
        dispatch(mock_log, mock_parser, ns, mock_cfg)

        mock_log.stop_active_tasks.assert_called_once()
        mock_log.commit.assert_called_once_with("task",
                                                "start",
                                                0,
                                                None,
                                                identifier="foobar")
예제 #13
0
    def test_doctor(self, mock_log, mock_parser, mock_cfg):
        ns = Namespace(subcmd="doctor")
        dispatch(mock_log, mock_parser, ns, mock_cfg)

        mock_log.doctor.assert_called_once()
예제 #14
0
    def test_report_task_by_id(self, mock_log, mock_parser, mock_cfg):
        """It should be possible to report infos about a single task id."""
        ns = Namespace(subcmd="task", type="report", id="foobar")
        dispatch(mock_log, mock_parser, ns, mock_cfg)

        mock_log.task_report.assert_called_once_with("foobar")
예제 #15
0
    def test_list_tasks(self, mock_log, mock_parser, mock_cfg):
        """It should be possible to list tasks."""
        ns = Namespace(subcmd="task", type="list")
        dispatch(mock_log, mock_parser, ns, mock_cfg)

        mock_log.list_tasks.assert_called_once()