def test_create_tarfile_fails_on_tar_failure(self, log): os.makedirs('2016/01/28') file('2016/01/28/test1.txt', 'w').write('hello') file('2016/01/28/test2.txt', 'w').write('goodbye') with self.assertRaises(scraper.NonRecoverableScraperException): scraper.create_tarfile( '/bin/false', 'test.tgz', ['2016/01/28/test1.txt', '2016/01/28/test2.txt']) self.assertIn('ERROR', [x.levelname for x in log.records])
def test_create_tarfile_fails_when_file_is_missing(self, log): os.makedirs('2016/01/28') file('2016/01/28/test1.txt', 'w').write('hello') file('2016/01/28/test2.txt', 'w').write('goodbye') with self.assertRaises(scraper.NonRecoverableScraperException): # Executes successfully, but fails to create the tarfile. scraper.create_tarfile( '/bin/true', 'test.tgz', ['2016/01/28/test1.txt', '2016/01/28/test2.txt']) self.assertIn('ERROR', [x.levelname for x in log.records])
def test_create_tarfile_succeeds_on_existing_tarfile(self, log): os.makedirs('2016/01/28') file('2016/01/28/test1.txt', 'w').write('hello') file('2016/01/28/test2.txt', 'w').write('goodbye') file('test.tgz', 'w').write('in the way') self.assertEqual(file('test.tgz').read(), 'in the way') scraper.create_tarfile( '/bin/tar', 'test.tgz', ['2016/01/28/test1.txt', '2016/01/28/test2.txt']) self.assertIn('WARNING', [x.levelname for x in log.records])
def test_create_tarfile(self): os.makedirs('2016/01/28') file('2016/01/28/test1.txt', 'w').write('hello') file('2016/01/28/test2.txt', 'w').write('goodbye') scraper.create_tarfile( '/bin/tar', 'test.tgz', ['2016/01/28/test1.txt', '2016/01/28/test2.txt']) shutil.rmtree('2016') self.assertFalse(os.path.exists('2016')) self.assertTrue(os.path.exists('test.tgz')) subprocess.check_call(['/bin/tar', 'xfz', 'test.tgz']) self.assertTrue(os.path.exists('2016')) self.assertEqual(file('2016/01/28/test1.txt').read(), 'hello') self.assertEqual(file('2016/01/28/test2.txt').read(), 'goodbye')