コード例 #1
0
 def __init__(self):
     self.__menu = Menu.Builder(Description('Student houses reservations platform'),
                                auto_select=lambda: None) \
         .with_entry(Entry.create('1', 'Login as student', on_selected=lambda: self.__student_login())) \
         .with_entry(Entry.create('2', 'Login as employee', on_selected=lambda: self.__employee_login())) \
         .with_entry(Entry.create('0', 'Exit', on_selected=lambda: print('Bye!'), is_exit=True)) \
         .build()
コード例 #2
0
def test_menu_selection_on_wrong_key(mocked_print, mocked_input):
    menu = Menu.Builder(Description('a description')) \
        .with_entry(Entry.create('1', 'first entry', on_selected=lambda: print('first entry selected'))) \
        .with_entry(Entry.create('0', 'exit', is_exit=True)) \
        .build()
    menu.run()
    mocked_print.assert_any_call('Invalid selection. Please, try again...')
    mocked_input.assert_called()
コード例 #3
0
    def __switch_to_admins_menu(self) -> None:  # VIEW DEL MENU ADMIN
        self.__menu = Menu.Builder(Description('Administration panel'), auto_select=lambda: None) \
            .with_entry(Entry.create('1', 'Show all required reservations',
                                     on_selected=lambda: self.__print_reservations())) \
            .with_entry(Entry.create('0', 'Exit', on_selected=lambda: print('Bye!'), is_exit=True)) \
            .build()

        self.__menu.run()
コード例 #4
0
    def __switch_to_students_menu(self) -> None:  # VIEW DEL MENU STUDENTE

        self.__menu = Menu.Builder(Description('Students panel'), auto_select=lambda: None) \
            .with_entry(Entry.create('1', 'Add reservation', on_selected=lambda: self.__add_reservation())) \
            .with_entry(Entry.create('2', 'Retrieve your reservation',
                                     on_selected=lambda: self.__retrieve_your_reservation())) \
            .with_entry(Entry.create('0', 'Exit', on_selected=lambda: self.__logout(), is_exit=True)) \
            .build()

        self.__menu.run()
コード例 #5
0
def test_menu_builder_cannot_call_two_times_build():
    menu_builder = Menu.Builder(Description('a description'))
    menu_builder.with_entry(Entry.create('1', 'first entry', is_exit=True))
    menu_builder.build()
    with pytest.raises(ValidationError):
        menu_builder.build()
コード例 #6
0
def test_menu_builder_cannot_create_menu_without_exit():
    menu_builder = Menu.Builder(Description('a description'))
    with pytest.raises(ValidationError):
        menu_builder.build()
    menu_builder.with_entry(Entry.create('1', 'exit', is_exit=True))
    menu_builder.build()
コード例 #7
0
def test_menu_builder_cannot_create_empty_menu():
    menu_builder = Menu.Builder(Description('a description'))
    with pytest.raises(ValidationError):
        menu_builder.build()
コード例 #8
0
def test_menu_does_not_contain_duplicates():
    menu_builder = Menu.Builder(Description('a description'))
    menu_builder.with_entry(Entry.create('1', 'first entry'))
    with pytest.raises(ValidationError):
        menu_builder.with_entry(Entry.create('1', 'first entry'))