Esempio n. 1
0
def test_can_save_physical_confirmation_false_preference():
    pm = PersonManager()
    p = Person(Name='calvin')
    p.require_physical_confirmation = False
    pm.update_window_set(p)
    p = pm.get_person('calvin')
    assert not p.require_physical_confirmation
Esempio n. 2
0
def test_person_req_phys_conf_sets_req_phys_conf_for_loc_verify(p_mock):
    pm = PersonManager()
    p = Person(Name='calvin')
    p.require_physical_confirmation = True
    pm.update_window_set(p)
    lv = LocationVerification(LocationName='room', PersonName='calvin')
    assert lv.person.require_physical_confirmation
Esempio n. 3
0
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
Esempio n. 4
0
def test_person_location_out_of_order_priorities_are_correct():
    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='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)
    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 media_room' in \
           result.output
Esempio n. 5
0
def test_no_locations_returns_error(c_mock, l_mock):
    e = test_event()
    lm = LibraryManager()
    lm.update_message(Name='dinner', Message='time for dinner')
    pm = PersonManager()
    p = Person(Name='calvin')
    pm.update_window_set(p)
    c_mock.return_value = 0
    handler(e, {})
    l_mock.assert_called_with('No locations are available for calvin')
Esempio n. 6
0
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
Esempio n. 7
0
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
Esempio n. 8
0
def test_verify_switch_with_press_returns_true():
    rpi_mock.GPIO.setmode.return_value = None
    rpi_mock.GPIO.setup.return_value = None
    rpi_mock.GPIO.input.return_value = False
    pm = PersonManager()
    p = Person(Name='calvin')
    p.require_physical_confirmation = True
    pm.update_window_set(p)
    l = LocationAvailability(LocationName='kitchen')
    id = 12
    l.with_switch(HardwareId=id, Color='Red', Name='Test', Style='Circle')
    lm = LocationManager()
    lm.update_input_capabilities(l)
    lv = LocationVerification(LocationName='kitchen', PersonName='calvin')

    done, count, timeout = lv.verify_person_at_location()
    print done, count, timeout
    assert done and count == 1 and timeout < 3
Esempio n. 9
0
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)