def test_get_last_run(self):
     no_run_status = StatusManager("TestBot")
     compare(None, no_run_status.last_run)
     one_run_status = StatusManager("TestBot")
     compare(None, no_run_status.last_run)
     compare(datetime(year=2001, month=1, day=1, minute=0),
             one_run_status.last_runs[0].start_time)
 def test_finish_run(self):
     manager = StatusManager("TestBot")
     manager.finish_run()
     last_item = StatusManager("TestBot").last_run
     compare(True, last_item.finish)
     self.assertGreater(last_item.finish_time, datetime.min)
     self.assertGreater(last_item.finish_time, last_item.start_time)
    def test_finish_success(self):
        manager = StatusManager("TestBot")
        manager.current_run.success = True
        manager.finish_run()
        last_item = StatusManager("TestBot").last_run
        compare(True, last_item.success)

        manager2 = StatusManager("TestBot")
        manager2.finish_run(success=True)
        last_item = StatusManager("TestBot").last_run
        compare(True, last_item.success)
 def test_get_last_runs(self):
     StatusManager("TestBot")
     time.sleep(0.01)
     StatusManager("TestBot1")
     StatusManager("TestBot")
     status_manager_last_runs = StatusManager("TestBot")
     compare(2, len(status_manager_last_runs.last_runs))
     # newest entry first in array
     compare(datetime(year=2001, month=1, day=1, minute=4),
             status_manager_last_runs.last_runs[0].start_time)
     compare(datetime(year=2001, month=1, day=1, minute=0),
             status_manager_last_runs.last_runs[1].start_time)
 def test_get_last_finished_runs(self):
     manager = StatusManager("TestBot")
     manager.finish_run()
     StatusManager("TestBot")
     manager = StatusManager("TestBot")
     manager.finish_run(success=True)
     status_manager_last_runs = StatusManager("TestBot")
     compare(2, len(status_manager_last_runs.last_finished_runs))
     # newest entry first in array
     compare(datetime(year=2001, month=1, day=1, minute=6),
             status_manager_last_runs.last_finished_runs[0].start_time)
     compare(datetime(year=2001, month=1, day=1, minute=0),
             status_manager_last_runs.last_finished_runs[1].start_time)
Example #6
0
 def test_set_timestamp_for_searcher_no_successful_run(self):
     self._make_json_file(filename="MinimalBot.data.json")
     StatusManager("MinimalBot").finish_run(success=False)
     with self.MinimalBot(log_to_screen=False, log_to_wiki=False) as bot:
         self.assertEqual(
             datetime(1, 1, 1),
             bot.create_timestamp_for_search(offset=timedelta(days=1)))
Example #7
0
 def test_data_outdated_not_outdated_1(self):
     self._make_json_file(filename="DataOutdatedBot.data.json")
     StatusManager("DataOutdatedBot").finish_run(success=True)
     with self.DataOutdatedBot(log_to_screen=False,
                               log_to_wiki=False) as bot:
         self.assertFalse(bot.data_outdated())
         self.assertDictEqual({"a": [1, 2]}, bot.data._data)
Example #8
0
 def test_load_and_store_data(self):
     self._make_json_file(filename="AddDataBot.data.json")
     StatusManager("AddDataBot").finish_run(success=True)
     with self.AddDataBot(log_to_screen=False, log_to_wiki=False) as bot:
         compare({"a": [1, 2]}, bot.data._data)
         bot.run()
     with self.AddDataBot(log_to_screen=False, log_to_wiki=False) as bot:
         compare({"a": [1, 2], "b": 2}, bot.data._data)
Example #9
0
 def test_no_load_model_outdated(self):
     self._make_json_file(filename="DataOutdatedBot.data.json")
     StatusManager("DataOutdatedBot").finish_run(success=True)
     with LogCapture() as log_catcher:
         with self.DataOutdatedBot(log_to_screen=False,
                                   log_to_wiki=False) as bot:
             self.assertIn(
                 "DataOutdatedBot WARNING\n  The data is thrown away. It is out of date",
                 str(log_catcher))
             self.assertDictEqual({}, bot.data._data)
             bot.run()
Example #10
0
 def test_init(self):
     StatusManager("TestBot")
     compare(
         {
             "bot_name": "TestBot",
             "finish": mock.ANY,
             "success": mock.ANY,
             "start_time": "2001-01-01T00:00:00",
             "finish_time": mock.ANY,
             "output": mock.ANY
         },
         self.manage_table.get_item(Key={
             "bot_name": "TestBot",
             "start_time": "2001-01-01T00:00:00"
         })["Item"])
Example #11
0
 def test_keep_broken_data(self):
     self._make_json_file(filename="DataThrowException.data.json")
     StatusManager("DataThrowException").finish_run(success=True)
     with LogCapture() as log_catcher:
         with mock.patch("tools.bots.cloud.lambda_bot.PersistedData.dump"
                         ) as mock_dump:
             with self.DataThrowException(log_to_screen=False,
                                          log_to_wiki=False) as bot:
                 log_catcher.clear()
                 bot.run()
             mock_dump.assert_called_once_with(success=False)
             self.assertIn(
                 "DataThrowException CRITICAL\n"
                 "  There was an error in the general procedure. "
                 "The broken data and a backup of the old will be keept.",
                 str(log_catcher))
Example #12
0
 def __init__(self,
              wiki: Site = None,
              debug: bool = True,
              log_to_screen: bool = True,
              log_to_wiki: bool = True):
     self.success: bool = False
     self.log_to_screen: bool = log_to_screen
     self.log_to_wiki: bool = log_to_wiki
     self.status: StatusManager = StatusManager(bot_name=self.bot_name)
     self.data: PersistedData = PersistedData(bot_name=self.bot_name)
     self.wiki: Page = wiki
     self.debug: bool = debug
     self.timeout: timedelta = timedelta(days=1)
     self.logger: WikiLogger = WikiLogger(
         self.bot_name,
         self.status.current_run.start_time,
         log_to_screen=self.log_to_screen)
     self.new_data_model = datetime.min
Example #13
0
 def test_finish_no_success(self):
     manager = StatusManager("TestBot")
     manager.finish_run()
     last_item = StatusManager("TestBot").last_run
     compare(False, last_item.success)
Example #14
0
 def test_last_run_successful_false_1(self):
     self._make_json_file(filename="MinimalBot.data.json")
     StatusManager("MinimalBot").finish_run(success=False)
     with self.MinimalBot(log_to_screen=False, log_to_wiki=False) as bot:
         self.assertFalse(bot.status.last_run.success)
Example #15
0
 def test_last_run_failure(self):
     self._make_json_file(filename="AddDataBot.data.json")
     StatusManager("AddDataBot").finish_run(success=False)
     with self.AddDataBot(log_to_screen=False, log_to_wiki=False) as bot:
         compare({}, bot.data._data)