Skip to content

Commit 4c44328

Browse files
author
Vladimir
committed
[IMP] Have fixed all the tests
1 parent b09a7c9 commit 4c44328

File tree

5 files changed

+51
-9
lines changed

5 files changed

+51
-9
lines changed

tests/cli/test_create_backup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def test_ok(dump_db_mock, dump_filestore_mock, import_module_mock):
3636
'backup_location': '/tmp/test',
3737
'clean_backup_after': '12',
3838
'db_name': 'test',
39+
'with_db': 'True',
3940
'with_filestore': 'True',
4041
'filestore_location': '/tmp/test',
4142
}

tests/protocols/ftp/test_ftp_save_db.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33

44
# Stdlib:
55
import configparser
6+
from datetime import datetime
67

78
# Thirdparty:
89
from mock import patch
910
from odoo_backup_db_cli.protocols.ftp import FtpBackupHandler, ftplib, os
1011

12+
FORMAT_TIME = '%Y-%m-%d-%H-%M-%S'
13+
1114

1215
@patch.object(os, 'remove')
1316
@patch.object(ftplib.FTP, 'mkd')
@@ -96,7 +99,7 @@ def test_ok_with_subfolder(
9699
'with_filestore': 'True',
97100
'filestore_location': '/tmp/test',
98101
}
99-
nlst_mock.return_value = ["test"]
102+
nlst_mock.return_value = [datetime.now().strftime(FORMAT_TIME)]
100103
ftp_backup_handler_instance = FtpBackupHandler(config, 'test')
101104
ftp_backup_handler_instance._save_db()
102105
ftp_mk_dirs_mock.assert_called_once()

tests/protocols/sftp/test_sftp_delete_old_backups.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
from mock import patch
99
from odoo_backup_db_cli.protocols.sftp import SftpBackupHandler, pysftp
1010

11+
12+
@patch.object(pysftp.CnOpts, 'get_hostkey')
13+
@patch('pysftp.paramiko.Transport')
1114
@patch('odoo_backup_db_cli.protocols.sftp.pysftp.Connection.pwd')
1215
@patch.object(pysftp.Connection, 'listdir', side_effect=(('2020-01-01-01-01-01',),('1', '2')))
1316
@patch.object(pysftp.Connection, 'cwd')
@@ -19,7 +22,9 @@ def test_delete(
1922
cwd_mock,
2023
listdir_mock,
2124
pwd_mock,
22-
):
25+
hostkey_mock,
26+
transport_mock
27+
):
2328
config = configparser.ConfigParser()
2429
config['test'] = {
2530
'db_host': '0.0.0.0',
@@ -40,13 +45,16 @@ def test_delete(
4045
'filestore_location': '/tmp/test',
4146
}
4247
sftp_backup_handler_instance = SftpBackupHandler(config, 'test')
48+
sftp_backup_handler_instance._connect()
4349
sftp_backup_handler_instance._delete_old_backups()
4450
assert remove_mock.call_count == 2
4551
assert listdir_mock.call_count == 2
4652
assert cwd_mock.call_count == 4
4753
rmdir_mock.assert_called_once()
4854

4955

56+
@patch.object(pysftp.CnOpts, 'get_hostkey')
57+
@patch('pysftp.paramiko.Transport')
5058
@patch('odoo_backup_db_cli.protocols.sftp.pysftp.Connection.pwd')
5159
@patch.object(pysftp.Connection, 'listdir', side_effect=(('2020',),('1', '2')))
5260
@patch.object(pysftp.Connection, 'cwd')
@@ -58,7 +66,9 @@ def test_try_delete_incorrect(
5866
cwd_mock,
5967
listdir_mock,
6068
pwd_mock,
61-
):
69+
hostkey_mock,
70+
transport_mock
71+
):
6272
config = configparser.ConfigParser()
6373
config['test'] = {
6474
'db_host': '0.0.0.0',
@@ -79,13 +89,16 @@ def test_try_delete_incorrect(
7989
'filestore_location': '/tmp/test',
8090
}
8191
sftp_backup_handler_instance = SftpBackupHandler(config, 'test')
92+
sftp_backup_handler_instance._connect()
8293
sftp_backup_handler_instance._delete_old_backups()
8394
assert remove_mock.call_count == 0
8495
assert listdir_mock.call_count == 1
8596
assert cwd_mock.call_count == 0
8697
rmdir_mock.assert_not_called()
8798

8899

100+
@patch.object(pysftp.CnOpts, 'get_hostkey')
101+
@patch('pysftp.paramiko.Transport')
89102
@patch('odoo_backup_db_cli.protocols.sftp.pysftp.Connection.pwd')
90103
@patch.object(pysftp.Connection, 'listdir', side_effect=((),('1', '2')))
91104
@patch.object(pysftp.Connection, 'cwd')
@@ -97,7 +110,9 @@ def test_not_delete(
97110
cwd_mock,
98111
listdir_mock,
99112
pwd_mock,
100-
):
113+
hostkey_mock,
114+
transport_mock
115+
):
101116
config = configparser.ConfigParser()
102117
config['test'] = {
103118
'db_host': '0.0.0.0',
@@ -118,6 +133,7 @@ def test_not_delete(
118133
'filestore_location': '/tmp/test',
119134
}
120135
sftp_backup_handler_instance = SftpBackupHandler(config, 'test')
136+
sftp_backup_handler_instance._connect()
121137
sftp_backup_handler_instance._delete_old_backups()
122138
remove_mock.assert_not_called()
123139
listdir_mock.assert_called_once()

tests/protocols/sftp/test_sftp_save_db.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@
33

44
# Stdlib:
55
import configparser
6+
from datetime import datetime
67

78
# Thirdparty:
89
from mock import patch
910
from odoo_backup_db_cli.protocols.sftp import SftpBackupHandler, pysftp, os
1011

12+
FORMAT_TIME = '%Y-%m-%d-%H-%M-%S'
1113

14+
15+
@patch.object(pysftp.CnOpts, 'get_hostkey')
16+
@patch('pysftp.paramiko.Transport')
1217
@patch.object(os, 'remove')
1318
@patch.object(pysftp.Connection, 'makedirs')
1419
@patch.object(pysftp.Connection, 'mkdir')
@@ -24,7 +29,9 @@ def test_ok_without_subfolder(
2429
mkdir_mock,
2530
makedirs_mock,
2631
remove_mock,
27-
):
32+
hostkey_mock,
33+
transport_mock
34+
):
2835
config = configparser.ConfigParser()
2936
config['test'] = {
3037
'db_host': '0.0.0.0',
@@ -46,6 +53,7 @@ def test_ok_without_subfolder(
4653
}
4754
listdir_mock.return_value = [""]
4855
sftp_backup_handler_instance = SftpBackupHandler(config, 'test')
56+
sftp_backup_handler_instance._connect()
4957
sftp_backup_handler_instance._save_db()
5058
assert cwd_mock.call_count == 3
5159
put_mock.assert_called_once()
@@ -55,6 +63,8 @@ def test_ok_without_subfolder(
5563
remove_mock.assert_called_once()
5664

5765

66+
@patch.object(pysftp.CnOpts, 'get_hostkey')
67+
@patch('pysftp.paramiko.Transport')
5868
@patch.object(os, 'remove')
5969
@patch.object(pysftp.Connection, 'makedirs')
6070
@patch.object(pysftp.Connection, 'mkdir')
@@ -70,7 +80,9 @@ def test_ok_with_subfolder(
7080
mkdir_mock,
7181
makedirs_mock,
7282
remove_mock,
73-
):
83+
hostkey_mock,
84+
transport_mock
85+
):
7486
config = configparser.ConfigParser()
7587
config['test'] = {
7688
'db_host': '0.0.0.0',
@@ -90,8 +102,9 @@ def test_ok_with_subfolder(
90102
'with_filestore': 'True',
91103
'filestore_location': '/tmp/test',
92104
}
93-
listdir_mock.return_value = ["test"]
105+
listdir_mock.return_value = [datetime.now().strftime(FORMAT_TIME)]
94106
sftp_backup_handler_instance = SftpBackupHandler(config, 'test')
107+
sftp_backup_handler_instance._connect()
95108
sftp_backup_handler_instance._save_db()
96109
assert cwd_mock.call_count == 3
97110
put_mock.assert_called_once()

tests/protocols/sftp/test_sftp_save_filestore.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
from odoo_backup_db_cli.protocols.sftp import SftpBackupHandler, pysftp, os
1010

1111

12+
@patch.object(pysftp.CnOpts, 'get_hostkey')
13+
@patch('pysftp.paramiko.Transport')
1214
@patch.object(os, 'remove')
1315
@patch('odoo_backup_db_cli.protocols.sftp.pysftp.Connection.pwd')
1416
@patch.object(pysftp.Connection, 'put')
@@ -18,7 +20,9 @@ def test_with_filestore(
1820
put_mock,
1921
pwd_mock,
2022
remove_mock,
21-
):
23+
hostkey_mock,
24+
transport_mock
25+
):
2226
config = configparser.ConfigParser()
2327
config['test'] = {
2428
'db_host': '0.0.0.0',
@@ -46,6 +50,8 @@ def test_with_filestore(
4650
remove_mock.assert_called_once()
4751

4852

53+
@patch.object(pysftp.CnOpts, 'get_hostkey')
54+
@patch('pysftp.paramiko.Transport')
4955
@patch.object(os, 'remove')
5056
@patch('odoo_backup_db_cli.protocols.sftp.pysftp.Connection.pwd')
5157
@patch.object(pysftp.Connection, 'put')
@@ -55,7 +61,9 @@ def test_without_filestore(
5561
put_mock,
5662
pwd_mock,
5763
remove_mock,
58-
):
64+
hostkey_mock,
65+
transport_mock
66+
):
5967
config = configparser.ConfigParser()
6068
config['test'] = {
6169
'db_host': '0.0.0.0',
@@ -76,6 +84,7 @@ def test_without_filestore(
7684
'filestore_location': '/tmp/test',
7785
}
7886
sftp_backup_handler_instance = SftpBackupHandler(config, 'test')
87+
sftp_backup_handler_instance._connect()
7988
sftp_backup_handler_instance._save_filestore()
8089
cwd_mock.assert_not_called()
8190
put_mock.assert_not_called()

0 commit comments

Comments
 (0)