Exemplo n.º 1
0
def test_should_save_shift_start(shift_repo_mock: mock.Mock) -> None:
    input_dto = use_cases.StartingShiftUseCase.InputDTO(
        category=entities.Category(name='category1'))

    with freezegun.freeze_time('2010-01-01'):
        use_cases.StartingShiftUseCase().execute(input_dto)

    shift_repo_mock.save.assert_called_once_with(
        entities.Shift(category=entities.Category('category1'),
                       start_time=datetime.datetime(2010, 1, 1)))
Exemplo n.º 2
0
def test_should_end_shift(shift_repo_mock: mock.Mock) -> None:
    shift_repo_mock.get_last.return_value = entities.Shift(
        category=entities.Category(name='A'),
        start_time=datetime.datetime(2010, 1, 1),
    )

    with freezegun.freeze_time('2010-01-01 00:05'):
        use_cases.EndingShiftUseCase().execute()

    shift_repo_mock.save.assert_called_once_with(
        entities.Shift(
            category=entities.Category('A'),
            start_time=datetime.datetime(2010, 1, 1),
            end_time=datetime.datetime(2010, 1, 1, 0, 5),
        ))
Exemplo n.º 3
0
 def _line_to_shift(self, line: str) -> entities.Shift:
     parts = line.strip().split(',')
     category_name = parts[0]
     start = datetime.datetime.strptime(parts[1], DATETIME_FORMAT)
     end = datetime.datetime.strptime(parts[2], DATETIME_FORMAT) if parts[2] != 'null' else None
     return entities.Shift(
         category=entities.Category(name=category_name), start_time=start, end_time=end
     )
Exemplo n.º 4
0
def test_completed_shift_should_be_saved(tmp_path: str) -> None:
    file_path = os.path.join(tmp_path, 'aa.txt')
    shift_repo = repositories.FileShiftRepository(file_path)

    shift_repo.save(
        entities.Shift(
            category=entities.Category(name='AA'),
            start_time=datetime.datetime(2010, 1, 1),
            end_time=datetime.datetime(2010, 1, 1, 0, 5, 0),
        ))

    with open(file_path) as data_file:
        file_text = data_file.read()
    assert file_text == 'AA,2010-01-01 00:00:00,2010-01-01 00:05:00\n'
Exemplo n.º 5
0
def shift() -> entities.Shift:
    return entities.Shift(category=entities.Category(name='A'))