Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1from paramiko import SFTPAttributes 

2 

3from sdc_etl_libs.sdc_filetransfer.utils.delete_files_mechanism.AfterNDaysDeleteCriteria import \ 

4 AfterNDaysDeleteCriteria 

5from datetime import datetime, timedelta 

6 

7 

8def test_get_files_to_delete_all_files(): 

9 days_threshold = 5 

10 # mock_sftp_files 

11 first_ftp_file = SFTPAttributes() 

12 first_ftp_file.st_mtime = (datetime.today() - timedelta(days=6)).timestamp() 

13 second_ftp_file = SFTPAttributes() 

14 second_ftp_file.st_mtime = (datetime.today() - timedelta(days=7)).timestamp() 

15 files = [first_ftp_file, second_ftp_file] 

16 delete_criteria = AfterNDaysDeleteCriteria(days_threshold) 

17 assert len(delete_criteria.get_files_to_delete(files)) == 2 

18 

19 

20def test_get_files_to_delete_one_file(): 

21 days_threshold = 5 

22 # mock_sftp_files 

23 first_ftp_file = SFTPAttributes() 

24 first_ftp_file.st_mtime = (datetime.today() - timedelta(days=6)).timestamp() 

25 second_ftp_file = SFTPAttributes() 

26 second_ftp_file.st_mtime = (datetime.today() - timedelta(days=4)).timestamp() 

27 files = [first_ftp_file, second_ftp_file] 

28 delete_criteria = AfterNDaysDeleteCriteria(days_threshold) 

29 assert len(delete_criteria.get_files_to_delete(files)) == 1 

30 

31 

32def test_get_files_to_delete_no_files(): 

33 days_threshold = 5 

34 # mock_sftp_files 

35 first_ftp_file = SFTPAttributes() 

36 first_ftp_file.st_mtime = (datetime.today() - timedelta(days=2)).timestamp() 

37 second_ftp_file = SFTPAttributes() 

38 second_ftp_file.st_mtime = (datetime.today() - timedelta(days=3)).timestamp() 

39 files = [first_ftp_file, second_ftp_file] 

40 delete_criteria = AfterNDaysDeleteCriteria(days_threshold) 

41 assert len(delete_criteria.get_files_to_delete(files)) == 0