def test_poke(self): op = FTPSensor(path="foobar.json", ftp_conn_id="bob_ftp", task_id="test_task") self.hook_mock.get_mod_time.side_effect = \ [error_perm("550: Can't check for file existence"), None] self.assertFalse(op.poke(None)) self.assertTrue(op.poke(None))
def test_poke(self): op = FTPSensor(path="foobar.json", ftp_conn_id="bob_ftp", task_id="test_task") self.hook_mock.get_mod_time.side_effect = \ [error_perm("550: Can't check for file existence"), None] self.assertFalse(op.poke(None)) self.assertTrue(op.poke(None))
def test_poke_ignore_transient_error(self): op = FTPSensor(path="foobar.json", ftp_conn_id="bob_ftp", task_id="test_task", fail_on_transient_errors=False) self.hook_mock.get_mod_time.side_effect = \ [error_perm("434: Host unavailable"), None] self.assertFalse(op.poke(None)) self.assertTrue(op.poke(None))
def test_poke_ignore_transient_error(self, mock_hook): op = FTPSensor(path="foobar.json", ftp_conn_id="bob_ftp", task_id="test_task", fail_on_transient_errors=False) mock_hook.return_value.__enter__.return_value.get_mod_time.side_effect = [ error_perm("434: Host unavailable"), None ] self.assertFalse(op.poke(None)) self.assertTrue(op.poke(None))
def test_poke_fails_due_error(self): op = FTPSensor(path="foobar.json", ftp_conn_id="bob_ftp", task_id="test_task") self.hook_mock.get_mod_time.side_effect = \ error_perm("530: Login authentication failed") with self.assertRaises(error_perm) as context: op.execute(None) self.assertTrue("530" in str(context.exception))
def test_poke_fails_due_error(self): op = FTPSensor(path="foobar.json", ftp_conn_id="bob_ftp", task_id="test_task") self.hook_mock.get_mod_time.side_effect = \ error_perm("530: Login authentication failed") with self.assertRaises(error_perm) as context: op.execute(None) self.assertTrue("530" in str(context.exception))
def test_poke_fail_on_transient_error(self): op = FTPSensor(path="foobar.json", ftp_conn_id="bob_ftp", task_id="test_task") self.hook_mock.get_mod_time.side_effect = \ error_perm("434: Host unavailable") with self.assertRaises(error_perm) as context: op.execute(None) self.assertTrue("434" in str(context.exception))
def test_poke_fail_on_transient_error(self, mock_hook): op = FTPSensor(path="foobar.json", ftp_conn_id="bob_ftp", task_id="test_task") mock_hook.return_value.__enter__.return_value\ .get_mod_time.side_effect = error_perm("434: Host unavailable") with self.assertRaises(error_perm) as context: op.execute(None) self.assertTrue("434" in str(context.exception))
def test_poke(self, mock_hook): op = FTPSensor(path="foobar.json", ftp_conn_id="bob_ftp", task_id="test_task") mock_hook.return_value.__enter__.return_value.get_mod_time.side_effect = [ error_perm("550: Can't check for file existence"), error_perm("550: Directory or file does not exist"), error_perm("550 - Directory or file does not exist"), None ] self.assertFalse(op.poke(None)) self.assertFalse(op.poke(None)) self.assertFalse(op.poke(None)) self.assertTrue(op.poke(None))