diff --git a/test_slogging/unit/test_log_uploader.py b/test_slogging/unit/test_log_uploader.py index 52bfe5c..1520ac8 100644 --- a/test_slogging/unit/test_log_uploader.py +++ b/test_slogging/unit/test_log_uploader.py @@ -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: