added test for error checking on log uploader

This commit is contained in:
John Dickinson 2012-01-17 09:31:33 -06:00
parent ca810882f9
commit fed1581e93

View File

@ -81,6 +81,12 @@ class MockLogUploader(_orig_LogUploader):
day, hour)
class ErrorLogUploader(MockLogUploader):
def upload_one_log(self, filename, year, month, day, hour):
raise OSError('foo bar')
class TestLogUploader(unittest.TestCase):
def setUp(self):
@ -94,6 +100,20 @@ class TestLogUploader(unittest.TestCase):
log_uploader.appconfig = self._orig_appconfig
log_uploader.InternalProxy = self._orig_InternalProxy
def test_bad_upload(self):
files = [datetime.now().strftime('%Y%m%d%H')]
with temptree(files, contents=[COMPRESSED_DATA] * len(files)) as t:
# invalid pattern
conf = {'log_dir': t,
'source_filename_pattern': '%Y%m%d%h'} # should be %H
uploader = MockLogUploader(conf)
self.assertRaises(SystemExit, uploader.upload_all_logs)
conf = {'log_dir': t, 'source_filename_pattern': access_regex}
uploader = ErrorLogUploader(conf)
# this tests if the exception is handled
uploader.upload_all_logs()
def test_bad_pattern_in_config(self):
files = [datetime.now().strftime('%Y%m%d%H')]
with temptree(files, contents=[COMPRESSED_DATA] * len(files)) as t: