Пример #1
0
def test_model_searches_for_sakila(connection):
    model = DatabasesModel(connection)

    result = model.search('saki', 0)
    assert result is not None

    row_index, row = result
    assert row_index > 0
    assert row == ('sakila', )
Пример #2
0
def test_keypresses(connection):
    model = DatabasesModel(connection)
    view = DBView(model, connection)

    size = (80, 30)

    emitter = None
    database = None

    def test_db_is_selected(emitter_, database_):
        nonlocal emitter
        nonlocal database
        emitter = emitter_
        database = database_

    urwid.connect_signal(view, view.SIGNAL_ACTION_SELECT_DB,
                         test_db_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, DBView)
    assert database is not None
    old_database = database

    view.keypress(size, 'down')
    view.keypress(size, 'enter')
    assert database is not None
    assert database != old_database
Пример #3
0
def test_db_view_refreshes_table(connection):
    model = DatabasesModel(connection)
    view = DBView(model, connection)
    size = (80, 30)

    initial_focus = view._table._focused_row_index

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

    new_focus = view._table._focused_row_index

    assert new_focus > initial_focus

    model.reload()
    new_focus = view._table._focused_row_index
    assert new_focus == initial_focus
Пример #4
0
def test_model_fetches_data(connection):
    model = DatabasesModel(connection)
    assert len(model) > 0
    assert 'Database' in [c['name'] for c in model.columns]

    model_was_iterated = False
    rows = []
    for row in model:
        rows.append(row[0])
        model_was_iterated = True

    assert 'sakila' in rows
    assert len(model.columns)
Пример #5
0
def test_db_view_searches_for_database(connection):
    model = DatabasesModel(connection)
    view = DBView(model, connection)

    size = (80, 30)

    result = view.search_db('sakila')
    assert result is not None

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

    result = view.search_db('non existent database')
    assert result is None
Пример #6
0
 def create_databases_view(self, connection):
     model = DatabasesModel(connection)
     view = DBView(model, connection)
     self._connect_signal(view,
                          view.SIGNAL_ACTION_QUIT,
                          self.change_fsm_state,
                          user_args=['quit'])
     self._connect_signal(view,
                          view.SIGNAL_ACTION_SELECT_DB,
                          self.change_fsm_state,
                          user_args=['select'])
     self._connect_signal(view,
                          view.SIGNAL_ACTION_RUN_QUERY,
                          self.change_fsm_state,
                          user_args=['run_query'])
     return view