Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions Orange/widgets/data/owsql.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,6 @@ def __init__(self):
self.tablecombo.setToolTip('table')
tables.layout().addWidget(self.tablecombo)

index = self.tablecombo.findText(str(self.table))
if index != -1:
self.tablecombo.setCurrentIndex(index)
# set up the callback to select_table in case of selection change
self.tablecombo.activated[int].connect(self.select_table)

self.connectbutton = gui.button(
tables, self, '↻', callback=self.connect)
self.connectbutton.setSizePolicy(
Expand Down Expand Up @@ -181,6 +175,11 @@ def __init__(self):
gui.rubber(self.buttonsArea)

self.connect()
index = self.tablecombo.findText(str(self.table))
if index != -1:
self.tablecombo.setCurrentIndex(index)
# set up the callback to select_table in case of selection change
self.tablecombo.activated[int].connect(self.select_table)

QTimer.singleShot(0, self.select_table)

Expand Down
22 changes: 22 additions & 0 deletions Orange/widgets/data/tests/test_owsql.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,28 @@ def test_non_postgres(self, mock_backends):
self.assertTrue(widget.download)
self.assertFalse(widget.downloadcb.isEnabled())

@mock.patch('Orange.widgets.data.owsql.Table')
@mock.patch('Orange.widgets.data.owsql.SqlTable')
@mock.patch('Orange.widgets.data.owsql.Backend')
def test_restore_table(self, mock_backends, mock_sqltable, mock_table):
"""Test if selected table is restored from settings"""
backend = mock.Mock()
backend().display_name = "database"
del backend().missing_extension
backend().list_tables.return_value = ["a", "b", "c"]
mock_backends.available_backends.return_value = [backend]
mock_sqltable().approx_len.return_value = 100

settings = {'__version__': 2,
'host': '',
'port': '',
'guess_values': False,
'download': False,
'table': 'b'}

widget = self.create_widget(OWSql, stored_settings=settings)
self.assertEqual(widget.tablecombo.currentText(), "b")


if __name__ == "__main__":
unittest.main()