stale[bot] closed pull request #2598: [AIRFLOW-1595] Change to construct 
sqlite_hook from connection schema
URL: https://github.com/apache/incubator-airflow/pull/2598
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/airflow/hooks/sqlite_hook.py b/airflow/hooks/sqlite_hook.py
index c241c2ddef..5a9c7e3516 100644
--- a/airflow/hooks/sqlite_hook.py
+++ b/airflow/hooks/sqlite_hook.py
@@ -32,5 +32,5 @@ def get_conn(self):
         Returns a sqlite connection object
         """
         conn = self.get_connection(self.sqlite_conn_id)
-        conn = sqlite3.connect(conn.host)
+        conn = sqlite3.connect(conn.schema)
         return conn
diff --git a/airflow/utils/db.py b/airflow/utils/db.py
index 35c187ca54..44aa05429d 100644
--- a/airflow/utils/db.py
+++ b/airflow/utils/db.py
@@ -160,7 +160,7 @@ def initdb():
     merge_conn(
         models.Connection(
             conn_id='sqlite_default', conn_type='sqlite',
-            host='/tmp/sqlite_default.db'))
+            schema='/tmp/sqlite_default.db'))
     merge_conn(
         models.Connection(
             conn_id='http_default', conn_type='http',
diff --git a/tests/hooks/test_sqlite_hook.py b/tests/hooks/test_sqlite_hook.py
new file mode 100644
index 0000000000..de830f09ae
--- /dev/null
+++ b/tests/hooks/test_sqlite_hook.py
@@ -0,0 +1,53 @@
+# -*- coding: utf-8 -*-
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+import mock
+import unittest
+import os
+
+from airflow import settings, models
+from airflow.settings import Session
+from airflow.hooks.sqlite_hook import SqliteHook
+
+
[email protected](not settings.SQL_ALCHEMY_CONN.startswith('sqlite'), 
'SqliteHook won\'t work without backend SQLite. No need to test anything here')
+class TestSqliteHook(unittest.TestCase):
+
+    CONN_ID = 'sqlite_hook_test'
+
+    @classmethod
+    def setUpClass(cls):
+        super(TestSqliteHook, cls).setUpClass()
+        session = Session()
+        
session.query(models.Connection).filter_by(conn_id=cls.CONN_ID).delete()
+        session.commit()
+        connection = models.Connection(conn_id=cls.CONN_ID, 
uri=settings.SQL_ALCHEMY_CONN)
+        session.add(connection)
+        session.commit()
+        session.close()
+
+    def test_sql_hook(self):
+        hook = SqliteHook(sqlite_conn_id=self.CONN_ID)
+        conn_id, = hook.get_first('SELECT conn_id FROM connection WHERE 
conn_id = :conn_id',
+                                  {'conn_id': self.CONN_ID})
+        self.assertEqual(conn_id, self.CONN_ID)
+
+    @classmethod
+    def tearDownClass(cls):
+        session = Session()
+        
session.query(models.Connection).filter_by(conn_id=cls.CONN_ID).delete()
+        session.commit()
+        session.close()
+        super(TestSqliteHook, cls).tearDownClass()


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to