Skip to content

Commit e369bb4

Browse files
CopilotMichaIng
andauthored
test(config): assert exact restored file sets
Agent-Logs-Url: https://github.com/motioneye-project/motioneye/sessions/00a4e7c8-9dfa-4f02-9b39-e917cebeea6a Co-authored-by: MichaIng <28480705+MichaIng@users.noreply.github.com>
1 parent e02b162 commit e369bb4

1 file changed

Lines changed: 12 additions & 33 deletions

File tree

‎tests/test_config.py‎

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,16 @@ def _make_tarball_members(
176176
tf.addfile(info, BytesIO(data))
177177
return buf.getvalue()
178178

179+
def _assert_restored_files(self, expected: list[str]):
180+
self.assertEqual(sorted(os.listdir(self.conf_dir)), sorted(expected))
181+
179182
def test_restore_extracts_motion_conf(self):
180183
content = b'[motion]\ndaemon = on\n'
181184
tarball = self._make_tarball({'motion.conf': content})
182185

183186
result = config.restore(tarball)
184187
self.assertIsNotNone(result)
185-
self.assertIn('motion.conf', os.listdir(self.conf_dir))
188+
self._assert_restored_files(['motion.conf'])
186189
with open(os.path.join(self.conf_dir, 'motion.conf'), 'rb') as f:
187190
self.assertEqual(f.read(), content)
188191

@@ -196,9 +199,7 @@ def test_restore_extracts_camera_confs(self):
196199

197200
result = config.restore(tarball)
198201
self.assertIsNotNone(result)
199-
files = os.listdir(self.conf_dir)
200-
self.assertIn('camera-1.conf', files)
201-
self.assertIn('camera-42.conf', files)
202+
self._assert_restored_files(['camera-1.conf', 'camera-42.conf'])
202203

203204
def test_restore_extracts_mask_files(self):
204205
tarball = self._make_tarball(
@@ -210,16 +211,14 @@ def test_restore_extracts_mask_files(self):
210211

211212
result = config.restore(tarball)
212213
self.assertIsNotNone(result)
213-
files = os.listdir(self.conf_dir)
214-
self.assertIn('mask_1.pgm', files)
215-
self.assertIn('mask_2.pgm', files)
214+
self._assert_restored_files(['mask_1.pgm', 'mask_2.pgm'])
216215

217216
def test_restore_extracts_prefs_json(self):
218217
tarball = self._make_tarball({'prefs.json': b'{}'})
219218

220219
result = config.restore(tarball)
221220
self.assertIsNotNone(result)
222-
self.assertIn('prefs.json', os.listdir(self.conf_dir))
221+
self._assert_restored_files(['prefs.json'])
223222

224223
def test_restore_ignores_non_matching_files(self):
225224
tarball = self._make_tarball(
@@ -233,11 +232,7 @@ def test_restore_ignores_non_matching_files(self):
233232

234233
result = config.restore(tarball)
235234
self.assertIsNotNone(result)
236-
files = os.listdir(self.conf_dir)
237-
self.assertIn('motion.conf', files)
238-
self.assertNotIn('uploadservices.json', files)
239-
self.assertNotIn('secrets.json', files)
240-
self.assertNotIn('motioneye.conf', files)
235+
self._assert_restored_files(['motion.conf'])
241236

242237
def test_restore_ignores_non_regular_members(self):
243238
camera_symlink_info = tarfile.TarInfo(name='camera-9.conf')
@@ -258,10 +253,7 @@ def test_restore_ignores_non_regular_members(self):
258253

259254
result = config.restore(tarball)
260255
self.assertIsNotNone(result)
261-
files = os.listdir(self.conf_dir)
262-
self.assertIn('motion.conf', files)
263-
self.assertNotIn('camera-9.conf', files)
264-
self.assertNotIn('mask_9.pgm', files)
256+
self._assert_restored_files(['motion.conf'])
265257

266258
def test_restore_ignores_absolute_paths(self):
267259
tarball = self._make_tarball(
@@ -276,11 +268,7 @@ def test_restore_ignores_absolute_paths(self):
276268

277269
result = config.restore(tarball)
278270
self.assertIsNotNone(result)
279-
files = os.listdir(self.conf_dir)
280-
self.assertIn('motion.conf', files)
281-
self.assertNotIn('camera-1.conf', files)
282-
self.assertNotIn('mask_1.pgm', files)
283-
self.assertNotIn('prefs.json', files)
271+
self._assert_restored_files(['motion.conf'])
284272

285273
def test_restore_ignores_pattern_matches_with_path_elements(self):
286274
tarball = self._make_tarball(
@@ -299,24 +287,15 @@ def test_restore_ignores_pattern_matches_with_path_elements(self):
299287

300288
result = config.restore(tarball)
301289
self.assertIsNotNone(result)
302-
files = os.listdir(self.conf_dir)
303-
self.assertIn('camera-1.conf', files)
304-
self.assertIn('mask_1.pgm', files)
305-
self.assertNotIn('camera-2.conf', files)
306-
self.assertNotIn('camera-3.conf', files)
307-
self.assertNotIn('camera-4.conf', files)
308-
self.assertNotIn('camera-5.conf', files)
309-
self.assertNotIn('mask_2.pgm', files)
310-
self.assertNotIn('mask_3.pgm', files)
311-
self.assertNotIn('mask_4.pgm', files)
290+
self._assert_restored_files(['camera-1.conf', 'mask_1.pgm'])
312291

313292
def test_restore_accepts_dot_slash_prefix(self):
314293
"""Tarball entries prefixed with ./ (e.g. from GNU tar) should still be accepted."""
315294
tarball = self._make_tarball({'./motion.conf': b'[motion]\n'})
316295

317296
result = config.restore(tarball)
318297
self.assertIsNotNone(result)
319-
self.assertIn('motion.conf', os.listdir(self.conf_dir))
298+
self._assert_restored_files(['motion.conf'])
320299

321300
def test_restore_returns_reboot_false(self):
322301
tarball = self._make_tarball({'motion.conf': b'[motion]\n'})

0 commit comments

Comments
 (0)