Debian Codegraph @

tests.py

raw symbols SCIP
1 #!/usr/bin/python3.4
2 # -*- coding: utf-8 -*-
3 # Copyright © 2015 Carl Chenet <[email protected]>
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17 import argparse
18 import bz2
19 import gzip
20 import logging
21 import os
22 import os.path
23 import stat
24 import sys
25 import tarfile
26 import unittest
27 import zipfile
28
29 import brebis.applogger
30 import brebis.archiveinfomsg
31 import brebis.checkbackups.checkarchive
32 import brebis.checkbackups.checkbackups
33 import brebis.checkbackups.checkbzip2
34 import brebis.checkbackups.checkgzip
35 import brebis.checkbackups.checklzma
36 import brebis.checkhashes
37 import brebis.checkbackups.checktar
38 import brebis.checkbackups.checktree
39 import brebis.checkbackups.checkzip
40 import brebis.cliparse
41 import brebis.configurations
42 from brebis.expectedvalues import ExpectedValues
43 import brebis.generatelist.generatelistfortar
44 import brebis.generatelist.generatelistforbzip2
45 import brebis.listtype
46 import brebis.main
47
48 # !! logging module uses a single logger for the whole file
49 TESTLOG = 'tests/testlog'
50 DEFAULTDELIMITER = '|'
51
52 # mock the object produced by argparse, useful for lots of tests below
53 class Options:
54 '''Mock the object produced by argparse, useful for lots of unittests'''
55 def __init__(self):
56 self.delimiter = DEFAULTDELIMITER
57
58 class MyDict(dict):
59 '''mock object'''
60 pass
61
62 class TestApp(unittest.TestCase):
63
64 def test_applogger(self):
65 '''Test the AppLoggerclass'''
66 brebis.applogger.AppLogger(TESTLOG)
67 self.assertEqual(True, str(logging.getLogger('applogger')).startswith('<logging.Logger object at'))
68
69 def test_checkbackup(self):
70 '''Test the CheckBackup class'''
71 _logfile = TESTLOG
72 brebis.applogger.AppLogger(_logfile)
73 brebis.checkbackups.checkbackups.CheckBackups({'essai': {'path': 'tests/tar_gz_archive_content/essai.tar.gz', 'files_list': 'tests/tar_gz_archive_content/essai-list', 'type': 'archive','delimiter':''}, 'essai2': {'path': 'tests/tar_bz2_archive_content/titi.tar.bz2', 'files_list': 'tests/tar_bz2_archive_content/essai2-list', 'type': 'archive','delimiter':''}}, Options())
74 with open(_logfile) as _res:
75 self.assertIn('WARNING:root:1 file missing in tests/tar_gz_archive_content/essai.tar.gz: \nWARNING:root:essai/dir/titi\n', _res.read())
76
77 def test_checktar_missing_files(self):
78 '''Check if the CheckTar class returns a missing file'''
79 _missingfiles = []
80 _missingfiles = brebis.checkbackups.checktar.CheckTar({'path':
81 'tests/tar_gz_archive_content/essai.tar.gz',
82 'files_list':
83 'tests/tar_gz_archive_content/essai-list',
84 'type': 'archive', 'delimiter': ''}, Options()).missing_files
85 self.assertEqual(_missingfiles, ['essai/dir/titi'])
86
87 def test_checktar_missing_equality(self):
88 '''Check if the CheckTar class returns a dictionary with a file whose size should have been equal with the expected size'''
89 __missing_equality = []
90 __missing_equality = brebis.checkbackups.checktar.CheckTar({'path':
91 'tests/file_size/essai.tar.bz2',
92 'files_list':
93 'tests/file_size/essai-list',
94 'type': 'archive', 'delimiter': ''}, Options()).missing_equality
95 self.assertEqual(__missing_equality[0]['path'], 'essai/dir/toto')
96
97 def test_checktar_missing_bigger_than(self):
98 '''Check if the CheckTar class returns a dictionary with a file whose size should have been bigger than the expected size'''
99 __missing_bigger_than = []
100 __missing_bigger_than = brebis.checkbackups.checktar.CheckTar({'path':
101 'tests/file_size/essai.tar.bz2',
102 'files_list':
103 'tests/file_size/essai-list',
104 'type': 'archive', 'delimiter': ''}, Options()).missing_bigger_than
105 self.assertEqual(__missing_bigger_than[0]['path'], 'essai/titi')
106
107 def test_checktar_missing_smaller_than(self):
108 '''Check if the CheckTar class returns a dictionary with a file whose size should have been smaller than the expected size'''
109 __missing_smaller_than = []
110 __missing_smaller_than = brebis.checkbackups.checktar.CheckTar({'path':
111 'tests/file_size/essai.tar.bz2',
112 'files_list':
113 'tests/file_size/essai-list',
114 'type': 'archive', 'delimiter': ''}, Options()).missing_smaller_than
115 self.assertEqual(__missing_smaller_than[0]['path'], 'essai/dir/toutou')
116
117 def test_checktree_missing_files(self):
118 '''Check if the CheckTar class returns a missing file'''
119 __missing_files = []
120 __missing_files = brebis.checkbackups.checktree.CheckTree({'path':
121 'tests/filetree/foo',
122 'files_list':
123 'tests/filetree/filelist',
124 'type': 'tree', 'delimiter': ''}, Options()).missing_files
125 self.assertEqual(__missing_files, ['bar/toto'])
126
127 def test_checktree_missing_equality(self):
128 '''Check if the CheckTree class returns a dictionary with a file whose size should have been equal with the expected size'''
129 __missing_equality= []
130 __missing_equality = brebis.checkbackups.checktree.CheckTree({'path':
131 'tests/filetree/foo',
132 'files_list':
133 'tests/filetree/filelist',
134 'type': 'tree', 'delimiter': ''}, Options()).missing_equality
135 self.assertEqual(__missing_equality[0]['path'], 'foo1')
136
137 def test_checktree_missing_bigger_than(self):
138 '''Check if the CheckTree class returns a dictionary with a file whose size should have been bigger than the expected size'''
139 __missing_bigger_than = []
140 __missing_bigger_than = brebis.checkbackups.checktree.CheckTree({'path':
141 'tests/filetree/foo',
142 'files_list':
143 'tests/filetree/filelist',
144 'type': 'tree', 'delimiter': ''}, Options()).missing_bigger_than
145 self.assertEqual(__missing_bigger_than[0]['path'], 'foo2')
146
147 def test_checktree_missing_smaller_than(self):
148 '''Check if the CheckTree class returns a dictionary with a file whose size should have been smaller than the expected size'''
149 __missing_smaller_than = []
150 __missing_smaller_than = brebis.checkbackups.checktree.CheckTree({'path':
151 'tests/filetree/foo',
152 'files_list':
153 'tests/filetree/filelist',
154 'type': 'tree', 'delimiter': ''}, Options()).missing_smaller_than
155 self.assertEqual(__missing_smaller_than[0]['path'], 'bar/foo3')
156
157 #######################################################################################
158 #
159 # Testing the brebis/checkbackup/checkgzip module
160 #
161 #######################################################################################
162
163 def test_checkgzip_missing_files(self):
164 '''Check if the CheckGzip class returns a missing file'''
165 _missing_files = []
166 _missing_files = brebis.checkbackups.checkgzip.CheckGzip({'path':
167 'tests/gzip/mygzip.gz',
168 'files_list':
169 'tests/gzip/mygzip-list',
170 'type': 'archive', 'delimiter': ''}, Options()).missing_files
171 self.assertEqual(_missing_files, ['foo'])
172
173 def test_checkgzip_missing_equality(self):
174 '''Check if the CheckGzip class returns a dictionary with a file whose size should have been equal with the expected size'''
175 __missing_equality = []
176 __missing_equality = brebis.checkbackups.checkgzip.CheckGzip({'path':
177 'tests/file_size/mygzip.gz',
178 'files_list':
179 'tests/file_size/mygzip-list',
180 'type': 'archive', 'delimiter': ''}, Options()).missing_equality
181 self.assertEqual(__missing_equality[0]['path'], 'mygzip')
182
183 def test_checkgzip_missing_bigger_than(self):
184 '''Check if the CheckGzip class returns a dictionary with a file whose size should have been bigger than the expected size'''
185 __missing_bigger_than= []
186 __missing_bigger_than = brebis.checkbackups.checkgzip.CheckGzip({'path':
187 'tests/file_size/missing-bigger-than/mygzip.gz',
188 'files_list':
189 'tests/file_size/missing-bigger-than/mygzip-list',
190 'type': 'archive', 'delimiter': ''}, Options()).missing_bigger_than
191 self.assertEqual(__missing_bigger_than[0]['path'], 'mygzip')
192
193 def test_checkgzip_missing_smaller_than(self):
194 '''Check if the CheckGzip class returns a dictionary with a file whose size should have been smaller than the expected size'''
195 __missing_smaller_than= []
196 __missing_smaller_than = brebis.checkbackups.checkgzip.CheckGzip({'path':
197 'tests/file_size/missing-smaller-than/mygzip.gz',
198 'files_list':
199 'tests/file_size/missing-smaller-than/mygzip-list',
200 'type': 'archive', 'delimiter': ''}, Options()).missing_smaller_than
201 self.assertEqual(__missing_smaller_than[0]['path'], 'mygzip')
202
203 #######################################################################################
204 #
205 # Testing the brebis/checkbackup/checklzma module
206 #
207 #######################################################################################
208
209 def test_checklzma_missing_files(self):
210 '''Check if the CheckLzma class returns a missing file'''
211 _missing_files = []
212 _missing_files = brebis.checkbackups.checklzma.CheckLzma({'path':
213 'tests/lzma/mylzma.xz',
214 'files_list':
215 'tests/lzma/mylzma-list',
216 'type': 'archive', 'delimiter': ''}, Options()).missing_files
217 self.assertEqual(_missing_files, ['foo'])
218
219 #######################################################################################
220 #
221 # Testing the brebis/checkbackup/checkzip module
222 #
223 #######################################################################################
224
225 def test_checkzip_missing_files(self):
226 '''Check if the CheckZip class returns a missing file'''
227 _missing_files = []
228 _missing_files = brebis.checkbackups.checkzip.CheckZip({'path':
229 'tests/zip/myzip.zip',
230 'files_list':
231 'tests/zip/myzip-list',
232 'type': 'archive', 'delimiter': ''}, Options()).missing_files
233 self.assertEqual(_missing_files, ['toto/bling'])
234
235 def test_checkzip_missing_equality(self):
236 '''Check if the CheckZip class returns a dictionary with a file whose size should have been equal with the expected size'''
237 __missing_equality = []
238 __missing_equality = brebis.checkbackups.checkzip.CheckZip({'path':
239 'tests/file_size/myzip.zip',
240 'files_list':
241 'tests/file_size/essai-list2',
242 'type': 'archive', 'delimiter': ''}, Options()).missing_equality
243 self.assertEqual(__missing_equality[0]['path'], 'myzip/titi')
244
245 def test_checkzip_missing_bigger_than(self):
246 '''Check if the CheckZip class returns a dictionary with a file whose size should have been bigger than the expected size'''
247 __missing_bigger_than= []
248 __missing_bigger_than = brebis.checkbackups.checkzip.CheckZip({'path':
249 'tests/file_size/myzip.zip',
250 'files_list':
251 'tests/file_size/essai-list2',
252 'type': 'archive', 'delimiter': ''}, Options()).missing_bigger_than
253 self.assertEqual(__missing_bigger_than[0]['path'], 'myzip/foo/toto')
254
255 def test_checkzip_missing_smaller_than(self):
256 '''Check if the CheckZip class returns a dictionary with a file whose size should have been smaller than the expected size'''
257 __missing_smaller_than= []
258 __missing_smaller_than = brebis.checkbackups.checkzip.CheckZip({'path':
259 'tests/file_size/myzip.zip',
260 'files_list':
261 'tests/file_size/essai-list2',
262 'type': 'archive', 'delimiter': ''}, Options()).missing_smaller_than
263 self.assertEqual(__missing_smaller_than[0]['path'], 'myzip/toutou')
264
265 #######################################################################################
266 #
267 # Testing the brebis/configurations module
268 #
269 #######################################################################################
270
271 def test_configurations(self):
272 '''Test the Configurations.configs attribute of the Configurations class'''
273 __path = os.path.abspath('tests/test_conf/')
274 __res = brebis.configurations.Configurations(__path).configs
275 self.assertEqual({'essai': {'path': os.path.normpath(os.path.join(__path,'essai.tar.gz')), 'sha512': None, 'files_list': os.path.normpath(os.path.join(__path,'essai-list')), 'type': 'archive', 'delimiter': '|'}}, __res)
276
277 def test_configurations_with_subdir(self):
278 '''Test the Configurations.configs attribute of the Configurations class'''
279 __path = os.path.abspath('tests/test_conf/subdir/')
280 __res = brebis.configurations.Configurations(__path).configs
281 self.assertEqual({'essai2': {'path': os.path.normpath(os.path.join(__path, 'toto/essai.tar.gz')), 'sha512': None, 'files_list': os.path.normpath(os.path.join(__path, 'toto/essai-list')), 'type': 'archive', 'delimiter': None}}, __res)
282
283 def test_configurations_strip_gpg_header(self):
284 '''Test the Configurations.configs attribute of the Configurations class'''
285 __base = os.path.abspath('tests/test_conf_gpg/')
286 __path = os.path.join(__base, 'archive.conf')
287 __strippedfilepath = os.path.join(__base, 'result')
288 __myobj = brebis.configurations.Configurations(__path)
289 with open(__path) as __myfile:
290 __newfile = __myobj.strip_gpg_header(__myfile, __path)
291 with open(__strippedfilepath) as __good:
292 __goodfile = __good.read()
293 self.assertEqual(__newfile, __goodfile)
294
295 #######################################################################################
296 #
297 # Testing the brebis/expectedvalues module
298 #
299 #######################################################################################
300 def test_expected_values(self):
301 '''Check the ExpectedValues class'''
302 __data, _ = ExpectedValues({'files_list':'tests/file_size/essai-list','delimiter':''}, Options()).data
303 self.assertEqual([{'path':'essai/dir/toto', 'equals':536870912},
304 {'path':'essai/titi','biggerthan':536870912},
305 {'path':'essai/dir/toutou','smallerthan':19},
306 {'path':'essai/dir/zozo'}], __data)
307
308 def test_unexpected_files(self):
309 '''Check if an unexpected file is identified'''
310 __data, _ = ExpectedValues({'files_list':'tests/unexpected_files/files-list','delimiter':''}, Options()).data
311 self.assertEqual([{'path':'foo/foo1'},{'path':'foo/foo2'},
312 {'path':'foo/bar','unexpected':True}], __data)
313
314 def test_extract_expected_uid_gid(self):
315 '''Check the uid and gid of an expected file'''
316 __data, _ = ExpectedValues({'files_list':'tests/expected_uid_gid/files-list','delimiter':''}, Options()).data
317 self.assertEqual([{'path':'foo/foo1', 'uid':1001, 'gid':1001}], __data)
318
319 def test_compare_uid_gid(self):
320 '''Compare the uid and the gid of a file in the archive
321 and the expected one
322 '''
323 __uids = []
324 __gids = []
325 __myobj = brebis.checkbackups.checktar.CheckTar({'path':
326 'tests/expected_uid_gid/foo.tar.gz',
327 'files_list':
328 'tests/expected_uid_gid/files-list',
329 'type': 'archive', 'delimiter': ''}, Options())
330 __uids = __myobj.mismatched_uids
331 __gids = __myobj.mismatched_gids
332 self.assertEqual((__uids[0],__gids[0]), (
333 {'path':'foo/foo1','expecteduid':1001,'uid':1000},
334 {'path':'foo/foo1','expectedgid':1001,'gid':1000}))
335
336 def test_extract_modes(self):
337 '''Extract the expected file modes'''
338 __data, _ = ExpectedValues({'files_list':'tests/expected_mode/files-list','delimiter':''}, Options()).data
339 self.assertEqual([{'path':'foos/foo1', 'mode': '644'},
340 {'path':'foos/foo2', 'mode': '755'},
341 {'path':'foos/bar/foo3', 'mode': '4644'},
342 {'path':'foos/bar', 'mode': '754'}], __data)
343
344 def test_archive_compare_mode(self):
345 '''Compare the mode of a file in the archive and the
346 expected one
347 '''
348 __myobj = brebis.checkbackups.checktar.CheckTar({'path':
349 'tests/expected_mode/foos.tar.gz',
350 'files_list':
351 'tests/expected_mode/files-list',
352 'type': 'archive', 'delimiter': ''}, Options())
353 __modes = __myobj.mismatched_modes
354 self.assertEqual(__modes, [
355 {'path':'foos/foo2','expectedmode':'755','mode':'754'},
356 {'path':'foos/bar','expectedmode':'754','mode':'755'},
357 {'path':'foos/bar/foo3','expectedmode':'4644','mode':'4600'},
358 {'path':'foos/foo1','expectedmode':'644','mode':'744'}])
359
360 def test_extract_types(self):
361 '''Extract the expected file types'''
362 __data, _ = ExpectedValues({'files_list':'tests/expected_type/files-list','delimiter':''}, Options()).data
363 self.assertEqual([{'path':'foos/foo1', 'type': 'f'},
364 {'path':'foos/foo2', 'type': 'c'},
365 {'path':'foos/foo3', 'type': 'd'},
366 {'path':'foos/foo4', 'type': 's'},
367 {'path':'foos/foo5', 'type': 'b'},
368 {'path':'foos/foo6', 'type': 'k'},
369 {'path':'foos/foo7', 'type': 'o'}], __data)
370
371 def test_archive_compare_type(self):
372 '''Compare the type of a file in the archive and the
373 expected one
374 '''
375 __myobj = brebis.checkbackups.checktar.CheckTar({'path':
376 'tests/expected_type/foos.tar.gz',
377 'files_list':
378 'tests/expected_type/files-list',
379 'type': 'archive', 'delimiter': ''}, Options())
380 __types = __myobj.mismatched_types
381 self.assertEqual(__types, [
382 {'path':'foos/foo3','expectedtype':'d','type':'f'},
383 {'path':'foos/foo2','expectedtype':'c','type':'f'},
384 {'path':'foos/foo4','expectedtype':'s','type':'f'},
385 {'path':'foos/foo6','expectedtype':'k','type':'f'},
386 {'path':'foos/foo1','expectedtype':'f','type':'d'},
387 {'path':'foos/foo5','expectedtype':'b','type':'f'},
388 {'path':'foos/foo7','expectedtype':'o','type':'f'}])
389
390 def test_extract_hashes(self):
391 '''Extract the expected file hashes'''
392 __data, _ = ExpectedValues({'files_list':'tests/expected_hash/files-list','delimiter':''}, Options()).data
393 self.assertEqual([{'hash': {'hashtype': 'md5',
394 'hashvalue': '3718422a0bf93f7fc46cff6b5e660ff8'},
395 'path': 'foos/foo1'},
396 {'hash': {'hashtype': 'sha1',
397 'hashvalue': 'e0f58dcc57caad2182f701eb63f0c81f347d3fe5'},
398 'path': 'foos/foo2'},
399 {'hash': {'hashtype': 'sha224',
400 'hashvalue': 'g3c1d88024b6e2e333cbf8bed96182a62fbafaf2aea6dd8b17639552'},
401 'path': 'foos/foo3'},
402 {'hash': {'hashtype': 'sha256',
403 'hashvalue': '35a670af482f46a76f8033e05cca7a53a58456fa42ef47ea56ffd2b16e408863'},
404 'path': 'foos/foo4'},
405 {'hash': {'hashtype': 'sha384',
406 'hashvalue': '744e19f5c4258a573400b5059747d88797b150c08456e406e6473bd777332c5f66afe66c5bf77820906b97961c124810'},
407 'path': 'foos/foo5'},
408 {'hash': {'hashtype': 'sha512',
409 'hashvalue': 'c46dcb0f5124bd681cb5b91c812d2982efce703806026b1f9ffdeadf45c4128cd3e61fa939a0bc89af317e70d0d6c74b666edff9bd7ad9052cb8e7f42c8f7644'},
410 'path': 'foos/foo6'}],
411 __data)
412
413 def test_archive_tar_compare_hash(self):
414 '''Compare the hash of a file in the tar archive and the
415 expected one
416 '''
417 __myobj = brebis.checkbackups.checktar.CheckTar({'path':
418 'tests/expected_hash/foos.tar.gz',
419 'files_list':
420 'tests/expected_hash/files-list',
421 'type': 'archive', 'delimiter': ''}, Options())
422 __hashes = __myobj.mismatched_hashes
423 self.assertEqual(__hashes, [
424 {'path': 'foos/foo3',
425 'expectedhash': 'g3c1d88024b6e2e333cbf8bed96182a62fbafaf2aea6dd8b17639552',
426 'hash':'f3c1d88024b6e2e333cbf8bed96182a62fbafaf2aea6dd8b17639552'},
427 {'path': 'foos/foo2',
428 'expectedhash': 'e0f58dcc57caad2182f701eb63f0c81f347d3fe5',
429 'hash': 'd0f58dcc57caad2182f701eb63f0c81f347d3fe5'},
430 {'path': 'foos/foo4',
431 'expectedhash': '35a670af482f46a76f8033e05cca7a53a58456fa42ef47ea56ffd2b16e408863',
432 'hash': '25a670af482f46a76f8033e05cca7a53a58456fa42ef47ea56ffd2b16e408863'},
433 {'path': 'foos/foo6',
434 'expectedhash': 'c46dcb0f5124bd681cb5b91c812d2982efce703806026b1f9ffdeadf45c4128cd3e61fa939a0bc89af317e70d0d6c74b666edff9bd7ad9052cb8e7f42c8f7644',
435 'hash': 'b46dcb0f5124bd681cb5b91c812d2982efce703806026b1f9ffdeadf45c4128cd3e61fa939a0bc89af317e70d0d6c74b666edff9bd7ad9052cb8e7f42c8f7644'},
436 {'path': 'foos/foo1',
437 'expectedhash': '3718422a0bf93f7fc46cff6b5e660ff8',
438 'hash': '2718422a0bf93f7fc46cff6b5e660ff8'},
439 {'path': 'foos/foo5',
440 'expectedhash': '744e19f5c4258a573400b5059747d88797b150c08456e406e6473bd777332c5f66afe66c5bf77820906b97961c124810',
441 'hash': '644e19f5c4258a573400b5059747d88797b150c08456e406e6473bd777332c5f66afe66c5bf77820906b97961c124810'}])
442
443
444 def test_zip_compare_hash(self):
445 '''Compare the hash of a file in the zip archive and the
446 expected one
447 '''
448 __myobj = brebis.checkbackups.checkzip.CheckZip({'path':
449 'tests/expected_hash/bar.zip',
450 'files_list':
451 'tests/expected_hash/zip-list',
452 'type': 'archive', 'delimiter': ''}, Options())
453 __hashes = __myobj.mismatched_hashes
454 self.assertEqual(__hashes, [
455 {'path': 'bar/bar5',
456 'expectedhash': '65305af91a511f6d091237f97e5dbccd1427c6f48bcd509acd0a71938bfe9d708cfb93c3d163f96b328f6cabb80b0860',
457 'hash':'55305af91a511f6d091237f97e5dbccd1427c6f48bcd509acd0a71938bfe9d708cfb93c3d163f96b328f6cabb80b0860'},
458 {'path': 'bar/bar4',
459 'expectedhash': 'd67f2596a1ef0893f176b0b68d6e1445a9acd5fda2f5a073f1318ff4b75e5b84',
460 'hash': 'c67f2596a1ef0893f176b0b68d6e1445a9acd5fda2f5a073f1318ff4b75e5b84'},
461 {'path': 'bar/bar6',
462 'expectedhash': 'g0fc5b14ab8b242e4c6462deee58a0a10fabdb4bc792174fdeec92cd12df8d5a7a8fed9545e2c109b3cecd345d970afaea0183ea0dd19371913cb55b23b9fc2e',
463 'hash': 'f0fc5b14ab8b242e4c6462deee58a0a10fabdb4bc792174fdeec92cd12df8d5a7a8fed9545e2c109b3cecd345d970afaea0183ea0dd19371913cb55b23b9fc2e'},
464 {'path': 'bar/bar3',
465 'expectedhash': '33975be818906ec2228074d2a4438ef8f78ec33792aac4d037ad8f95',
466 'hash': '23975be818906ec2228074d2a4438ef8f78ec33792aac4d037ad8f95'},
467 {'path': 'bar/bar1',
468 'expectedhash': '9151b18e6dd21a734890b56b5a15d24b',
469 'hash': '8151b18e6dd21a734890b56b5a15d24b'},
470 {'path': 'bar/bar2',
471 'expectedhash': '3676c9d706eb6f6b02eb5d67ba86a9b3e855c13d',
472 'hash': '2676c9d706eb6f6b02eb5d67ba86a9b3e855c13d'}])
473
474 def test_gzip_compare_hash(self):
475 '''Compare the hash of a file in the gzip archive and the
476 expected one
477 '''
478 __myobj = brebis.checkbackups.checkgzip.CheckGzip({'path':
479 'tests/expected_hash/bar.gz',
480 'files_list':
481 'tests/expected_hash/gzip-list',
482 'type': 'archive', 'delimiter': ''}, Options())
483 __hashes = __myobj.mismatched_hashes
484 self.assertEqual(__hashes, [
485 {'path': 'bar',
486 'expectedhash': 'ede',
487 'hash': 'ede69eff9660689e65c5e47bb849f152'}])
488
489 def test_lzma_compare_hash(self):
490 '''Compare the hash of a file in the lzma archive and the
491 expected one
492 '''
493 __myobj = brebis.checkbackups.checklzma.CheckLzma({'path':
494 'tests/expected_hash/bar.xz',
495 'files_list':
496 'tests/expected_hash/lzma-list',
497 'type': 'archive', 'delimiter': ''}, Options())
498 __hashes = __myobj.mismatched_hashes
499 self.assertEqual(__hashes, [
500 {'path': 'bar',
501 'expectedhash': 'ede',
502 'hash': '39fe9ceedb3aac1755142e7f425a5961'}])
503
504 def test_bzip2_compare_hash(self):
505 '''Compare the hash of a file in the bzip2 archive and the
506 expected one
507 '''
508 __myobj = brebis.checkbackups.checkbzip2.CheckBzip2({'path':
509 'tests/expected_hash/bar.bz2',
510 'files_list':
511 'tests/expected_hash/bzip2-list',
512 'type': 'archive', 'delimiter': ''}, Options())
513 __hashes = __myobj.mismatched_hashes
514 self.assertEqual(__hashes, [
515 {'path': 'bar',
516 'expectedhash': '768',
517 'hash': '768d0a4cdfde46a468b6d9ba01a19a2a'}])
518
519 def test_checktar_archive_equal_size(self):
520 '''Check if the CheckTar class returns a dictionary with the
521 archive itself file whose size should have been equal
522 to the expected size.
523 '''
524 __missing_equality = []
525 __missing_equality = brebis.checkbackups.checktar.CheckTar({'path':
526 'tests/file_size/essai.tar.bz2',
527 'files_list':
528 'tests/file_size/arcsize/equaltararcsize-list',
529 'type': 'archive', 'delimiter': ''}, Options()).missing_equality
530 self.assertEqual(__missing_equality[0]['path'], 'tests/file_size/essai.tar.bz2')
531
532 def test_checktar_archive_missing_smaller_than(self):
533 '''Check if the CheckTar class returns a dictionary with the
534 archive itself whose size should have been smaller
535 than the expected size.
536 '''
537 __missing_smaller_than = []
538 __missing_smaller_than = brebis.checkbackups.checktar.CheckTar({'path':
539 'tests/file_size/essai.tar.bz2',
540 'files_list':
541 'tests/file_size/arcsize/biggerthantararcsize-list',
542 'type': 'archive', 'delimiter': ''}, Options()).missing_smaller_than
543 self.assertEqual(__missing_smaller_than[0]['path'], 'tests/file_size/essai.tar.bz2')
544
545 def test_checktar_archive_missing_bigger_than(self):
546 '''Check if the CheckTar class returns a dictionary with the
547 archive itself whose size should have been bigger
548 than the expected size.
549 '''
550 __missing_bigger_than = []
551 __missing_bigger_than = brebis.checkbackups.checktar.CheckTar({'path':
552 'tests/file_size/essai.tar.bz2',
553 'files_list':
554 'tests/file_size/arcsize/smallerthantararcsize-list',
555 'type': 'archive', 'delimiter': ''}, Options()).missing_bigger_than
556 self.assertEqual(__missing_bigger_than[0]['path'], 'tests/file_size/essai.tar.bz2')
557
558 def test_checkzip_archive_equal_size(self):
559 '''Check if the CheckZip class returns a dictionary with the
560 archive itself file whose size should have been equal
561 to the expected size.
562 '''
563 __missing_equality = []
564 __missing_equality = brebis.checkbackups.checkzip.CheckZip({'path':
565 'tests/file_size/myzip.zip',
566 'files_list':
567 'tests/file_size/arcsize/equalziparcsize-list',
568 'type': 'archive', 'delimiter': ''}, Options()).missing_equality
569 self.assertEqual(__missing_equality[0]['path'], 'tests/file_size/myzip.zip')
570
571 def test_checkzip_archive_missing_smaller_than(self):
572 '''Check if the CheckZip class returns a dictionary with the
573 archive itself whose size should have been smaller
574 than the expected size.
575 '''
576 __missing_smaller_than = []
577 __missing_smaller_than = brebis.checkbackups.checkzip.CheckZip({'path':
578 'tests/file_size/myzip.zip',
579 'files_list':
580 'tests/file_size/arcsize/biggerthanziparcsize-list',
581 'type': 'archive', 'delimiter': ''}, Options()).missing_smaller_than
582 self.assertEqual(__missing_smaller_than[0]['path'], 'tests/file_size/myzip.zip')
583
584 def test_checkzip_archive_missing_bigger_than(self):
585 '''Check if the CheckZip class returns a dictionary with the
586 archive itself whose size should have been bigger
587 than the expected size.
588 '''
589 __missing_bigger_than = []
590 __missing_bigger_than = brebis.checkbackups.checkzip.CheckZip({'path':
591 'tests/file_size/myzip.zip',
592 'files_list':
593 'tests/file_size/arcsize/smallerthanziparcsize-list',
594 'type': 'archive', 'delimiter': ''}, Options()).missing_bigger_than
595 self.assertEqual(__missing_bigger_than[0]['path'], 'tests/file_size/myzip.zip')
596
597 def test_checktar_md5_hash_archive(self):
598 '''Check the md5 hash of the tar archive itself using CheckTar class'''
599 __mismatchedhashes = brebis.checkbackups.checktar.CheckTar({'path':
600 'tests/expected_hash/archash/mytar.tar.gz',
601 'files_list':
602 'tests/expected_hash/archash/md5hashtararchive-list',
603 'type': 'archive', 'delimiter': ''}, Options()).mismatched_hashes
604 self.assertEqual(__mismatchedhashes[0], {'path': 'tests/expected_hash/archash/mytar.tar.gz',
605 'expectedhash': '47907de120577e6ba3b9dd8821374937',
606 'hash': '47907de120577e6ba3b9dd8821374936'})
607
608 def test_checktar_sha1_hash_archive(self):
609 '''Check the sha1 hash of the tar archive itself using CheckTar class'''
610 __mismatchedhashes = brebis.checkbackups.checktar.CheckTar({'path':
611 'tests/expected_hash/archash/mytar.tar.gz',
612 'files_list':
613 'tests/expected_hash/archash/sha1hashtararchive-list',
614 'type': 'archive', 'delimiter': ''}, Options()).mismatched_hashes
615 self.assertEqual(__mismatchedhashes[0], {'path': 'tests/expected_hash/archash/mytar.tar.gz',
616 'expectedhash': '84db203e2902fa5ea51e6d46ea365c7bfc5524b9',
617 'hash': '84db203e2902fa5ea51e6d46ea365c7bfc5524b8'})
618
619 def test_checktar_sha224_hash_archive(self):
620 '''Check the sha224 hash of the tar archive itself using CheckTar class'''
621 __mismatchedhashes = brebis.checkbackups.checktar.CheckTar({'path':
622 'tests/expected_hash/archash/mytar.tar.gz',
623 'files_list':
624 'tests/expected_hash/archash/sha224hashtararchive-list',
625 'type': 'archive', 'delimiter': ''}, Options()).mismatched_hashes
626 self.assertEqual(__mismatchedhashes[0], {'path': 'tests/expected_hash/archash/mytar.tar.gz',
627 'expectedhash': 'e25621dfdd2b2cfca451c735f4e676653e8628187e2b7ddc14402c1e',
628 'hash': 'e25621dfdd2b2cfca451c735f4e676653e8628187e2b7ddc14402c1d'})
629
630 def test_checktar_sha256_hash_archive(self):
631 '''Check the sha256 hash of the tar archive itself using CheckTar class'''
632 __mismatchedhashes = brebis.checkbackups.checktar.CheckTar({'path':
633 'tests/expected_hash/archash/mytar.tar.gz',
634 'files_list':
635 'tests/expected_hash/archash/sha256hashtararchive-list',
636 'type': 'archive', 'delimiter': ''}, Options()).mismatched_hashes
637 self.assertEqual(__mismatchedhashes[0], {'path': 'tests/expected_hash/archash/mytar.tar.gz',
638 'expectedhash': '7090d29295216e95ab4a190d489aa405d141cac978567c227f17ee78eb3f5fd5',
639 'hash': '7090d29295216e95ab4a190d489aa405d141cac978567c227f17ee78eb3f5fd4'})
640
641 def test_checktar_sha384_hash_archive(self):
642 '''Check the sha384 hash of the tar archive itself using CheckTar class'''
643 __mismatchedhashes = brebis.checkbackups.checktar.CheckTar({'path':
644 'tests/expected_hash/archash/mytar.tar.gz',
645 'files_list':
646 'tests/expected_hash/archash/sha384hashtararchive-list',
647 'type': 'archive', 'delimiter': ''}, Options()).mismatched_hashes
648 self.assertEqual(__mismatchedhashes[0], {'path': 'tests/expected_hash/archash/mytar.tar.gz',
649 'expectedhash': 'aa01a55142a04de52cebba3797ca25054e51c33a5fbfdc4dd0cc2f01f6252c6a62cb87f35405d9d8b07a506eefacfd11',
650 'hash': 'aa01a55142a04de52cebba3797ca25054e51c33a5fbfdc4dd0cc2f01f6252c6a62cb87f35405d9d8b07a506eefacfd10'})
651
652 def test_checktar_sha512_hash_archive(self):
653 '''Check the sha512 hash of the tar archive itself using CheckTar class'''
654 __mismatchedhashes = brebis.checkbackups.checktar.CheckTar({'path':
655 'tests/expected_hash/archash/mytar.tar.gz',
656 'files_list':
657 'tests/expected_hash/archash/sha512hashtararchive-list',
658 'type': 'archive', 'delimiter': ''}, Options()).mismatched_hashes
659 self.assertEqual(__mismatchedhashes[0], {'path': 'tests/expected_hash/archash/mytar.tar.gz',
660 'expectedhash': 'd72eef1d9c42615f6b2a92848e8fa65ffd4276d91d9976fa8c644b41c15d91441ae42f897b30a2403795a876b14ae6ed8addca4a74f24839f6506a29e662e588',
661 'hash': 'd72eef1d9c42615f6b2a92848e8fa65ffd4276d91d9976fa8c644b41c15d91441ae42f897b30a2403795a876b14ae6ed8addca4a74f24839f6506a29e662e587'})
662
663 def test_checkzip_md5_hash_archive(self):
664 '''Check the md5 hash of the zip archive itself using CheckTar class'''
665 __mismatchedhashes = brebis.checkbackups.checkzip.CheckZip({'path':
666 'tests/expected_hash/archash/myzip.zip',
667 'files_list':
668 'tests/expected_hash/archash/md5hashziparchive-list',
669 'type': 'archive', 'delimiter': ''}, Options()).mismatched_hashes
670 self.assertEqual(__mismatchedhashes[0], {'path': 'tests/expected_hash/archash/myzip.zip',
671 'expectedhash': 'e48e1ce2fbe0db616632ba8030ac2c9e',
672 'hash': 'e48e1ce2fbe0db616632ba8030ac2c9f'})
673
674 def test_checkzip_sha1_hash_archive(self):
675 '''Check the sha1 hash of the zip archive itself using CheckTar class'''
676 __mismatchedhashes = brebis.checkbackups.checkzip.CheckZip({'path':
677 'tests/expected_hash/archash/myzip.zip',
678 'files_list':
679 'tests/expected_hash/archash/sha1hashziparchive-list',
680 'type': 'archive', 'delimiter': ''}, Options()).mismatched_hashes
681 self.assertEqual(__mismatchedhashes[0], {'path': 'tests/expected_hash/archash/myzip.zip',
682 'expectedhash': '4cd5933d78603d8b4ba484ef8e45d2b6bc9fd5ce',
683 'hash': '4cd5933d78603d8b4ba484ef8e45d2b6bc9fd5cf'})
684
685 def test_checkzip_sha224_hash_archive(self):
686 '''Check the sha224 hash of the zip archive itself using CheckTar class'''
687 __mismatchedhashes = brebis.checkbackups.checkzip.CheckZip({'path':
688 'tests/expected_hash/archash/myzip.zip',
689 'files_list':
690 'tests/expected_hash/archash/sha224hashziparchive-list',
691 'type': 'archive', 'delimiter': ''}, Options()).mismatched_hashes
692 self.assertEqual(__mismatchedhashes[0], {'path': 'tests/expected_hash/archash/myzip.zip',
693 'expectedhash': '6e0838302f48cc7863a160f197a23492833b59862d89cabc46c2a1c4',
694 'hash': '6e0838302f48cc7863a160f197a23492833b59862d89cabc46c2a1c3'})
695
696 def test_checkzip_sha256_hash_archive(self):
697 '''Check the sha256 hash of the zip archive itself using CheckZip class'''
698 __mismatchedhashes = brebis.checkbackups.checkzip.CheckZip({'path':
699 'tests/expected_hash/archash/myzip.zip',
700 'files_list':
701 'tests/expected_hash/archash/sha256hashziparchive-list',
702 'type': 'archive', 'delimiter': ''}, Options()).mismatched_hashes
703 self.assertEqual(__mismatchedhashes[0], {'path': 'tests/expected_hash/archash/myzip.zip',
704 'expectedhash': '358bae9af3f9f510095b2e2a245a5e49ab27d7de862cd22f0dd4f212e25fb139',
705 'hash': '358bae9af3f9f510095b2e2a245a5e49ab27d7de862cd22f0dd4f212e25fb138'})
706
707 def test_checkzip_sha384_hash_archive(self):
708 '''Check the sha384 hash of the zip archive itself using CheckZip class'''
709 __mismatchedhashes = brebis.checkbackups.checkzip.CheckZip({'path':
710 'tests/expected_hash/archash/myzip.zip',
711 'files_list':
712 'tests/expected_hash/archash/sha384hashziparchive-list',
713 'type': 'archive', 'delimiter': ''}, Options()).mismatched_hashes
714 self.assertEqual(__mismatchedhashes[0], {'path': 'tests/expected_hash/archash/myzip.zip',
715 'expectedhash': '6a372e2867442826b64d1e3bca4b35e18d12d5df25e89decff214023d45f7f85d07ee79e6522f53961626e525ee29988',
716 'hash': '6a372e2867442826b64d1e3bca4b35e18d12d5df25e89decff214023d45f7f85d07ee79e6522f53961626e525ee29989'})
717
718 def test_checkzip_sha512_hash_archive(self):
719 '''Check the sha512 hash of the zip archive itself using CheckZip class'''
720 __mismatchedhashes = brebis.checkbackups.checkzip.CheckZip({'path':
721 'tests/expected_hash/archash/myzip.zip',
722 'files_list':
723 'tests/expected_hash/archash/sha512hashziparchive-list',
724 'type': 'archive', 'delimiter': ''}, Options()).mismatched_hashes
725 self.assertEqual(__mismatchedhashes[0], {'path': 'tests/expected_hash/archash/myzip.zip',
726 'expectedhash': 'c177ca5b618ca613f27c44991eabb922d589691000fa602a0d2767ba84b317c653e6ed541f5922d201d2e65158eee4cfb7d87665bbe1d31c07f636bb25dac7b2',
727 'hash': 'c177ca5b618ca613f27c44991eabb922d589691000fa602a0d2767ba84b317c653e6ed541f5922d201d2e65158eee4cfb7d87665bbe1d31c07f636bb25dac7b3'})
728
729
730 def test_compare_tar_archive_uid_gid(self):
731 '''Compare the uid and the gid of the tar archive itself
732 and the expected one
733 '''
734 __uids = []
735 __gids = []
736 __myobj = brebis.checkbackups.checktar.CheckTar({'path':
737 'tests/expected_uid_gid/arc_uid_gid/uid-gid.tar.gz',
738 'files_list':
739 'tests/expected_uid_gid/arc_uid_gid/tar-uid-gid-list',
740 'type': 'archive', 'delimiter': ''}, Options())
741 __uids = __myobj.mismatched_uids
742 __gids = __myobj.mismatched_gids
743 self.assertEqual((__uids[0],__gids[0]), (
744 {'path':'tests/expected_uid_gid/arc_uid_gid/uid-gid.tar.gz','expecteduid':5,'uid':os.getuid()},
745 {'path':'tests/expected_uid_gid/arc_uid_gid/uid-gid.tar.gz','expectedgid':6,'gid':os.getgid()}))
746
747 def test_compare_zip_archive_uid_gid(self):
748 '''Compare the uid and the gid of the zip archive itself
749 and the expected one
750 '''
751 __uids = []
752 __gids = []
753 __myobj = brebis.checkbackups.checkzip.CheckZip({'path':
754 'tests/expected_uid_gid/arc_uid_gid/uid-gid.zip',
755 'files_list':
756 'tests/expected_uid_gid/arc_uid_gid/zip-uid-gid-list',
757 'type': 'archive', 'delimiter': ''}, Options())
758 __uids = __myobj.mismatched_uids
759 __gids = __myobj.mismatched_gids
760 self.assertEqual((__uids[0],__gids[0]), (
761 {'path':'tests/expected_uid_gid/arc_uid_gid/uid-gid.zip','expecteduid':5,'uid':os.getuid()},
762 {'path':'tests/expected_uid_gid/arc_uid_gid/uid-gid.zip','expectedgid':6,'gid':os.getgid()}))
763
764 ###########################################################
765 #
766 # Testing the private method from checkarchive.CheckArchive
767 #
768 ###########################################################
769
770 def test_extract_archive_info(self):
771 '''test the extract_archive_info private method from CheckArchive'''
772 __myobj = brebis.checkbackups.checktar.CheckTar({'path':
773 'tests/checkarchive_private_methods/mytar.tar.gz',
774 'files_list':
775 'tests/checkarchive_private_methods/tar-list',
776 'type': 'archive', 'delimiter': ''}, Options())
777 __file = 'tests/checkarchive_private_methods/mytar.tar.gz'
778 __fileinfo = __myobj._CheckArchive__extract_archive_info(__file)
779 self.assertEqual(type(os.lstat(__file)), type(__fileinfo))
780
781 def test_find_archive_size(self):
782 '''test the find_archive_size private method from CheckArchive'''
783 __myobj = brebis.checkbackups.checktar.CheckTar({'path':
784 'tests/checkarchive_private_methods/mytar.tar.gz',
785 'files_list':
786 'tests/checkarchive_private_methods/tar-list',
787 'type': 'archive', 'delimiter': ''}, Options())
788 __file = 'tests/checkarchive_private_methods/mytar.tar.gz'
789 __filesize = __myobj._CheckArchive__find_archive_size(__file)
790 self.assertEqual(os.lstat(__file).st_size, __filesize)
791
792 def test_find_archive_mode(self):
793 '''test the find_archive_mode private method from CheckArchive'''
794 __myobj = brebis.checkbackups.checktar.CheckTar({'path':
795 'tests/checkarchive_private_methods/mytar.tar.gz',
796 'files_list':
797 'tests/checkarchive_private_methods/tar-list',
798 'type': 'archive', 'delimiter': ''}, Options())
799 __file = 'tests/checkarchive_private_methods/mytar.tar.gz'
800 __filemode = __myobj._CheckArchive__find_archive_mode(__file)
801 self.assertEqual(stat.S_IMODE(os.lstat(__file).st_mode), __filemode)
802
803 def test_find_archive_uid_gid(self):
804 '''test the find_archive_uid_gid private method from CheckArchive'''
805 __myobj = brebis.checkbackups.checktar.CheckTar({'path':
806 'tests/checkarchive_private_methods/mytar.tar.gz',
807 'files_list':
808 'tests/checkarchive_private_methods/tar-list',
809 'type': 'archive', 'delimiter': ''}, Options())
810 __file = 'tests/checkarchive_private_methods/mytar.tar.gz'
811 __arcuid, __arcgid = __myobj._CheckArchive__find_archive_uid_gid(__file)
812 __fileinfo = os.lstat(__file)
813 __fileuid, __filegid = __fileinfo.st_uid, __fileinfo.st_gid
814 self.assertEqual((__arcuid, __arcgid), (__fileuid, __filegid))
815
816 def test_check_uid(self):
817 ''' test checkarchive.CheckArchive__check_uid'''
818 __myobj = brebis.checkbackups.checktar.CheckTar({'path':
819 'tests/checkarchive_private_methods/mytar.tar.gz',
820 'files_list':
821 'tests/checkarchive_private_methods/tar-list',
822 'type': 'archive', 'delimiter': ''}, Options())
823 __file = 'tests/checkarchive_private_methods/mytar.tar.gz'
824 __myobj._CheckArchive__check_uid('1000', {'path':'test', 'uid':'999'})
825 self.assertEqual([{'path':'test', 'expecteduid':'999', 'uid':'1000'}], __myobj.mismatched_uids)
826
827 def test_check_gid(self):
828 ''' test checkarchive.CheckArchive__check_gid'''
829 __myobj = brebis.checkbackups.checktar.CheckTar({'path':
830 'tests/checkarchive_private_methods/mytar.tar.gz',
831 'files_list':
832 'tests/checkarchive_private_methods/tar-list',
833 'type': 'archive', 'delimiter': ''}, Options())
834 __file = 'tests/checkarchive_private_methods/mytar.tar.gz'
835 __myobj._CheckArchive__check_gid('1000', {'path':'test', 'gid':'999'})
836 self.assertEqual([{'path':'test', 'expectedgid':'999', 'gid':'1000'}], __myobj.mismatched_gids)
837
838 #############################################################
839 #
840 # Testing the protected method from checkarchive.CheckArchive
841 #
842 #############################################################
843
844 def test_compare_sizes(self):
845 '''test the compare_sizes method from CheckArchive'''
846 __myobj = brebis.checkbackups.checktar.CheckTar({'path':
847 'tests/checkarchive_private_methods/mytar.tar.gz',
848 'files_list':
849 'tests/checkarchive_private_methods/tar-list',
850 'type': 'archive', 'delimiter': ''}, Options())
851 __mydict1 = {'equals': 12}
852 __mydict2 = {'biggerthan': 3}
853 __mydict3 = {'smallerthan': 7}
854 __myobj._compare_sizes(13, 'mytar1.tar.gz', __mydict1 )
855 __myobj._compare_sizes(1, 'mytar2.tar.gz', __mydict2 )
856 __myobj._compare_sizes(15, 'mytar3.tar.gz', __mydict3 )
857 self.assertEqual(__myobj.missing_equality, [{'expected': 12, 'path': 'mytar1.tar.gz', 'size': 13}])
858 self.assertEqual(__myobj.missing_bigger_than, [{'expected': 3, 'path': 'mytar2.tar.gz', 'size': 1}])
859 self.assertEqual(__myobj.missing_smaller_than, [{'expected': 7, 'path': 'mytar3.tar.gz', 'size': 15}])
860
861 def test_normalize_path(self):
862 '''test the normalize_path method from CheckArchive'''
863 __myobj = brebis.checkbackups.checktar.CheckTar({'path':
864 'tests/checkarchive_private_methods/mytar.tar.gz',
865 'files_list':
866 'tests/checkarchive_private_methods/tar-list',
867 'type': 'archive', 'delimiter': ''}, Options())
868 __res = __myobj._normalize_path('/test/')
869 self.assertEqual(__res, '/test')
870
871 def test_check_unexpected_files(self):
872 '''test the check_unexpected_files method from CheckArchive'''
873 __myobj = brebis.checkbackups.checktar.CheckTar({'path':
874 'tests/checkarchive_private_methods/mytar.tar.gz',
875 'files_list':
876 'tests/checkarchive_private_methods/tar-list',
877 'type': 'archive', 'delimiter': ''}, Options())
878 __myobj._check_unexpected_files('test.tar.gz', 'unexpected weird ok')
879 self.assertEqual(__myobj.unexpected_files, ['test.tar.gz'])
880
881 def test_check_mode(self):
882 '''test the check_mode method from CheckArchive'''
883 __myobj = brebis.checkbackups.checktar.CheckTar({'path':
884 'tests/checkarchive_private_methods/mytar.tar.gz',
885 'files_list':
886 'tests/checkarchive_private_methods/tar-list',
887 'type': 'archive', 'delimiter': ''}, Options())
888 __myobj._check_mode(777, {'path': 'test.tar.gz', 'mode':'644'})
889 self.assertEqual(__myobj.mismatched_modes, [{'path': 'test.tar.gz', 'mode':'1411', 'expectedmode':'644'}])
890
891 def test_check_type(self):
892 '''test the check_type method from CheckArchive'''
893 __myobj = brebis.checkbackups.checktar.CheckTar({'path':
894 'tests/checkarchive_private_methods/mytar.tar.gz',
895 'files_list':
896 'tests/checkarchive_private_methods/tar-list',
897 'type': 'archive', 'delimiter': ''}, Options())
898 __myobj._check_type('s', {'path': 'test.tar.gz', 'type':'f'})
899 self.assertEqual(__myobj.mismatched_types, [{'path': 'test.tar.gz', 'type':'s', 'expectedtype':'f'}])
900
901 def test_check_mtime(self):
902 '''test the check_mtime method from CheckArchive'''
903 __myobj = brebis.checkbackups.checktar.CheckTar({'path':
904 'tests/checkarchive_private_methods/mytar.tar.gz',
905 'files_list':
906 'tests/checkarchive_private_methods/tar-list',
907 'type': 'archive', 'delimiter': ''}, Options())
908 __myobj._check_mtime(1383912787.0, {'path': 'test.tar.gz', 'mtime': 1383912786.0})
909 self.assertEqual(__myobj.mismatched_mtimes, [{'path': 'test.tar.gz', 'mtime': 1383912787.0, 'expectedmtime': 1383912786.0}])
910
911 ##############################################################
912 #
913 # Testing the private/protected methods from checkzip.CheckZip
914 #
915 ##############################################################
916
917 def test_zip_extract_stored_file(self):
918 '''test the _extract_stored_file protected method from checkzip.CheckZip'''
919 __myobj = brebis.checkbackups.checkzip.CheckZip({'path':
920 'tests/checkzip_private_methods/myzip.zip',
921 'files_list':
922 'tests/checkzip_private_methods/myzip-list',
923 'type': 'archive', 'delimiter': ''}, Options())
924 __file = 'tests/checkzip_private_methods/myzip.zip'
925 self._zip = zipfile.ZipFile(__file,'r')
926 __result = __myobj._extract_stored_file('file-missing-in-zip/foo')
927 self.assertEqual(type(__result), type(self._zip.open('file-missing-in-zip/foo')))
928
929 def test_zip_extract_uid_gid(self):
930 '''test the __extract_uid_gid private method from checkzip.CheckZip'''
931 __myobj = brebis.checkbackups.checkzip.CheckZip({'path':
932 'tests/checkzip_private_methods/myzip.zip',
933 'files_list':
934 'tests/checkzip_private_methods/myzip-list',
935 'type': 'archive', 'delimiter': ''}, Options())
936 __file = 'tests/checkzip_private_methods/myzip.zip'
937 __myz = zipfile.ZipFile(__file,'r')
938 __myinfo = __myz.infolist()
939 __result = __myobj._CheckZip__extract_uid_gid(__myinfo[-1])
940 self.assertEqual((1000,1000), __result)
941
942 def test_zip_translate_type_file(self):
943 '''test the __translate_type private method from checkzip.CheckZip - expecting file'''
944 __myobj = brebis.checkbackups.checkzip.CheckZip({'path':
945 'tests/checkzip_private_methods/myzip.zip',
946 'files_list':
947 'tests/checkzip_private_methods/myzip-list',
948 'type': 'archive', 'delimiter': ''}, Options())
949 __file = 'tests/checkzip_private_methods/myzip.zip'
950 __myz = zipfile.ZipFile(__file,'r')
951 __myinfo = __myz.infolist()
952 __result = __myobj._CheckZip__translate_type(__myinfo[-1].external_attr >> 16)
953 self.assertEqual('f', __result)
954
955 def test_zip_translate_type_directory(self):
956 '''test the __translate_type private method from checkzip.CheckZip - expecting directory'''
957 __myobj = brebis.checkbackups.checkzip.CheckZip({'path':
958 'tests/checkzip_private_methods/myzip.zip',
959 'files_list':
960 'tests/checkzip_private_methods/myzip-list',
961 'type': 'archive', 'delimiter': ''}, Options())
962 __file = 'tests/checkzip_private_methods/myzip.zip'
963 __myz = zipfile.ZipFile(__file,'r')
964 __myinfo = __myz.infolist()
965 __result = __myobj._CheckZip__translate_type(__myinfo[0].external_attr >> 16)
966 self.assertEqual('d', __result)
967
968 ##############################################################
969 #
970 # Testing the private/protected methods from checktar.CheckTar
971 #
972 ##############################################################
973
974 def test_tar_extract_stored_file(self):
975 '''test the _extract_stored_file protected method from checktar.CheckTar'''
976 __myobj = brebis.checkbackups.checktar.CheckTar({'path':
977 'tests/checktar_private_methods/mytargz/mytargz.tar.gz',
978 'files_list':
979 'tests/checktar_private_methods/mytargz/mytargz-list',
980 'type': 'archive', 'delimiter': ''}, Options())
981 __file = 'tests/checktar_private_methods/mytargz/mytargz.tar.gz'
982 self._tar = tarfile.open(__file)
983 __result = __myobj._extract_stored_file('mytargz/hello')
984 self.assertEqual(type(__result), type(self._tar.extractfile('mytargz/hello')))
985
986 def test_tar_translate_type_file(self):
987 '''test the __translate_type private method from checktar.CheckTar - expecting file'''
988 __myobj = brebis.checkbackups.checktar.CheckTar({'path':
989 'tests/checktar_private_methods/mytargz/mytargz.tar.gz',
990 'files_list':
991 'tests/checktar_private_methods/mytargz/mytargz-list',
992 'type': 'archive', 'delimiter': ''}, Options())
993 __file = 'tests/checktar_private_methods/mytargz/mytargz.tar.gz'
994 self._tar = tarfile.open(__file)
995 __result = __myobj._CheckTar__translate_type(self._tar.getmembers()[2].type)
996 self.assertEqual('f', __result)
997
998 def test_tar_translate_type_directory(self):
999 '''test the __translate_type private method from checktar.CheckTar - expecting directory'''
1000 __myobj = brebis.checkbackups.checktar.CheckTar({'path':
1001 'tests/checktar_private_methods/mytargz/mytargz.tar.gz',
1002 'files_list':
1003 'tests/checktar_private_methods/mytargz/mytargz-list',
1004 'type': 'archive', 'delimiter': ''}, Options())
1005 __file = 'tests/checktar_private_methods/mytargz/mytargz.tar.gz'
1006 self._tar = tarfile.open(__file)
1007 __result = __myobj._CheckTar__translate_type(self._tar.getmembers()[0].type)
1008 self.assertEqual('d', __result)
1009
1010 def test_tar_translate_type_symbolic_link(self):
1011 '''test the __translate_type private method from checktar.CheckTar - expecting symbolic link'''
1012 __myobj = brebis.checkbackups.checktar.CheckTar({'path':
1013 'tests/checktar_private_methods/mytargz/mytargz.tar.gz',
1014 'files_list':
1015 'tests/checktar_private_methods/mytargz/mytargz-list',
1016 'type': 'archive', 'delimiter': ''}, Options())
1017 __file = 'tests/checktar_private_methods/mytargz/mytargz.tar.gz'
1018 self._tar = tarfile.open(__file)
1019 __result = __myobj._CheckTar__translate_type(self._tar.getmembers()[1].type)
1020 self.assertEqual('s', __result)
1021
1022 ################################################################
1023 #
1024 # Testing the private/protected methods from checktree.CheckTree
1025 #
1026 ################################################################
1027
1028 def test_tree_extract_stored_file(self):
1029 '''test the _extract_stored_file protected method from checktree.CheckTree'''
1030 __myobj = brebis.checkbackups.checktree.CheckTree({'path':
1031 'tests/checktree_private_methods/mytree',
1032 'files_list':
1033 'tests/checktree_private_methods/mytree-list',
1034 'type': 'tree', 'delimiter': ''}, Options())
1035 __file = 'tests/checktree_private_methods/mytree'
1036 __result = __myobj._extract_stored_file('hello')
1037 with open(os.path.join(__file, 'hello'), 'rb') as self.__desc:
1038 self.assertEqual(type(__result), type(self.__desc))
1039 __result.close()
1040
1041 def test_tree_translate_type_file(self):
1042 '''test the __translate_type private method from checktree.CheckTree - expecting file'''
1043 __myobj = brebis.checkbackups.checktree.CheckTree({'path':
1044 'tests/checktree_private_methods/mytree',
1045 'files_list':
1046 'tests/checktree_private_methods/mytree-list',
1047 'type': 'tree', 'delimiter': ''}, Options())
1048 __file = 'tests/checktree_private_methods/mytree/hello'
1049 __result = __myobj._CheckTree__translate_type(os.lstat(__file).st_mode)
1050 self.assertEqual('f', __result)
1051
1052 def test_tree_translate_type_directory(self):
1053 '''test the __translate_type private method from checktree.CheckTree - expecting directory'''
1054 __myobj = brebis.checkbackups.checktree.CheckTree({'path':
1055 'tests/checktree_private_methods/mytree',
1056 'files_list':
1057 'tests/checktree_private_methods/mytree-list',
1058 'type': 'tree', 'delimiter': ''}, Options())
1059 __file = 'tests/checktree_private_methods/mytree'
1060 __result = __myobj._CheckTree__translate_type(os.lstat(__file).st_mode)
1061 self.assertEqual('d', __result)
1062
1063 def test_tree_translate_type_symbolic_link(self):
1064 '''test the __translate_type private method from checktree.CheckTree - expecting symbolic link'''
1065 __myobj = brebis.checkbackups.checktree.CheckTree({'path':
1066 'tests/checktree_private_methods/mytree',
1067 'files_list':
1068 'tests/checktree_private_methods/mytree-list',
1069 'type': 'tree', 'delimiter': ''}, Options())
1070 __file = 'tests/checktree_private_methods/mytree/riri'
1071 __result = __myobj._CheckTree__translate_type(os.lstat(__file).st_mode)
1072 self.assertEqual('s', __result)
1073
1074 ################################################################
1075 #
1076 # Testing the private/protected methods from checkgzip.CheckGzip
1077 #
1078 ################################################################
1079
1080 def test_gzip_extract_stored_file(self):
1081 '''test the _extract_stored_file protected method from checkgzip.CheckGzip'''
1082 __myobj = brebis.checkbackups.checkgzip.CheckGzip({'path':
1083 'tests/checkgzip_private_methods/mygzip.gz',
1084 'files_list':
1085 'tests/checkgzip_private_methods/mygzip-list',
1086 'type': 'archive', 'delimiter': ''}, Options())
1087 __file = 'tests/checkgzip_private_methods/mygzip.gz'
1088 __result = __myobj._extract_stored_file('mygzip')
1089 with gzip.open(__file, 'rb') as self.__desc:
1090 self.assertEqual(type(__result), type(self.__desc))
1091 __result.close()
1092
1093 def test_extract_size_from_gzip_archive(self):
1094 '''test the extraction of a gzip uncompressed file in the gzip archive'''
1095 __arcpath = 'tests/checkgzip_private_methods/mygzip.gz'
1096 __myobj = brebis.checkbackups.checkgzip.CheckGzip({'path':
1097 __arcpath,
1098 'files_list':
1099 'tests/checkgzip_private_methods/mygzip-list',
1100 'type': 'archive', 'delimiter': ''}, Options())
1101 with open(__arcpath, 'rb') as __myf:
1102 self.assertEqual(23, __myobj._CheckGzip__extract_size(__myf))
1103
1104 def test_extract_initial_filename_from_gzip_archive(self):
1105 '''test the extraction of the initial name of an uncompressed file'''
1106 __arcpath = 'tests/checkgzip_private_methods/mygzip.gz'
1107 __myobj = brebis.checkbackups.checkgzip.CheckGzip({'path':
1108 __arcpath,
1109 'files_list':
1110 'tests/checkgzip_private_methods/mygzip-list',
1111 'type': 'archive', 'delimiter': ''}, Options())
1112 with open(__arcpath, 'rb') as __myf:
1113 self.assertEqual('mygzip', __myobj._CheckGzip__extract_initial_filename(__myf, 'mygzip'))
1114
1115 ##################################################################
1116 #
1117 # Testing the private/protected methods from checkbzip2.CheckBzip2
1118 #
1119 ##################################################################
1120
1121 def test_bzip2_extract_stored_file(self):
1122 '''test the _extract_stored_file protected method from checkbzip2.CheckBzip2'''
1123 __myobj = brebis.checkbackups.checkbzip2.CheckBzip2({'path':
1124 'tests/checkbzip2_private_methods/mybz2.bz2',
1125 'files_list':
1126 'tests/checkbzip2_private_methods/mybzip2-list',
1127 'type': 'archive', 'delimiter': ''}, Options())
1128 __file = 'tests/checkbzip2_private_methods/mybz2.bz2'
1129 __result = __myobj._extract_stored_file('mygzip')
1130 with bz2.BZ2File(__file, 'r') as self.__desc:
1131 self.assertEqual(type(__result), type(self.__desc))
1132 __result.close()
1133
1134 ######################################################################################
1135 #
1136 # Testing the private/protected methods from generatelistforbzip2.GenerateListForBzip2
1137 #
1138 ######################################################################################
1139
1140 def test__listconfinfo(self):
1141 '''test the GenerateListForBzip2 class'''
1142 __myobj = brebis.generatelist.generatelistforbzip2.GenerateListForBzip2({
1143 'arcpath': 'tests/checkbzip2_private_methods/mybz2.bz2', 'delimiter': '|', 'hashtype': '', 'parsingexceptions' : '', 'getallhashes': True, 'genfull': True, 'confoutput':'','listoutput':'','fulloutput':''})
1144 self.assertEqual(__myobj._GenerateListForBzip2__lci, {'arclistpath': 'tests/checkbzip2_private_methods/mybz2.list',
1145 'listoffiles': ['[files]\n', 'mybz2| type|f md5|f5488b7ce878d89b59ef2752f260354f\n']})
1146 self.assertEqual(__myobj._GenerateListForBzip2__ci, {'arcconfpath': 'tests/checkbzip2_private_methods/mybz2.conf',
1147 'arclistpath': 'tests/checkbzip2_private_methods/mybz2.list',
1148 'arcname': 'mybz2',
1149 'arcpath': 'tests/checkbzip2_private_methods/mybz2.bz2',
1150 'arctype': 'archive',
1151 'sha512': 'b45fa678a2208bfbf457f602b2d3de0c83e82ad9ba042b029b8d37f23bfe2774d1cd25576da880d20bb7f6ffcfc2ecb4bcc80112e880415de82fe63d81f81cb7'})
1152
1153 ###############################################################################################
1154 #
1155 # Testing the private/protected methods from generatelist.generatelist.GenerateList
1156 #
1157 ###############################################################################################
1158
1159 def test_generatelist_generate_list(self):
1160 '''test the _generate_list protected method from GenerateList'''
1161 __file = 'tests/generatelist_private_methods/mytar.list'
1162 __myobj = brebis.generatelist.generatelist.GenerateList()
1163 __content = ['[files]\n', 'foo:\n']
1164 __myobj._generate_list({'arclistpath': __file, 'listoffiles': __content})
1165 with open(__file, 'r') as __f:
1166 self.assertEqual(__f.readlines(), __content)
1167
1168 ###############################################################################################
1169 #
1170 # Testing the private/protected methods from generatelist.generatelistfortar.GenerateListForTar
1171 #
1172 ###############################################################################################
1173
1174 def test_listfortar_translate_type_file(self):
1175 '''test the __translate_type private method from GenerateListForTar - expecting file'''
1176 __file = 'tests/generatelistfortar_private_methods/mytar.tar.gz'
1177 __myobj = brebis.generatelist.generatelistfortar.GenerateListForTar({'arcpath':__file, 'delimiter':DEFAULTDELIMITER, 'hashtype': '', 'parsingexceptions': '', 'getallhashes': False, 'genfull':False, 'confoutput':'','listoutput':'','fulloutput':''})
1178 self.__tar = tarfile.open(__file)
1179 __result = __myobj._GenerateListForTar__translate_type(self.__tar.getmembers()[3].type)
1180 self.assertEqual('f', __result)
1181
1182 def test_listfortar_translate_type_directory(self):
1183 '''test the __translate_type private method from GenerateListForTar - expecting directory'''
1184 __file = 'tests/generatelistfortar_private_methods/mytar.tar.gz'
1185 __myobj = brebis.generatelist.generatelistfortar.GenerateListForTar({'arcpath':__file, 'delimiter':DEFAULTDELIMITER, 'hashtype': '', 'parsingexceptions': '', 'getallhashes': False, 'genfull':False, 'confoutput':'','listoutput':'','fulloutput':''})
1186 self.__tar = tarfile.open(__file)
1187 __result = __myobj._GenerateListForTar__translate_type(self.__tar.getmembers()[1].type)
1188 self.assertEqual('d', __result)
1189
1190 def test_listfortar_translate_type_symbolic_link(self):
1191 '''test the __translate_type private method from GenerateListForTar - expecting symbolic link'''
1192 __file = 'tests/generatelistfortar_private_methods/mytar.tar.gz'
1193 __myobj = brebis.generatelist.generatelistfortar.GenerateListForTar({'arcpath':__file, 'delimiter':DEFAULTDELIMITER, 'hashtype': '', 'parsingexceptions': '', 'getallhashes': False, 'genfull':False, 'confoutput':'','listoutput':'','fulloutput':''})
1194 self.__tar = tarfile.open(__file)
1195 __result = __myobj._GenerateListForTar__translate_type(self.__tar.getmembers()[2].type)
1196 self.assertEqual('s', __result)
1197
1198 ###############################################################################################
1199 #
1200 # Testing the private/protected methods from generatelist.generatelistforzip.GenerateListForZip
1201 #
1202 ###############################################################################################
1203
1204 def test_listforzip_translate_type_file(self):
1205 '''test the __translate_type private method from GenerateListForZip - expecting file'''
1206 __file = 'tests/generatelistforzip_private_methods/myzip.zip'
1207 __myobj = brebis.generatelist.generatelistforzip.GenerateListForZip({'arcpath':__file, 'delimiter':DEFAULTDELIMITER, 'hashtype': '', 'parsingexceptions': '', 'getallhashes': False, 'genfull':False, 'confoutput':'','listoutput':'','fulloutput':''})
1208 __myz = zipfile.ZipFile(__file,'r')
1209 __myinfo = __myz.infolist()
1210 __result = __myobj._GenerateListForZip__translate_type(__myinfo[-1].external_attr >> 16)
1211 self.assertEqual('f', __result)
1212
1213 def test_listforzip_translate_type_directory(self):
1214 '''test the __translate_type private method from GenerateListForZip - expecting directory'''
1215 __file = 'tests/generatelistforzip_private_methods/myzip.zip'
1216 __myobj = brebis.generatelist.generatelistforzip.GenerateListForZip({'arcpath':__file, 'delimiter':DEFAULTDELIMITER, 'hashtype': '', 'parsingexceptions': '', 'getallhashes': False, 'genfull':False, 'confoutput':'','listoutput':'','fulloutput':''})
1217 __myz = zipfile.ZipFile(__file,'r')
1218 __myinfo = __myz.infolist()
1219 __result = __myobj._GenerateListForZip__translate_type(__myinfo[0].external_attr >> 16)
1220 self.assertEqual('d', __result)
1221
1222 def test_listforzip_extract_uid_gid(self):
1223 '''test the __extract_uid_gid private method from GenerateListForZip'''
1224 __file = 'tests/generatelistforzip_private_methods/myzip.zip'
1225 __myobj = brebis.generatelist.generatelistforzip.GenerateListForZip({'arcpath':__file, 'delimiter':DEFAULTDELIMITER, 'hashtype': '', 'parsingexceptions': '', 'getallhashes': False, 'genfull':False, 'confoutput':'','listoutput':'','fulloutput':''})
1226 __myz = zipfile.ZipFile(__file,'r')
1227 __myinfo = __myz.infolist()
1228 __result = __myobj._GenerateListForZip__extract_uid_gid(__myinfo[-1])
1229 self.assertEqual((1000,1000), __result)
1230
1231 #################################################################################################
1232 #
1233 # Testing the private/protected methods from generatelist.generatelistfortree.GenerateListForTree
1234 #
1235 #################################################################################################
1236
1237 def test_listfortree_translate_type_file(self):
1238 '''test the __translate_type private method from GenerateListForTree - expecting file'''
1239 __dir = 'tests/generatelistfortree_private_methods/mydir'
1240 __file = os.path.join(__dir, 'foo')
1241 __myobj = brebis.generatelist.generatelistfortree.GenerateListForTree({'arcpath':__file, 'delimiter':DEFAULTDELIMITER, 'hashtype': '', 'parsingexceptions': '', 'getallhashes': False, 'genfull':False, 'confoutput':'','listoutput':'','fulloutput':''})
1242 __myobj._GenerateListForTree__fileinfo = os.lstat(__file)
1243 __result = __myobj._GenerateListForTree__translate_type(os.lstat(__file).st_mode)
1244 self.assertEqual('f', __result)
1245
1246 def test_listfortree_translate_type_directory(self):
1247 '''test the __translate_type private method from GenerateListForTree - expecting directory'''
1248 __dir = 'tests/generatelistfortree_private_methods/mydir'
1249 __file = os.path.join(__dir, 'bar')
1250 __myobj = brebis.generatelist.generatelistfortree.GenerateListForTree({'arcpath':__file, 'delimiter':DEFAULTDELIMITER, 'hashtype': '', 'parsingexceptions': '', 'getallhashes': False, 'genfull':False, 'confoutput':'','listoutput':'','fulloutput':''})
1251 __result = __myobj._GenerateListForTree__translate_type(os.lstat(__file).st_mode)
1252 self.assertEqual('d', __result)
1253
1254 def test_listfortree_translate_type_symbolic_link(self):
1255 '''test the __translate_type private method from GenerateListForTree - expecting symbolic link'''
1256 __dir = 'tests/generatelistfortree_private_methods/mydir'
1257 __file = os.path.join(__dir, 'oof')
1258 __myobj = brebis.generatelist.generatelistfortree.GenerateListForTree({'arcpath':__file, 'delimiter':DEFAULTDELIMITER, 'hashtype': '', 'parsingexceptions': '', 'getallhashes': False, 'genfull':False, 'confoutput':'','listoutput':'','fulloutput':''})
1259 __result = __myobj._GenerateListForTree__translate_type(os.lstat(__file).st_mode)
1260 self.assertEqual('s', __result)
1261
1262 #################################################################################################
1263 #
1264 # Testing the private/protected methods from generatelist.generatelistfortree.GenerateListForTree
1265 #
1266 #################################################################################################
1267
1268 def test_listforgzip_extract_size_from_gzip_archive(self):
1269 '''test the extraction of a gzip uncompressed file in the gzip archive'''
1270 __file = 'tests/generatelistforgzip_private_methods/mygzip.gz'
1271 __myobj = brebis.generatelist.generatelistforgzip.GenerateListForGzip({'arcpath':__file, 'delimiter':DEFAULTDELIMITER, 'hashtype': '', 'parsingexceptions': '', 'getallhashes': False, 'genfull':False, 'confoutput':'','listoutput':'','fulloutput':''})
1272 with open(__file, 'rb') as __myf:
1273 self.assertEqual(15, __myobj._GenerateListForGzip__extract_size(__myf))
1274
1275 def test_listforgzip_extract_initial_filename_from_gzip_archive(self):
1276 __file = 'tests/generatelistforgzip_private_methods/mygzip.gz'
1277 __myobj = brebis.generatelist.generatelistforgzip.GenerateListForGzip({'arcpath':__file, 'delimiter':DEFAULTDELIMITER, 'hashtype': '', 'parsingexceptions': '', 'getallhashes': False, 'genfull':False, 'confoutput':'','listoutput':'','fulloutput':''})
1278 with open(__file, 'rb') as __myf:
1279 self.assertEqual('mygzip', __myobj._GenerateListForGzip__extract_initial_filename(__myf, 'mygzip'))
1280
1281 ##############################################################
1282 #
1283 # Testing the private/protected methods from cliparse.CliParse
1284 #
1285 ##############################################################
1286
1287 def test_cliparse_cliparse(self):
1288 '''Test the cliparse.CliParse class'''
1289 __archivepath = '/tmp/archive.conf'
1290 __logpath = '/tmp/a.out'
1291 with open(__archivepath, 'w') as __desc:
1292 __desc.write('')
1293 sys.argv.append('-c')
1294 sys.argv.append(__archivepath)
1295 sys.argv.append('-l')
1296 sys.argv.append(__logpath)
1297 __myobj = brebis.cliparse.CliParse()
1298 self.assertEqual(vars(__myobj.options), {'archives': [],
1299 'confpath': __archivepath,
1300 'delimiter': '|',
1301 'hashtype': '',
1302 'parsingexceptions': '',
1303 'getallhashes': False,
1304 'genfull': False,
1305 'genlist': False,
1306 'logfile': __logpath,
1307 'fulloutput':'',
1308 'confoutput':'',
1309 'listoutput':''})
1310 os.remove(__archivepath)
1311
1312 #######################################################################################
1313 #
1314 # Testing the consistent given version of the software both in setup.py and cliparse.py
1315 #
1316 #######################################################################################
1317
1318 def test_version_consistency_in_setup_py_and_cliparse_py(self):
1319 '''test the consistency of the version of the software
1320 in both setup.py and cliparse.py
1321 '''
1322 with open('setup.py') as __setuppy:
1323 __setuppycode = __setuppy.readlines()
1324 with open('brebis/cliparse.py') as __cliparsepy:
1325 __cliparsepycode = __cliparsepy.readlines()
1326 for line in __setuppycode:
1327 if 'version = ' in line:
1328 setuppyversion = line.split("'")[1]
1329 break
1330 for line in __cliparsepycode:
1331 if 'version=' in line:
1332 cliparsepyversion = line.split('s ')[1].split("'")[0]
1333 break
1334 self.assertEqual(setuppyversion, cliparsepyversion)
1335
1336 #######################################################################################
1337 #
1338 # Testing the brebis/archiveinfomsg.py
1339 #
1340 #######################################################################################
1341
1342 def test_archiveinfomsg_main(self):
1343 '''test the archivemsginfo.ArchiveMsgInfo__main method'''
1344 _logfile = TESTLOG
1345 brebis.applogger.AppLogger(TESTLOG)
1346 __mydict = MyDict()
1347 __mydict.missing_files = ['testarchiveinfomsgmain1']
1348 __mydict.unexpected_files = []
1349 __mydict.missing_equality = []
1350 __mydict.missing_smaller_than = []
1351 __mydict.missing_bigger_than = []
1352 __mydict.missing_bigger_than = []
1353 __mydict.mismatched_uids = []
1354 __mydict.mismatched_gids = []
1355 __mydict.mismatched_modes = []
1356 __mydict.mismatched_types = []
1357 __mydict.mismatched_hashes = []
1358 __mydict.mismatched_targets = []
1359 __mydict.mismatched_mtimes = []
1360 __myobj = brebis.archiveinfomsg.ArchiveInfoMsg(__mydict, {'path': 'testarchiveinfomsgmain.tar.gz', 'sha512': None, 'files_list': '', 'type': 'archive', 'delimiter': None})
1361 __myobj._ArchiveInfoMsg__main(__mydict, {'path': 'testarchiveinfomsgmain.tar.gz', 'sha512': None, 'files_list': '', 'type': 'archive', 'delimiter': None})
1362 with open(_logfile) as _res:
1363 self.assertIn('WARNING:root:1 file missing in testarchiveinfomsgmain.tar.gz: \nWARNING:root:testarchiveinfomsgmain1\n', _res.read())
1364
1365 def test_archiveinfomsg_missing_files(self):
1366 '''test the __missing_files method'''
1367 _logfile = TESTLOG
1368 brebis.applogger.AppLogger(TESTLOG)
1369 __mydict = MyDict()
1370 __mydict.missing_files = []
1371 __mydict.unexpected_files = []
1372 __mydict.missing_equality = []
1373 __mydict.missing_smaller_than = []
1374 __mydict.missing_bigger_than = []
1375 __mydict.missing_bigger_than = []
1376 __mydict.mismatched_uids = []
1377 __mydict.mismatched_gids = []
1378 __mydict.mismatched_modes = []
1379 __mydict.mismatched_types = []
1380 __mydict.mismatched_hashes = []
1381 __mydict.mismatched_targets = []
1382 __mydict.mismatched_mtimes = []
1383 __myobj = brebis.archiveinfomsg.ArchiveInfoMsg(__mydict, {'path': 'testmissingfiles.tar.gz', 'sha512': None, 'files_list': '', 'type': 'archive', 'delimiter': None})
1384 __myobj._ArchiveInfoMsg__missing_files(['titi'], 'testmissingfiles.tar.gz')
1385 with open(_logfile) as _res:
1386 self.assertIn('WARNING:root:1 file missing in testmissingfiles.tar.gz: \nWARNING:root:titi\n', _res.read())
1387
1388 def test_archiveinfomsg_unexpected_files(self):
1389 '''test the archiveinfomsg.ArchiveInfoMsg__unexpected_files method'''
1390 _logfile = TESTLOG
1391 brebis.applogger.AppLogger(TESTLOG)
1392 __mydict = MyDict()
1393 __mydict.missing_files = []
1394 __mydict.unexpected_files = []
1395 __mydict.missing_equality = []
1396 __mydict.missing_smaller_than = []
1397 __mydict.missing_bigger_than = []
1398 __mydict.missing_bigger_than = []
1399 __mydict.mismatched_uids = []
1400 __mydict.mismatched_gids = []
1401 __mydict.mismatched_modes = []
1402 __mydict.mismatched_types = []
1403 __mydict.mismatched_hashes = []
1404 __mydict.mismatched_targets = []
1405 __mydict.mismatched_mtimes = []
1406 __myobj = brebis.archiveinfomsg.ArchiveInfoMsg(__mydict, {'path': 'testunexpectedfiles.tar.gz', 'sha512': None, 'files_list': '', 'type': 'archive', 'delimiter': None})
1407 __myobj._ArchiveInfoMsg__unexpected_files(['titi'], 'testunexpectedfiles.tar.gz')
1408 with open(_logfile) as _res:
1409 self.assertIn('WARNING:root:1 unexpected file checking testunexpectedfiles.tar.gz: \nWARNING:root:titi\n', _res.read())
1410
1411 def test_archiveinfomsg_classify_differences(self):
1412 '''test the archiveinfomsg.ArchiveInfoMsg__classify_differences method'''
1413 _logfile = TESTLOG
1414 brebis.applogger.AppLogger(TESTLOG)
1415 __mydict = MyDict()
1416 __mydict.missing_files = []
1417 __mydict.unexpected_files = []
1418 __mydict.missing_equality = [{'path':'classifydifferences1', 'size':'12','expected':'3'}]
1419 __mydict.missing_smaller_than = [{'path':'classifydifferences2', 'size':'12','expected':'3'}]
1420 __mydict.missing_bigger_than = [{'path':'classifydifferences3', 'size':'12','expected':'3'}]
1421 __mydict.mismatched_uids = []
1422 __mydict.mismatched_gids = []
1423 __mydict.mismatched_modes = []
1424 __mydict.mismatched_types = []
1425 __mydict.mismatched_hashes = []
1426 __mydict.mismatched_targets = []
1427 __mydict.mismatched_mtimes = []
1428 __myobj = brebis.archiveinfomsg.ArchiveInfoMsg(__mydict, {'path': 'testclassifydifferences.tar.gz', 'sha512': None, 'files_list': '', 'type': 'archive', 'delimiter': None})
1429 __myobj._ArchiveInfoMsg__classify_differences(__mydict, 'testclassifydifferences.tar.gz')
1430 with open(_logfile) as _res:
1431 __testresult = _res.read()
1432 self.assertIn('WARNING:root:classifydifferences1 size is 12. Should have been 3.', __testresult)
1433 self.assertIn('WARNING:root:classifydifferences2 size is 12. Should have been smaller than 3.', __testresult)
1434 self.assertIn('WARNING:root:classifydifferences3 size is 12. Should have been bigger than 3.', __testresult)
1435
1436 def test_archiveinfomsg_log_differences(self):
1437 '''test the archiveinfomsg.ArchiveInfoMsg__log_differences method'''
1438 _logfile = TESTLOG
1439 brebis.applogger.AppLogger(TESTLOG)
1440 __mydict = MyDict()
1441 __mydict.missing_files = []
1442 __mydict.unexpected_files = []
1443 __mydict.missing_equality = [{'path':'classifydifferences4', 'size':'12','expected':'3'}]
1444 __mydict.missing_smaller_than = []
1445 __mydict.missing_bigger_than = []
1446 __mydict.mismatched_uids = []
1447 __mydict.mismatched_gids = []
1448 __mydict.mismatched_modes = []
1449 __mydict.mismatched_types = []
1450 __mydict.mismatched_hashes = []
1451 __mydict.mismatched_targets = []
1452 __mydict.mismatched_mtimes = []
1453 __myobj = brebis.archiveinfomsg.ArchiveInfoMsg(__mydict, {'path': 'testlogdifferences.tar.gz', 'sha512': None, 'files_list': '', 'type': 'archive', 'delimiter': None})
1454 __myobj._ArchiveInfoMsg__log_differences(__mydict.missing_equality, 'testlogdifferences.tar.gz', '{} {} with unexpected size while checking {}: ')
1455 with open(_logfile) as _res:
1456 __testresult = _res.read()
1457 self.assertIn('WARNING:root:classifydifferences4 size is 12. Should have been 3.', __testresult)
1458
1459 def test_archiveinfomsg_uid_gid_mismatches(self):
1460 '''test the archiveinfomsg.ArchiveInfoMsg__uid_gid_mismatches method'''
1461 _logfile = TESTLOG
1462 brebis.applogger.AppLogger(TESTLOG)
1463 __mydict = MyDict()
1464 __mydict.missing_files = []
1465 __mydict.unexpected_files = []
1466 __mydict.missing_equality = []
1467 __mydict.missing_smaller_than = []
1468 __mydict.missing_bigger_than = []
1469 __mydict.mismatched_uids = [{'path':'classifydifferences5', 'expecteduid':'1010','uid':'1000'}]
1470 __mydict.mismatched_gids = [{'path':'classifydifferences6', 'expectedgid':'1010','gid':'1000'}]
1471 __mydict.mismatched_modes = []
1472 __mydict.mismatched_types = []
1473 __mydict.mismatched_hashes = []
1474 __mydict.mismatched_targets = []
1475 __mydict.mismatched_mtimes = []
1476 __myobj = brebis.archiveinfomsg.ArchiveInfoMsg(__mydict, {'path': 'testuidgidmismatches.tar.gz', 'sha512': None, 'files_list': '', 'type': 'archive', 'delimiter': None})
1477 __myobj._ArchiveInfoMsg__uid_gid_mismatches(__mydict, 'testuidgidmismatches.tar.gz')
1478 with open(_logfile) as _res:
1479 __testresult = _res.read()
1480 self.assertIn('WARNING:root:classifydifferences5 uid is 1000. Should have been 1010.', __testresult)
1481 self.assertIn('WARNING:root:classifydifferences6 gid is 1000. Should have been 1010.', __testresult)
1482
1483 def test_archiveinfomsg_mode_mismatches(self):
1484 '''test the archiveinfomsg.ArchiveInfoMsg__mode_mismatches method'''
1485 _logfile = TESTLOG
1486 brebis.applogger.AppLogger(TESTLOG)
1487 __mydict = MyDict()
1488 __mydict.missing_files = []
1489 __mydict.unexpected_files = []
1490 __mydict.missing_equality = []
1491 __mydict.missing_smaller_than = []
1492 __mydict.missing_bigger_than = []
1493 __mydict.mismatched_uids = []
1494 __mydict.mismatched_gids = []
1495 __mydict.mismatched_modes = [{'path':'classifydifferences7', 'expectedmode':'644','mode':'777'}]
1496 __mydict.mismatched_types = []
1497 __mydict.mismatched_hashes = []
1498 __mydict.mismatched_targets = []
1499 __mydict.mismatched_mtimes = []
1500 __myobj = brebis.archiveinfomsg.ArchiveInfoMsg(__mydict, {'path': 'testmodemismatches.tar.gz', 'sha512': None, 'files_list': '', 'type': 'archive', 'delimiter': None})
1501 __myobj._ArchiveInfoMsg__mode_mismatches(__mydict, 'testmodemismatches.tar.gz')
1502 with open(_logfile) as _res:
1503 __testresult = _res.read()
1504 self.assertIn('WARNING:root:classifydifferences7 mode is 777. Should have been 644.', __testresult)
1505
1506 def test_archiveinfomsg_target_mismatches(self):
1507 '''test the archiveinfomsg.ArchiveInfoMsg__target_mismatches method'''
1508 _logfile = TESTLOG
1509 brebis.applogger.AppLogger(TESTLOG)
1510 __mydict = MyDict()
1511 __mydict.missing_files = []
1512 __mydict.unexpected_files = []
1513 __mydict.missing_equality = []
1514 __mydict.missing_smaller_than = []
1515 __mydict.missing_bigger_than = []
1516 __mydict.mismatched_uids = []
1517 __mydict.mismatched_gids = []
1518 __mydict.mismatched_modes = []
1519 __mydict.mismatched_types = []
1520 __mydict.mismatched_hashes = []
1521 __mydict.mismatched_targets = [{'path':'classifydifferences8', 'expectedtarget':'../target1','target':'../target2'}]
1522 __mydict.mismatched_mtimes = []
1523 __myobj = brebis.archiveinfomsg.ArchiveInfoMsg(__mydict, {'path': 'testtargetmismatches.tar.gz', 'sha512': None, 'files_list': '', 'type': 'archive', 'delimiter': None})
1524 __myobj._ArchiveInfoMsg__target_mismatches(__mydict, 'testtargetmismatches.tar.gz')
1525 with open(_logfile) as _res:
1526 __testresult = _res.read()
1527 self.assertIn('WARNING:root:classifydifferences8 target is ../target2. Should have been ../target1.', __testresult)
1528
1529 def test_archiveinfomsg_type_mismatches(self):
1530 '''test the archiveinfomsg.ArchiveInfoMsg__type_mismatches method'''
1531 _logfile = TESTLOG
1532 brebis.applogger.AppLogger(TESTLOG)
1533 __mydict = MyDict()
1534 __mydict.missing_files = []
1535 __mydict.unexpected_files = []
1536 __mydict.missing_equality = []
1537 __mydict.missing_smaller_than = []
1538 __mydict.missing_bigger_than = []
1539 __mydict.mismatched_uids = []
1540 __mydict.mismatched_gids = []
1541 __mydict.mismatched_modes = []
1542 __mydict.mismatched_types = [{'path':'classifydifferences9', 'expectedtype':'s','type':'f'}]
1543 __mydict.mismatched_hashes = []
1544 __mydict.mismatched_targets = []
1545 __mydict.mismatched_mtimes = []
1546 __myobj = brebis.archiveinfomsg.ArchiveInfoMsg(__mydict, {'path': 'testtypemismatches.tar.gz', 'sha512': None, 'files_list': '', 'type': 'archive', 'delimiter': None})
1547 __myobj._ArchiveInfoMsg__target_mismatches(__mydict, 'testtypemismatches.tar.gz')
1548 with open(_logfile) as _res:
1549 __testresult = _res.read()
1550 self.assertIn('WARNING:root:classifydifferences9 is a regular file. Should have been a symbolic link.', __testresult)
1551
1552 def test_archiveinfomsg_hash_mismatches(self):
1553 '''test the archiveinfomsg.ArchiveInfoMsg__hash_mismatches method'''
1554 _logfile = TESTLOG
1555 brebis.applogger.AppLogger(TESTLOG)
1556 __mydict = MyDict()
1557 __mydict.missing_files = []
1558 __mydict.unexpected_files = []
1559 __mydict.missing_equality = []
1560 __mydict.missing_smaller_than = []
1561 __mydict.missing_bigger_than = []
1562 __mydict.mismatched_uids = []
1563 __mydict.mismatched_gids = []
1564 __mydict.mismatched_modes = []
1565 __mydict.mismatched_types = []
1566 __mydict.mismatched_hashes = [{'path':'classifydifferences10', 'expectedhash':'azeraezr','hash':'qdslfmjaze'}]
1567 __mydict.mismatched_targets = []
1568 __mydict.mismatched_mtimes = []
1569 __myobj = brebis.archiveinfomsg.ArchiveInfoMsg(__mydict, {'path': 'testhashmismatches.tar.gz', 'sha512': None, 'files_list': '', 'type': 'archive', 'delimiter': None})
1570 __myobj._ArchiveInfoMsg__hash_mismatches(__mydict, 'testhashmismatches.tar.gz')
1571 with open(_logfile) as _res:
1572 __testresult = _res.read()
1573 self.assertIn('WARNING:root:classifydifferences10 hash is qdslfmjaze. Should have been azeraezr.', __testresult)
1574
1575 #######################################################################################
1576 #
1577 # Testing the brebis.listtype.ListType
1578 #
1579 #######################################################################################
1580
1581 def test_listtype_tar(self):
1582 '''test the listtype class with a tar archive'''
1583 #__mydict = brebis.listtype.ListType({'arcpath': 'test.tar.gz', 'delimiter': None, 'genfull': True})
1584 __mydict = MyDict()
1585 __mydict.archives = ['tests/listtype/mytargz.tar.gz']
1586 __mydict.delimiter = None
1587 __mydict.hashtype = ''
1588 __mydict.genfull = True
1589 __mydict.getallhashes = True
1590 __mydict.fulloutput = ''
1591 __mydict.confoutput = ''
1592 __mydict.listoutput = ''
1593 __mydict = brebis.listtype.ListType(__mydict)
1594 self.assertEqual(str(type(__mydict._ListType__bck)), "<class 'brebis.generatelist.generatelistfortar.GenerateListForTar'>")
1595
1596 def test_listtype_tree(self):
1597 '''test the listtype class with a tree archive'''
1598 __mydict = MyDict()
1599 __mydict.archives = ['tests/listtype/mytree']
1600 __mydict.delimiter = None
1601 __mydict.hashtype = ''
1602 __mydict.genfull = True
1603 __mydict.getallhashes = True
1604 __mydict.fulloutput = ''
1605 __mydict.confoutput = ''
1606 __mydict.listoutput = ''
1607 __mydict = brebis.listtype.ListType(__mydict)
1608 self.assertEqual(str(type(__mydict._ListType__bck)), "<class 'brebis.generatelist.generatelistfortree.GenerateListForTree'>")
1609
1610 def test_listtype_zip(self):
1611 '''test the listtype class with a zip archive'''
1612 __mydict = MyDict()
1613 __mydict.archives = ['tests/listtype/myzip.zip']
1614 __mydict.delimiter = None
1615 __mydict.hashtype = ''
1616 __mydict.genfull = True
1617 __mydict.getallhashes = True
1618 __mydict.fulloutput = ''
1619 __mydict.confoutput = ''
1620 __mydict.listoutput = ''
1621 __mydict = brebis.listtype.ListType(__mydict)
1622 self.assertEqual(str(type(__mydict._ListType__bck)), "<class 'brebis.generatelist.generatelistforzip.GenerateListForZip'>")
1623
1624 def test_listtype_gz(self):
1625 '''test the listtype class with a gzip archive'''
1626 __mydict = MyDict()
1627 __mydict.archives = ['tests/listtype/mygzip.gz']
1628 __mydict.delimiter = None
1629 __mydict.hashtype = ''
1630 __mydict.genfull = True
1631 __mydict.getallhashes = True
1632 __mydict.fulloutput = ''
1633 __mydict.confoutput = ''
1634 __mydict.listoutput = ''
1635 __mydict = brebis.listtype.ListType(__mydict)
1636 self.assertEqual(str(type(__mydict._ListType__bck)), "<class 'brebis.generatelist.generatelistforgzip.GenerateListForGzip'>")
1637
1638 def test_listtype_bz2(self):
1639 '''test the listtype class with a bzip2 archive'''
1640 __mydict = MyDict()
1641 __mydict.archives = ['tests/listtype/mybz2.bz2']
1642 __mydict.delimiter = None
1643 __mydict.hashtype = ''
1644 __mydict.genfull = True
1645 __mydict.getallhashes = True
1646 __mydict.fulloutput = ''
1647 __mydict.confoutput = ''
1648 __mydict.listoutput = ''
1649 __mydict = brebis.listtype.ListType(__mydict)
1650 self.assertEqual(str(type(__mydict._ListType__bck)), "<class 'brebis.generatelist.generatelistforbzip2.GenerateListForBzip2'>")
1651
1652 def test_listtype_xz(self):
1653 '''test the listtype class with a lzma archive'''
1654 __mydict = MyDict()
1655 __mydict.archives = ['tests/listtype/mylzma.xz']
1656 __mydict.delimiter = None
1657 __mydict.hashtype = ''
1658 __mydict.genfull = True
1659 __mydict.getallhashes = True
1660 __mydict.fulloutput = ''
1661 __mydict.confoutput = ''
1662 __mydict.listoutput = ''
1663 __mydict = brebis.listtype.ListType(__mydict)
1664 self.assertEqual(str(type(__mydict._ListType__bck)), "<class 'brebis.generatelist.generatelistforlzma.GenerateListForLzma'>")
1665
1666 ################################################################
1667 #
1668 # End of the unit tests
1669 #
1670 ################################################################
1671 @classmethod
1672 def tearDownClass(TestApp):
1673 '''clean after the tests'''
1674 _logfile = TESTLOG
1675 os.remove(_logfile)
1676
1677 if __name__ == '__main__':
1678 unittest.main()