Ejemplo n.º 1
0
def test_model_handles_error_if_database_is_invalid(connection):
    model = DBTablesModel(connection, database)

    assert model.last_error is None
    model.database = 'unknown database'
    model.reload()
    assert isinstance(model.last_error, errors.ProgrammingError)
Ejemplo n.º 2
0
def test_model_escapes_db_name_with_dash(db_dash_in_name_connection):
    model = DBTablesModel(db_dash_in_name_connection, 'db-with-dash')

    assert len(model) == 1
    table_names = []
    for row in model:
        table_names.append(row[0])

    assert 'table-with-dash' in table_names
Ejemplo n.º 3
0
def test_model_fetches_data(connection):
    model = DBTablesModel(connection, database)
    assert len(model) >= 35
    assert 'Name' in [c['name'] for c in model.columns]

    table_names = []
    for row in model:
        table_names.append(row[0])

    assert 'actor' in table_names
Ejemplo n.º 4
0
 def on_change_table(emitter):
     database = self._connection.database
     model = DBTablesModel(self._connection, database)
     if model.last_error is not None:
         self.view.show_error(model.last_error)
         return
     widget = TableChangerWidget(model)
     urwid.connect_signal(widget, widget.SIGNAL_CHANGE_TABLE,
                          self.switch_table)
     self.view.show_table_changer(widget)
     return
Ejemplo n.º 5
0
def test_model_emits_signals_during_reloading(connection):
    model = DBTablesModel(connection, database)
    pre_load_signal_handled = False
    load_signal_handled = False

    def pre_load_handler(emitter):
        nonlocal pre_load_signal_handled
        pre_load_signal_handled = True

    def load_handler(emitter):
        nonlocal load_signal_handled
        load_signal_handled = True

    urwid.connect_signal(model, model.SIGNAL_PRE_LOAD, pre_load_handler)
    urwid.connect_signal(model, model.SIGNAL_LOAD, load_handler)

    model.reload()

    assert pre_load_signal_handled is True
    assert load_signal_handled is True
Ejemplo n.º 6
0
def test_db_tables_view_searches_for_table(sakila_connection):
    model = DBTablesModel(sakila_connection, 'sakila')
    view = DBTablesView(model, sakila_connection)

    size = (80, 30)

    result = view.search_tables('film')
    assert result is not None

    index, row = result
    assert index > 0
    assert 'del_film' in row

    result = view.search_tables('non existent table')
    assert result is None
Ejemplo n.º 7
0
 def create_db_tables_view(self, database, connection):
     model = DBTablesModel(connection, database)
     view = DBTablesView(model, connection)
     self._connect_signal(view,
                          view.SIGNAL_ACTION_QUIT,
                          self.change_fsm_state,
                          user_args=['quit'])
     self._connect_signal(view,
                          view.SIGNAL_ACTION_EXIT,
                          self.change_fsm_state,
                          user_args=['back'])
     self._connect_signal(view,
                          view.SIGNAL_ACTION_RUN_QUERY,
                          self.change_fsm_state,
                          user_args=['run_query'])
     return view
Ejemplo n.º 8
0
def test_keypresses(sakila_connection):
    model = DBTablesModel(sakila_connection, 'sakila')
    view = DBTablesView(model, sakila_connection)

    size = (80, 30)

    emitter = None
    table = None

    def test_table_is_selected(emitter_, table_):
        nonlocal emitter
        nonlocal table
        emitter = emitter_
        table = table_

    urwid.connect_signal(view, view.SIGNAL_ACTION_SELECT_TABLE,
                         test_table_is_selected)

    view.keypress(size, 'down')
    view.keypress(size, 'down')
    view.keypress(size, 'down')
    view.keypress(size, 'up')
    view.keypress(size, 'up')
    view.keypress(size, 'up')

    view.keypress(size, 'enter')

    assert isinstance(emitter, DBTablesView)
    assert table is not None
    old_table = table

    view.keypress(size, 'down')
    view.keypress(size, 'enter')

    assert table is not None
    assert table != old_table

    initial_focus = view._table._focused_row_index
    assert initial_focus > 0

    view.keypress(size, 'f5')
    new_focus = view._table._focused_row_index

    assert new_focus == 0
Ejemplo n.º 9
0
def test_resizing_column_doesnt_raise_exception(sakila_connection):
    model = DBTablesModel(sakila_connection, 'sakila')
    view = DBTablesView(model, sakila_connection)

    view.resize_tbl_col('engine', 10)
    view.render((80, 30))