|
19 | 19 |
|
20 | 20 | from __future__ import print_function
|
21 | 21 |
|
| 22 | +import mock |
22 | 23 | import unittest
|
23 | 24 | import shutil
|
24 | 25 | import os
|
25 | 26 | import pysftp
|
26 | 27 |
|
27 |
| -from airflow import configuration |
| 28 | +from airflow import configuration, models |
28 | 29 | from airflow.contrib.hooks.sftp_hook import SFTPHook
|
29 | 30 |
|
30 | 31 | TMP_PATH = '/tmp'
|
@@ -105,6 +106,63 @@ def test_get_mod_time(self):
|
105 | 106 | TMP_PATH, TMP_DIR_FOR_TESTS, TMP_FILE_FOR_TESTS))
|
106 | 107 | self.assertEqual(len(output), 14)
|
107 | 108 |
|
| 109 | + @mock.patch('airflow.contrib.hooks.sftp_hook.SFTPHook.get_connection') |
| 110 | + def test_no_host_key_check_default(self, get_connection): |
| 111 | + connection = models.Connection(login='login', host='host') |
| 112 | + get_connection.return_value = connection |
| 113 | + hook = SFTPHook() |
| 114 | + self.assertEqual(hook.no_host_key_check, False) |
| 115 | + |
| 116 | + @mock.patch('airflow.contrib.hooks.sftp_hook.SFTPHook.get_connection') |
| 117 | + def test_no_host_key_check_enabled(self, get_connection): |
| 118 | + connection = models.Connection( |
| 119 | + login='login', host='host', |
| 120 | + extra='{"no_host_key_check": true}') |
| 121 | + |
| 122 | + get_connection.return_value = connection |
| 123 | + hook = SFTPHook() |
| 124 | + self.assertEqual(hook.no_host_key_check, True) |
| 125 | + |
| 126 | + @mock.patch('airflow.contrib.hooks.sftp_hook.SFTPHook.get_connection') |
| 127 | + def test_no_host_key_check_disabled(self, get_connection): |
| 128 | + connection = models.Connection( |
| 129 | + login='login', host='host', |
| 130 | + extra='{"no_host_key_check": false}') |
| 131 | + |
| 132 | + get_connection.return_value = connection |
| 133 | + hook = SFTPHook() |
| 134 | + self.assertEqual(hook.no_host_key_check, False) |
| 135 | + |
| 136 | + @mock.patch('airflow.contrib.hooks.sftp_hook.SFTPHook.get_connection') |
| 137 | + def test_no_host_key_check_disabled_for_all_but_true(self, get_connection): |
| 138 | + connection = models.Connection( |
| 139 | + login='login', host='host', |
| 140 | + extra='{"no_host_key_check": "foo"}') |
| 141 | + |
| 142 | + get_connection.return_value = connection |
| 143 | + hook = SFTPHook() |
| 144 | + self.assertEqual(hook.no_host_key_check, False) |
| 145 | + |
| 146 | + @mock.patch('airflow.contrib.hooks.sftp_hook.SFTPHook.get_connection') |
| 147 | + def test_no_host_key_check_ignore(self, get_connection): |
| 148 | + connection = models.Connection( |
| 149 | + login='login', host='host', |
| 150 | + extra='{"ignore_hostkey_verification": true}') |
| 151 | + |
| 152 | + get_connection.return_value = connection |
| 153 | + hook = SFTPHook() |
| 154 | + self.assertEqual(hook.no_host_key_check, True) |
| 155 | + |
| 156 | + @mock.patch('airflow.contrib.hooks.sftp_hook.SFTPHook.get_connection') |
| 157 | + def test_no_host_key_check_no_ignore(self, get_connection): |
| 158 | + connection = models.Connection( |
| 159 | + login='login', host='host', |
| 160 | + extra='{"ignore_hostkey_verification": false}') |
| 161 | + |
| 162 | + get_connection.return_value = connection |
| 163 | + hook = SFTPHook() |
| 164 | + self.assertEqual(hook.no_host_key_check, False) |
| 165 | + |
108 | 166 | def tearDown(self):
|
109 | 167 | shutil.rmtree(os.path.join(TMP_PATH, TMP_DIR_FOR_TESTS))
|
110 | 168 | os.remove(os.path.join(TMP_PATH, TMP_FILE_FOR_TESTS))
|
|
0 commit comments