Example #1
0
def test_model_loads_more_rows(sakila_connection):
    model = TableModel(sakila_connection, table)

    assert model.loaded_rowcount == 100
    model.load_more(50)
    assert model.loaded_rowcount == 200
    assert len(model) == 200
Example #2
0
def test_model_sorts_rows_by_first_name_descending(sakila_connection):
    model = TableModel(sakila_connection, table)
    model.sort('first_name', 'desc')

    row = model[0]
    assert row[0] == 11
    assert row[1] == 'ZERO'
Example #3
0
def test_model_fetches_next_records_set(sakila_connection):
    model = TableModel(sakila_connection, table)

    assert model.loaded_rowcount == 100
    model.load_next_set()
    assert model.loaded_rowcount == 200
    assert len(model) == 200
Example #4
0
def test_model_emits_error_signal(sakila_connection):
    model = TableModel(sakila_connection, table)
    assert model.last_error is None
    model.sort('non-existent-column', 'invalid-dir')
    assert isinstance(model.last_error, errors.ProgrammingError)

    assert len(model) == 0
    assert len(model.data) == 0
    assert model.loaded_rowcount == 0
    assert bool(model.columns) is False
Example #5
0
def test_model_sets_last_error_when_table_doesnt_exist(sakila_connection):
    model = TableModel(sakila_connection, 'unknown table')
    assert isinstance(model.last_error, errors.ProgrammingError)

    assert len(model) == 0
    assert len(model.data) == 0
    assert model.loaded_rowcount == 0
    assert bool(model.columns) is False
Example #6
0
def test_model_fetches_data(sakila_connection):
    model = TableModel(sakila_connection, table)
    model_columns = [c['name'] for c in model.columns]
    assert len(model) == 200
    assert 'actor_id' in model_columns
    assert 'first_name' in model_columns
    assert 'last_name' in model_columns
    assert 'last_update' in model_columns

    assert model.loaded_rowcount == 100
Example #7
0
def test_view_filters_model(sakila_connection, filter_cmd):
    model = TableModel(sakila_connection, 'address')
    view = TableView(model, sakila_connection)

    assert len(view.model) == 603

    op, *args = filter_cmd['filter']
    expected_count = filter_cmd['count']

    view.filter(op, *args)
    assert len(view.model) == expected_count
Example #8
0
def test_view_clears_model_filter(sakila_connection):
    model = TableModel(sakila_connection, 'address')
    view = TableView(model, sakila_connection)

    assert len(view.model) == 603

    view.filter('eq', 'address_id', '1')
    assert len(view.model) == 1

    view.filter('clearfilters')
    assert len(view.model) == 603
Example #9
0
def test_db_table_in_join_clause_suggestions(sakila_connection):
    raw_sql = '''
    SELECT actor_id aid FROM actor JOIN sakila.
    '''

    model = TableModel(sakila_connection, 'address')
    engine = SQLAutocompleteEngine(model)

    suggestions = engine.get_suggestions(raw_sql, len(raw_sql))
    suggestions = suggestions[0]

    assert len(suggestions) > 0
    assert 'actor_info' in suggestions
    assert 'address' in suggestions
Example #10
0
def test_tables_in_from_clause_suggestions(sakila_connection):
    raw_sql = '''
    SELECT * FROM 
    '''

    model = TableModel(sakila_connection, 'address')
    engine = SQLAutocompleteEngine(model)

    suggestions = engine.get_suggestions(raw_sql, len(raw_sql))
    suggestions = suggestions[0]

    assert len(suggestions) > 0
    assert 'actor' in suggestions
    assert 'address' in suggestions
Example #11
0
def test_subquery_column_suggestions(sakila_connection):
    raw_sql = '''
    SELECT actor_id, (SELECT * from inventory WHERE 
    '''

    model = TableModel(sakila_connection, 'address')
    engine = SQLAutocompleteEngine(model)

    suggestions = engine.get_suggestions(raw_sql, len(raw_sql))
    suggestions = suggestions[0]

    assert len(suggestions) > 0
    assert 'inventory_id' in suggestions
    assert 'last_update' in suggestions
Example #12
0
def test_column_in_join_spec_suggestions(sakila_connection):
    raw_sql = '''
    SELECT actor_id FROM actor ac JOIN actor_info ai ON ai.
    '''

    model = TableModel(sakila_connection, 'address')
    engine = SQLAutocompleteEngine(model)

    suggestions = engine.get_suggestions(raw_sql, len(raw_sql))
    suggestions = suggestions[0]

    assert len(suggestions) > 0
    assert 'film_info' in suggestions
    assert 'actor_id' in suggestions
Example #13
0
def test_columns_in_where_suggestions(sakila_connection):
    raw_sql = '''
    SELECT * FROM actor WHERE 
    '''

    model = TableModel(sakila_connection, 'address')
    engine = SQLAutocompleteEngine(model)

    suggestions = engine.get_suggestions(raw_sql, len(raw_sql))
    suggestions = suggestions[0]

    assert len(suggestions) > 0
    assert 'actor_id' in suggestions
    assert 'first_name' in suggestions
    assert 'last_name' in suggestions
Example #14
0
def test_columns_in_current_table_suggestions(sakila_connection):
    raw_sql = '''
    SELECT 
    '''

    model = TableModel(sakila_connection, 'address')
    engine = SQLAutocompleteEngine(model)

    suggestions = engine.get_suggestions(raw_sql, len(raw_sql))
    suggestions = suggestions[0]

    assert len(suggestions) > 0
    assert 'address_id' in suggestions
    assert 'address' in suggestions
    assert 'district' in suggestions
Example #15
0
def test_columns_in_database_table_identifier_suggestions(sakila_connection):
    raw_sql = '''
    SELECT sakila.actor.
    '''

    model = TableModel(sakila_connection, 'address')
    engine = SQLAutocompleteEngine(model)

    suggestions = engine.get_suggestions(raw_sql, len(raw_sql))
    suggestions = suggestions[0]

    assert len(suggestions) > 0
    assert 'actor_id' in suggestions
    assert 'first_name' in suggestions
    assert 'last_name' in suggestions
Example #16
0
def test_column_alias_in_order_by_clause_suggestions(sakila_connection):
    raw_sql = '''
    SELECT actor_id aid FROM actor ORDER BY 
    '''

    model = TableModel(sakila_connection, 'address')
    engine = SQLAutocompleteEngine(model)

    suggestions = engine.get_suggestions(raw_sql, len(raw_sql))
    suggestions = suggestions[0]

    assert len(suggestions) > 0
    assert 'aid' in suggestions
    assert 'first_name' in suggestions
    assert 'last_name' in suggestions
Example #17
0
 def create_table_view(self, table, connection):
     model = TableModel(connection, table)
     view = TableView(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
Example #18
0
def test_model_properly_escapes_alias(sakila_connection):
    long_str = "x" * 1024
    create_table_sql = '''
CREATE TABLE IF NOT EXISTS `table_with_space_in_column_names` (
counter INT NULL,
`column varchar` VARCHAR (1024) NULL,
`column text` TEXT NULL
)
    '''

    sakila_connection.query(create_table_sql)
    sakila_connection.query('''REPLACE INTO table_with_space_in_column_names
            (counter, `column varchar`, `column text`) VALUES (1, "{0}", "{1}" )'''
                            .format(long_str, long_str))

    model = TableModel(sakila_connection, 'table_with_space_in_column_names')
    assert model.last_error is None
Example #19
0
def test_model_filters_records(sakila_connection, filter):
    model = TableModel(sakila_connection, 'address')
    model.filter(filter)

    assert model.last_error is None
Example #20
0
def test_model_properly_escapes_dash_in_table_names(
        db_dash_in_name_connection):
    model = TableModel(db_dash_in_name_connection, 'table-with-dash')
    assert model.last_error is None