@@ -35,7 +35,7 @@ def setUp(self):
35
35
36
36
@contextmanager
37
37
def mock_assets (self ):
38
- """ It provides mocked core assets """
38
+ """It provides mocked core assets"""
39
39
self .path_join_val = "/this/is/a/path"
40
40
with patch ("%s.db" % model ) as db :
41
41
with patch ("%s.os" % model ) as os :
@@ -49,15 +49,15 @@ def mock_assets(self):
49
49
50
50
@contextmanager
51
51
def patch_filtered_sftp (self , record ):
52
- """ It patches filtered record and provides a mock """
52
+ """It patches filtered record and provides a mock"""
53
53
with patch ("%s.filtered" % class_name ) as filtered :
54
54
filtered .side_effect = [], [record ]
55
55
with patch ("%s.backup_log" % class_name ):
56
56
with patch ("%s.sftp_connection" % class_name ):
57
57
yield filtered
58
58
59
59
def new_record (self , method = "sftp" ):
60
- vals = {"name" : u "Têst backup" , "method" : method , "days_to_keep" : 1 }
60
+ vals = {"name" : "Têst backup" , "method" : method , "days_to_keep" : 1 }
61
61
if method == "sftp" :
62
62
vals .update (
63
63
{
@@ -72,7 +72,7 @@ def new_record(self, method="sftp"):
72
72
return self .Model .create (vals )
73
73
74
74
def test_compute_name_sftp (self ):
75
- """ It should create proper SFTP URI """
75
+ """It should create proper SFTP URI"""
76
76
rec_id = self .new_record ()
77
77
self .assertEqual (
78
78
"sftp://%(user)s@%(host)s:%(port)s%(folder)s"
@@ -86,7 +86,7 @@ def test_compute_name_sftp(self):
86
86
)
87
87
88
88
def test_check_folder (self ):
89
- """ It should not allow recursive backups """
89
+ """It should not allow recursive backups"""
90
90
rec_id = self .new_record ("local" )
91
91
with self .assertRaises (UserError ):
92
92
rec_id .write (
@@ -98,7 +98,7 @@ def test_check_folder(self):
98
98
99
99
@patch ("%s._" % model )
100
100
def test_action_sftp_test_connection_success (self , _ ):
101
- """ It should raise connection succeeded warning """
101
+ """It should raise connection succeeded warning"""
102
102
with patch ("%s.sftp_connection" % class_name , new_callable = PropertyMock ):
103
103
rec_id = self .new_record ()
104
104
with self .assertRaises (UserError ):
@@ -107,7 +107,7 @@ def test_action_sftp_test_connection_success(self, _):
107
107
108
108
@patch ("%s._" % model )
109
109
def test_action_sftp_test_connection_fail (self , _ ):
110
- """ It should raise connection fail warning """
110
+ """It should raise connection fail warning"""
111
111
with patch (
112
112
"%s.sftp_connection" % class_name , new_callable = PropertyMock
113
113
) as conn :
@@ -118,15 +118,15 @@ def test_action_sftp_test_connection_fail(self, _):
118
118
_ .assert_called_once_with ("Connection Test Failed!" )
119
119
120
120
def test_action_backup_local (self ):
121
- """ It should backup local database """
121
+ """It should backup local database"""
122
122
rec_id = self .new_record ("local" )
123
123
filename = rec_id .filename (datetime .now ())
124
124
rec_id .action_backup ()
125
125
generated_backup = [f for f in os .listdir (rec_id .folder ) if f >= filename ]
126
126
self .assertEqual (1 , len (generated_backup ))
127
127
128
128
def test_action_backup_local_cleanup (self ):
129
- """ Backup local database and cleanup old databases """
129
+ """Backup local database and cleanup old databases"""
130
130
rec_id = self .new_record ("local" )
131
131
old_date = datetime .now () - timedelta (days = 3 )
132
132
filename = rec_id .filename (old_date )
@@ -142,7 +142,7 @@ def test_action_backup_local_cleanup(self):
142
142
self .assertEqual (1 , len (generated_backup ))
143
143
144
144
def test_action_backup_sftp_mkdirs (self ):
145
- """ It should create remote dirs """
145
+ """It should create remote dirs"""
146
146
rec_id = self .new_record ()
147
147
with self .mock_assets ():
148
148
with self .patch_filtered_sftp (rec_id ):
@@ -152,7 +152,7 @@ def test_action_backup_sftp_mkdirs(self):
152
152
conn .makedirs .assert_called_once_with (rec_id .folder )
153
153
154
154
def test_action_backup_sftp_mkdirs_conn_exception (self ):
155
- """ It should guard from ConnectionException on remote.mkdirs """
155
+ """It should guard from ConnectionException on remote.mkdirs"""
156
156
rec_id = self .new_record ()
157
157
with self .mock_assets ():
158
158
with self .patch_filtered_sftp (rec_id ):
@@ -164,7 +164,7 @@ def test_action_backup_sftp_mkdirs_conn_exception(self):
164
164
self .assertTrue (True )
165
165
166
166
def test_action_backup_sftp_remote_open (self ):
167
- """ It should open remote file w/ proper args """
167
+ """It should open remote file w/ proper args"""
168
168
rec_id = self .new_record ()
169
169
with self .mock_assets () as assets :
170
170
with self .patch_filtered_sftp (rec_id ):
@@ -174,22 +174,22 @@ def test_action_backup_sftp_remote_open(self):
174
174
conn .open .assert_called_once_with (assets ["os" ].path .join (), "wb" )
175
175
176
176
def test_action_backup_all_search (self ):
177
- """ It should search all records """
177
+ """It should search all records"""
178
178
rec_id = self .new_record ()
179
179
with patch ("%s.search" % class_name , new_callable = PropertyMock ):
180
180
rec_id .action_backup_all ()
181
181
rec_id .search .assert_called_once_with ([])
182
182
183
183
def test_action_backup_all_return (self ):
184
- """ It should return result of backup operation """
184
+ """It should return result of backup operation"""
185
185
rec_id = self .new_record ()
186
186
with patch ("%s.search" % class_name , new_callable = PropertyMock ):
187
187
res = rec_id .action_backup_all ()
188
188
self .assertEqual (rec_id .search ().action_backup (), res )
189
189
190
190
@patch ("%s.pysftp" % model )
191
191
def test_sftp_connection_init_passwd (self , pysftp ):
192
- """ It should initiate SFTP connection w/ proper args and pass """
192
+ """It should initiate SFTP connection w/ proper args and pass"""
193
193
rec_id = self .new_record ()
194
194
rec_id .sftp_connection ()
195
195
pysftp .Connection .assert_called_once_with (
@@ -201,7 +201,7 @@ def test_sftp_connection_init_passwd(self, pysftp):
201
201
202
202
@patch ("%s.pysftp" % model )
203
203
def test_sftp_connection_init_key (self , pysftp ):
204
- """ It should initiate SFTP connection w/ proper args and key """
204
+ """It should initiate SFTP connection w/ proper args and key"""
205
205
rec_id = self .new_record ()
206
206
rec_id .write ({"sftp_private_key" : "pkey" , "sftp_password" : "pkeypass" })
207
207
rec_id .sftp_connection ()
@@ -215,7 +215,7 @@ def test_sftp_connection_init_key(self, pysftp):
215
215
216
216
@patch ("%s.pysftp" % model )
217
217
def test_sftp_connection_return (self , pysftp ):
218
- """ It should return new sftp connection """
218
+ """It should return new sftp connection"""
219
219
rec_id = self .new_record ()
220
220
res = rec_id .sftp_connection ()
221
221
self .assertEqual (
@@ -224,19 +224,19 @@ def test_sftp_connection_return(self, pysftp):
224
224
)
225
225
226
226
def test_filename_default (self ):
227
- """ It should not error and should return a .dump.zip file str """
227
+ """It should not error and should return a .dump.zip file str"""
228
228
now = datetime .now ()
229
229
res = self .Model .filename (now )
230
230
self .assertTrue (res .endswith (".dump.zip" ))
231
231
232
232
def test_filename_zip (self ):
233
- """ It should return a dump.zip filename"""
233
+ """It should return a dump.zip filename"""
234
234
now = datetime .now ()
235
235
res = self .Model .filename (now , ext = "zip" )
236
236
self .assertTrue (res .endswith (".dump.zip" ))
237
237
238
238
def test_filename_dump (self ):
239
- """ It should return a dump filename"""
239
+ """It should return a dump filename"""
240
240
now = datetime .now ()
241
241
res = self .Model .filename (now , ext = "dump" )
242
242
self .assertTrue (res .endswith (".dump" ))
0 commit comments