def test_last_update_equals(self, mock_current_time, mock_notifier, mock_storage, mock_comparator): mock_storage.get_last_update.return_value = update(1, 0, 0, 1453303423) processor.on_new_update(update(1, 0, 0, 1453303424)) mock_notifier.notify.assert_not_called() mock_storage.save_last_update.assert_called_with(update(1, 0, 0, 1453303467))
def test_no_last_update(self, mock_current_time, mock_notifier, mock_storage): mock_storage.get_last_update.return_value = None processor.on_new_update(update(1, 0, 0)) mock_notifier.notify.assert_not_called() mock_storage.save_last_update.assert_called_with(update(1, 0, 0, 1453306171))
def on_new_update(update): if 'sensors' not in update: return 422, "Invalid update" try: processor.on_new_update(update) return 200, "Update processed" except OperationalError as e: return 500, "Cannot process update: " + str(e)
def test_new_sensor(self, mock_settings, mock_current_time, mock_notifier, mock_storage, mock_comparator): mock_storage.get_last_update.return_value = update(0, 0, 0, 1453303467) processor.on_new_update(update(0, 0, 0, 1453303469)) expected_system_state = update(0, 0, 0, 1453303467) expected_system_state['time'] = 1453303467 expected_system_state['mode'] = 'guard' expected_system_state['state'] = 'ok' expected_last_update_to_save = update(0, 0, 0, 1453303467) mock_notifier.notify.assert_called_with(Comparator.RESULT_NEW_SENSOR, expected_system_state) mock_storage.save_last_update.assert_called_with(expected_last_update_to_save) mock_storage.add_to_log.assert_called_with(expected_system_state)