def test_edit_entry_ignored(): entries_collection = EntriesCollection( TimesheetParser(), "20.01.2014\n_internal 0800-0900 Fix coffee machine" ) entries_collection[datetime.date(2014, 1, 20)][0].ignored = True assert entries_collection.parser.to_text(entries_collection.lines[-1]) == "? _internal 0800-0900 Fix coffee machine"
def test_entries_collection_from_string(): entries_collection = EntriesCollection( TimesheetParser(), "20.01.2014\n_internal 0900-1000 Fix coffee machine\ntaxi 2 Work a bit" ) assert len(entries_collection) == 1 assert len(entries_collection[datetime.date(2014, 1, 20)]) == 2
def test_edit_entry_alias(): entries_collection = EntriesCollection( TimesheetParser(), "20.01.2014\n_internal 0800-0900 Fix coffee machine" ) entries_collection[datetime.date(2014, 1, 20)][0].alias = 'taxi' assert entries_collection.parser.to_text(entries_collection.lines[-1]) == "taxi 0800-0900 Fix coffee machine"
def test_edit_entry_description(): entries_collection = EntriesCollection( TimesheetParser(), "20.01.2014\n_internal 0800-0900 Fix coffee machine" ) entries_collection[datetime.date(2014, 1, 20)][0].description = "Fix printer" assert entries_collection.parser.to_text(entries_collection.lines[-1]) == "_internal 0800-0900 Fix printer"
def test_remove_last_entry_removes_date(): entries_collection = EntriesCollection( TimesheetParser(), "20.01.2014\n_internal 0800-0900 Fix coffee machine" ) entries_date = datetime.date(2014, 1, 20) del entries_collection[entries_date][0] assert len(entries_collection.lines) == 0
def test_remove_entry_removes_line(): entries_collection = EntriesCollection( TimesheetParser(), "20.01.2014\n_internal 0800-0900 Fix coffee machine\ntaxi 2 Work a bit" ) entries_date = datetime.date(2014, 1, 20) del entries_collection[entries_date][1] assert len(entries_collection[entries_date]) == 1 assert entries_collection.parser.to_text(entries_collection.lines[-1]) == "_internal 0800-0900 Fix coffee machine"
def test_add_entry_to_entries_collection(): entries_collection = EntriesCollection( TimesheetParser(), "20.01.2014\n_internal 0800-0900 Fix coffee machine" ) entries_collection[datetime.date(2014, 1, 20)].append( Entry('taxi', 4, 'Work a bit') ) assert len(entries_collection[datetime.date(2014, 1, 20)]) == 2
def test_get_entries_excluding_pushed_excludes_pushed(): contents = """01.04.2013 foo 2 bar = bar 0900-1000 bar foo 1 bar""" entries = EntriesCollection(TimesheetParser(), contents) timesheet = Timesheet(entries) timesheet_entries = timesheet.entries.filter(pushed=False) assert len(list(timesheet_entries.values())[0]) == 2
def test_remove_date_removes_lines(): entries_collection = EntriesCollection(TimesheetParser(), """20.01.2014 _internal 0800-0900 Fix coffee machine taxi 2 Work a bit 21.01.2014 _internal 0800-0900 Fix printer""") entries_date = datetime.date(2014, 1, 20) del entries_collection[entries_date] assert len(entries_collection.lines) == 2 assert entries_collection.parser.to_text(entries_collection.lines[0]) == "21.01.2014"
def test_insert_to_top(): parser = TimesheetParser(add_date_to_bottom=False) entries_collection = EntriesCollection(parser, """20.01.2014 _internal 0800-0900 Fix coffee machine""") entries_date = datetime.date(2014, 1, 21) entry_line = Entry('taxi', 4, 'Work a bit') entries_collection[entries_date].append(entry_line) assert entries_collection.parser.to_text(entries_collection.lines[0]) == "21.01.2014" assert entries_collection.parser.to_text(entries_collection.lines[1]) == "" assert entries_collection.lines[2] == entry_line
def test_failed_entry_doesnt_change_continuation_entry_time(cli, entries_file): entries_file.write("""03/07/2017 alias_1 0800-0900 Using a correct alias fail -1000 And a failing alias """) cli('commit') entries = EntriesCollection(TimesheetParser(), entries=entries_file.read())[datetime.date( 2017, 7, 3)] assert entries[0].pushed assert not entries[1].pushed assert entries[1].duration == (None, datetime.time(10))
def test_non_current_workday_entries(): entries = EntriesCollection(TimesheetParser(), """01.01.2014\nfoo 2 bar""") timesheet = Timesheet(entries) assert len(timesheet.entries.filter(current_workday=False)) == 1
def test_get_entries(): entries = EntriesCollection(TimesheetParser(), """10.10.2014\nfoo 2 bar\n11.10.2014\nfoo 1 bar""") timesheet = Timesheet(entries) assert len(timesheet.entries.filter(date=datetime.date(2014, 10, 10))) == 1
def test_timesheet_with_entries(): entries = EntriesCollection(TimesheetParser(), """10.10.2014\nfoo 2 bar\n11.10.2014\nfoo 1 bar""") timesheet = Timesheet(entries) assert len(timesheet.entries) == 2