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
3 changes: 2 additions & 1 deletion airflow/providers/sftp/sensors/sftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"""This module contains SFTP sensor."""
from __future__ import annotations

import os
from datetime import datetime
from typing import TYPE_CHECKING, Sequence

Expand Down Expand Up @@ -69,7 +70,7 @@ def poke(self, context: Context) -> bool:
if self.file_pattern:
file_from_pattern = self.hook.get_file_by_pattern(self.path, self.file_pattern)
if file_from_pattern:
actual_file_to_check = file_from_pattern
actual_file_to_check = os.path.join(self.path, file_from_pattern)
else:
return False
else:
Expand Down
11 changes: 1 addition & 10 deletions tests/providers/sftp/sensors/test_sftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,10 @@ def test_naive_datetime(self, sftp_hook_mock):
sftp_hook_mock.return_value.get_mod_time.assert_called_once_with("/path/to/file/1970-01-01.txt")
assert not output

@patch("airflow.providers.sftp.sensors.sftp.SFTPHook")
def test_file_with_pattern_parameter_call(self, sftp_hook_mock):
sftp_hook_mock.return_value.get_mod_time.return_value = "19700101000000"
sftp_sensor = SFTPSensor(task_id="unit_test", path="/path/to/file/", file_pattern="*.txt")
context = {"ds": "1970-01-01"}
output = sftp_sensor.poke(context)
sftp_hook_mock.return_value.get_file_by_pattern.assert_called_once_with("/path/to/file/", "*.txt")
assert output

@patch("airflow.providers.sftp.sensors.sftp.SFTPHook")
def test_file_present_with_pattern(self, sftp_hook_mock):
sftp_hook_mock.return_value.get_mod_time.return_value = "19700101000000"
sftp_hook_mock.return_value.get_file_by_pattern.return_value = "/path/to/file/text_file.txt"
sftp_hook_mock.return_value.get_file_by_pattern.return_value = "text_file.txt"
sftp_sensor = SFTPSensor(task_id="unit_test", path="/path/to/file/", file_pattern="*.txt")
context = {"ds": "1970-01-01"}
output = sftp_sensor.poke(context)
Expand Down