Skip to content

Commit 65e00b0

Browse files
author
Vladimir
committed
[IMP] Fixed tests
1 parent fb5f680 commit 65e00b0

File tree

6 files changed

+29
-18
lines changed

6 files changed

+29
-18
lines changed

odoo_backup_db_cli/cli.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,10 @@ def update_config(
190190
ATTENTION: will overwrite the environment if it exist.
191191
"""
192192
if not os.path.isfile(path):
193-
sys.exit(color_error_msg('The configuration file does not exist.'))
193+
logging.info(
194+
color_error_msg('The configuration file does not exist.')
195+
)
196+
sys.exit(CodeError.FILE_DOES_NOT_EXIST)
194197
config = configparser.ConfigParser()
195198
config.read(path)
196199
env = {
@@ -215,7 +218,9 @@ def update_config(
215218
for key, value in env.items(): # noqa: WPS110
216219
if value is not None:
217220
config[environment][key] = str(value)
218-
return sys.exit(write_config_file(config, path))
221+
222+
write_config_file(config, path)
223+
return sys.exit(CodeError.SUCCESS)
219224

220225

221226
@main.command() # noqa: C901,WPS213
@@ -236,16 +241,15 @@ def update_config(
236241
def create_backup(environment, save_type, path): # noqa: C901,WPS213
237242
"""Creates a backup according to the settings of the selected environment."""
238243
if not os.path.isfile(path):
239-
sys.exit(
240-
color_error_msg(
241-
'The configuration file {0} does not exist.'.format(path)
242-
)
244+
logging.info(
245+
'The configuration file {0} does not exist.'.format(path)
243246
)
247+
return sys.exit(CodeError.FILE_DOES_NOT_EXIST)
244248

245249
config = configparser.ConfigParser(default_section='common', allow_no_value=True)
246250
config.read(path)
247251
if not save_type:
248-
save_type = environment
252+
save_type = 'local' if environment == 'test' else environment
249253
try:
250254
plugin = getattr(
251255
importlib.import_module(
@@ -262,7 +266,8 @@ def create_backup(environment, save_type, path): # noqa: C901,WPS213
262266
try:
263267
bk_handler.check_config()
264268
except Exception as exp:
265-
sys.exit(color_error_msg(exp))
269+
logging.info(color_error_msg(exp))
270+
return sys.exit(CodeError.NO_SETTINGS)
266271

267272
if config[environment].get('with_db'):
268273
dump_db(config, environment)

odoo_backup_db_cli/protocols/ftp.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,22 @@
1313
class FtpBackupHandler(RemoteBackupHandler, FSBackupHandler):
1414
"""FTP Backup Handler."""
1515

16+
def __init__(self, *args, **kwargs):
17+
super(FtpBackupHandler, self).__init__(*args, **kwargs)
18+
self.ftp = ftplib.FTP() # noqa: S321
19+
20+
1621
def _get_required_settings(self):
1722
res = super()._get_required_settings()
1823
res.append(
1924
(
2025
('username', 'password', 'host', 'port', 'pasv'),
21-
'The creditials for the ftp server is not fully configured.'
26+
'The credentials for the ftp server is not fully configured.'
2227
)
2328
)
2429
return res
2530

2631
def _connect(self):
27-
self.ftp = ftplib.FTP() # noqa: S321
2832
self.ftp.connect(
2933
self.env.get('host'),
3034
int(self.env.get('port'))

odoo_backup_db_cli/protocols/sftp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ def _get_required_settings(self):
5454
res = super()._get_required_settings()
5555
res.append(
5656
(
57-
('username', 'host', 'port'),
58-
'The creditials for the sftp server is not fully configured.'
57+
('username', 'host', 'port', 'pasv'),
58+
'The credentials for the ftp server is not fully configured.'
5959
)
6060
)
6161
return res

tests/cli/test_update_config.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ def test_ok():
3939
'odoo2',
4040
'-w',
4141
'1234',
42-
'-t',
43-
'sftp',
4442
'-r',
4543
'5435',
4644
'-s',
@@ -58,6 +56,9 @@ def test_ok():
5856
'-d',
5957
'test',
6058
'-F',
59+
'True',
60+
'-D',
61+
'True',
6162
'-f',
6263
'/tmp/test',
6364
)
@@ -79,7 +80,6 @@ def test_ok():
7980
'db_port': '5434',
8081
'db_username': 'odoo2',
8182
'db_password': '1234',
82-
'type': 'sftp',
8383
'port': '5435',
8484
'pasv': 'True',
8585
'username': 'kek',
@@ -89,6 +89,7 @@ def test_ok():
8989
'clean_backup_after': '12',
9090
'db_name': 'test',
9191
'with_filestore': 'True',
92+
'with_db': 'True',
9293
'filestore_location': '/tmp/test',
9394
}
9495
assert res.exit_code == CodeError.SUCCESS
@@ -113,8 +114,6 @@ def test_check_exist_config():
113114
'odoo2',
114115
'-w',
115116
'1234',
116-
'-t',
117-
'sftp',
118117
'-H',
119118
'0.1.2.3',
120119
'-r',
@@ -134,6 +133,7 @@ def test_check_exist_config():
134133
'-d',
135134
'test',
136135
'-F',
136+
'True',
137137
'-f',
138138
'/tmp/test',
139139
)

tests/protocols/sftp/test_sftp_save_filestore.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def test_with_filestore(
3939
'filestore_location': '/tmp/test',
4040
}
4141
sftp_backup_handler_instance = SftpBackupHandler(config, 'test')
42+
sftp_backup_handler_instance._connect()
4243
sftp_backup_handler_instance._save_filestore()
4344
assert cwd_mock.call_count == 2
4445
put_mock.assert_called_once()

tests/utils/test_check_config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def get_test_config():
2424
'db_port': '5434',
2525
'db_username': 'odoo2',
2626
'db_password': '1234',
27-
'type': 'local',
27+
# 'type': 'local',
2828
'host': '0.1.2.3',
2929
'port': '5435',
3030
'pasv': 'True',
@@ -35,6 +35,7 @@ def get_test_config():
3535
'clean_backup_after': '12',
3636
'db_name': 'test',
3737
'with_filestore': 'True',
38+
'with_db': 'True',
3839
'filestore_location': '/tmp/test',
3940
}
4041
return config

0 commit comments

Comments
 (0)