def test_person_location_priority_is_used_to_queue(): p = Person(Name='calvin') now_dt = arrow.get('2014-01-01T09:09:00.000-05:00') tw = PersonTimeWindow(LocationName='kitchen', Priority=100, ical=ical_event, CompareDateTime=now_dt) p.add_window(tw) tw = PersonTimeWindow(LocationName='bedroom', Priority=200, ical=ical_event, CompareDateTime=now_dt) p.add_window(tw) pm = PersonManager() pm.update_window_set(p) with patch.object(Scheduler, 'get_messages', return_value=[mock_message1]): runner = CliRunner() result = runner.invoke(cli, obj=Config(), args=[ '--location_name', 'test', '--simulate_dt', now_dt.isoformat(), 'queue' ]) if result.exit_code > 0: exc_type, exc_value, exc_traceback = result.exc_info logging.error( traceback.format_exception(exc_type, exc_value, exc_traceback)) assert 'Publishing message for person calvin to location bedroom' in \ result.output
def test_add_multiple_returns_correct_number(): p = Person(Name='calvin') now_dt = arrow.get('2014-01-01T09:09:00.000-05:00') tw = PersonTimeWindow(LocationName='kitchen', Priority=100, ical=ical_event, CompareDateTime=now_dt) p.add_window(tw) tw = PersonTimeWindow(LocationName='bedroom', Priority=200, ical=ical_event, CompareDateTime=now_dt) p.add_window(tw) assert p.all_available_count(now_dt) == 2
def test_saving_person_with_available_windows_are_available(): now_dt = arrow.get('2014-01-01T09:09:00.000-05:00') pm = PersonManager() p = Person(Name='calvin') now_dt = arrow.get('2014-01-01T09:09:00.000-05:00') tw = PersonTimeWindow(LocationName='kitchen', Priority=100, ical=ical_event, CompareDateTime=now_dt) p.add_window(tw) tw = PersonTimeWindow(LocationName='bedroom', Priority=200, ical=ical_event, CompareDateTime=now_dt) p.add_window(tw) pm.update_window_set(p) assert p.all_available_count(now_dt) == 2
def test_saving_person_window_set_saves_set(): pm = PersonManager() p = Person(Name='calvin') now_dt = arrow.get('2014-01-01T09:09:00.000-05:00') tw = PersonTimeWindow(LocationName='kitchen', Priority=100, ical=ical_event, CompareDateTime=now_dt) p.add_window(tw) tw = PersonTimeWindow(LocationName='bedroom', Priority=200, ical=ical_event, CompareDateTime=now_dt) p.add_window(tw) pm.update_window_set(p) p = pm.get_person('calvin') assert p.time_windows.count() == 2
def test_preference_is_sorted_correctly(): pm = PersonManager() p = Person(Name='calvin') now_dt = arrow.get('2014-01-01T07:10:00.000-05:00') tw = PersonTimeWindow(LocationName='kitchen', Priority=100, ical=ical_event_before_school, CompareDateTime=now_dt) p.add_window(tw) tw = PersonTimeWindow(LocationName='bedroom', Priority=200, ical=ical_event_before_school, CompareDateTime=now_dt) p.add_window(tw) pm.update_window_set(p) assert p.all_available(now_dt)[0].priority == 200 assert p.all_available(now_dt)[1].priority == 100 tw = PersonTimeWindow(LocationName='mediaroom', Priority=50, ical=ical_event_before_school, CompareDateTime=now_dt) p.add_window(tw) pm.update_window_set(p) p = pm.get_person('calvin') assert p.all_available(now_dt)[0].priority == 200 assert p.all_available(now_dt)[1].priority == 100 assert p.all_available(now_dt)[2].priority == 50
def calvin_three_rooms(now_dt): p = Person(Name='calvin') tw = PersonTimeWindow(LocationName='kitchen', Priority=100, ical=ical_event, CompareDateTime=now_dt) p.add_window(tw) tw = PersonTimeWindow(LocationName='media_room', Priority=300, ical=ical_event, CompareDateTime=now_dt) p.add_window(tw) tw = PersonTimeWindow(LocationName='bedroom', Priority=200, ical=ical_event, CompareDateTime=now_dt) p.add_window(tw) pm = PersonManager() pm.update_window_set(p)