Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] OWSql: enforce data download for non PostgreSQL databases #3178

Merged
merged 2 commits into from
Aug 3, 2018
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
4 changes: 4 additions & 0 deletions Orange/widgets/data/owsql.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ def connect(self):
self.download = True
self.downloadcb.setEnabled(False)

if not is_postgres(self.backend):
self.download = True
self.downloadcb.setEnabled(False)

self._save_credentials()
self.database_desc = OrderedDict((
("Host", self.host), ("Port", self.port),
Expand Down
47 changes: 34 additions & 13 deletions Orange/widgets/data/tests/test_owsql.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# pylint: disable=missing-docstring

import unittest
from unittest import mock

from Orange.data import Table
from Orange.widgets.data.owsql import OWSql
Expand All @@ -10,7 +11,7 @@


@sql_test
class TestOWSql(WidgetTest):
class TestOWSqlConnected(WidgetTest):
def setUp(self):
self.widget = self.create_widget(OWSql)
params, _ = create_iris()
Expand Down Expand Up @@ -45,18 +46,6 @@ def test_output_iris(self):
output_domain = set(map(str, output.domain.attributes))
self.assertTrue(output_domain.issuperset(iris_domain))

def test_missing_extension(self):
"""Test for correctly handled missing backend extension"""
self.set_connection_params()
self.widget.backends[0] = unittest.mock.Mock()
self.widget.backends[0]().missing_extension = ["missing extension"]
self.widget.backends[0]().list_tables = lambda x: []
self.widget.connect()

self.assertTrue(self.widget.Warning.missing_extension.is_shown())
self.assertTrue(self.widget.download)
self.assertFalse(self.widget.downloadcb.isEnabled())

def set_connection_params(self):
"""Set database connection parameters on widget"""
port = ''
Expand All @@ -68,5 +57,37 @@ def set_connection_params(self):
self.widget.passwordtext.setText(self.params['password'])


class TestOWSql(WidgetTest):

@mock.patch('Orange.widgets.data.owsql.Backend')
def test_missing_extension(self, mock_backends):
"""Test for correctly handled missing backend extension"""
backend = mock.Mock()
backend().display_name = "PostgreSQL"
backend().missing_extension = ["missing extension"]
backend().list_tables.return_value = []
mock_backends.available_backends.return_value = [backend]

widget = self.create_widget(OWSql)

self.assertTrue(widget.Warning.missing_extension.is_shown())
self.assertTrue(widget.download)
self.assertFalse(widget.downloadcb.isEnabled())

@mock.patch('Orange.widgets.data.owsql.Backend')
def test_non_postgres(self, mock_backends):
"""Test if download is enforced for non postgres backends"""
backend = mock.Mock()
backend().display_name = "database"
del backend().missing_extension
backend().list_tables.return_value = []
mock_backends.available_backends.return_value = [backend]

widget = self.create_widget(OWSql)

self.assertTrue(widget.download)
self.assertFalse(widget.downloadcb.isEnabled())


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