def __init__(self, id, start_time, notes, table_ids, json): self.id = id self.start_time = start_time self.notes = Note(notes) self.json = json self.tables = [] for table_id in table_ids: t = Table.get_table_by_id(table_id) self.tables.append(t) t.add_reservation(self)
def test_next_string_multiple_reservations_single_table_after(): test_note = Note(None) table1 = [1, 2] table2 = [3, 4] time1 = datetime.strptime('Apr 1 2020 7:30PM', '%b %d %Y %I:%M%p') time2 = datetime.strptime('Apr 1 2020 7:45PM', '%b %d %Y %I:%M%p') res1 = (table1, time1) res2 = (table2, time2) assert test_note._next_string([res1, res2]) == "# Next: T1T2@7:30PM, T3T4@7:45PM"
def test_remove_header_only_next_string(): test_note = Note("# Next: T1@7:45PM") assert test_note.remove_header() == None
def test_remove_header_only_out_string(): test_note = Note("# Out @ 7:45PM") assert test_note.remove_header() == None
def test_remove_header_no_current_note(): test_note = Note(None) assert test_note.remove_header() == None
def test_has_header_returns_true_header_with_notes(): test_note = Note("# Out @ 7:45PM\n# Next: T1@7:45PM\nSome notes.") assert test_note.has_header() == True
def test_has_header_returns_true_only_header(): test_note = Note("# Out @ 7:45PM\n# Next: T1@7:45PM") assert test_note.has_header() == True
def test_has_header_returns_true_only_nextstring(): test_note = Note("# Next: T1@7:45PM") assert test_note.has_header() == True
def test_notes_has_header_returns_false_on_none_note(): test_note = Note(None) assert test_note.has_header() == False
def test_set_header_with_note(): test_note = Note("# Out @ 7:45PM\n# Next: T1@7:45PM\nSome notes.") assert test_note.set_header("# Out @ 6:45PM", "# Next: T1@7:00PM") == \ "# Out @ 6:45PM\n# Next: T1@7:00PM\nSome notes."
def test_set_header_with_multiple_line_note(): test_note = Note( "# Out @ 7:45PM\n# Next: T1@7:45PM\nSome notes.\nSome other notes.") assert test_note.set_header("# Out @ 6:45PM", "# Next: T1@7:00PM") == \ "# Out @ 6:45PM\n# Next: T1@7:00PM\nSome notes.\nSome other notes."
def test_set_header_only_next_string(): test_note = Note("# Next: T1@7:45PM") assert test_note.set_header( "# Out @ 6:45PM", "# Next: T1@7:00PM") == "# Out @ 6:45PM\n# Next: T1@7:00PM"
def test_set_header_no_current_note(): test_note = Note(None) assert test_note.set_header( "# Out @ 6:45PM", "# Next: T1@7:00PM") == "# Out @ 6:45PM\n# Next: T1@7:00PM"
def empty_note(): return Note(None)
def test_remove_header_with_note(): test_note = Note("# Out @ 7:45PM\n# Next: T1@7:45PM\nSome notes.") assert test_note.remove_header() == 'Some notes.'
def test_has_header_returns_true_only_outstring(): test_note = Note("# Out @ 7:45PM") assert test_note.has_header() == True
def test_remove_header_with_multiple_line_note(): test_note = Note( "# Out @ 7:45PM\n# Next: T1@7:45PM\nSome notes.\nSome other notes.") assert test_note.remove_header() == "Some notes.\nSome other notes."
class Reservation: def __init__(self, id, start_time, notes, table_ids, json): self.id = id self.start_time = start_time self.notes = Note(notes) self.json = json self.tables = [] for table_id in table_ids: t = Table.get_table_by_id(table_id) self.tables.append(t) t.add_reservation(self) def update_time_notes(self, setup_minutes=5): """ Add notes Sort out different cases """ # TODO: change this. I want to calculate out_time by getting the # generate out string and next string #out_time = datetime.DateTime next_reservations = self.get_next_reservations() if len(next_reservations) < 1: # There are no reservations after -> remove the note header if it # exists and exit early self.notes.remove_header() return elif len(next_reservations) == 1: if len(self.tables) > 1: # the current reservation uses more than one table. allow # setup_minutes minutes for setup out_time = next_reservations[0].start_time - timedelta( minutes=setup_minutes) else: out_time = next_reservations[0].start_time elif len(next_reservations) > 1: if len(self.tables) > 1: # more than one of the tables being used by this reservation is # required for a proceeding reservation. allow setup_minutes # minutes for setup from the EARLIEST next_reservation out_time = min(next_reservations, key=lambda r: r.start_time ).start_time - timedelta(minutes=setup_minutes) else: # the current table is part of a reservation using multiple # tables. allow setup_minutes minutes for setup out_time = next_reservations[0].start_time - timedelta( minutes=setup_minutes) else: out_time = next_reservations[0].start_time self.notes.generate_note(out_time, (([table.number for table in res.tables], res.start_time) for res in next_reservations)) def get_next_reservations(self): # TODO: only returns 1 reservation if the start_time's are the same. is # this the best way to handle this? return [ table.get_reservation_after(self.start_time) for table in self.tables if table.get_reservation_after(self.start_time) ]