async def test_fill_tentacle_config(): async with aiohttp.ClientSession() as session: await api.install_all_tentacles(_tentacles_local_path(), aiohttp_session=session) setup_config = configuration.TentaclesSetupConfiguration() available_tentacle = util.load_tentacle_with_metadata(constants.TENTACLES_PATH) with mock.patch.object(setup_config, "_get_installation_context_bot_version", mock.Mock()) as bot_version_mock: bot_version_mock.return_value = "1.0.5" await setup_config.fill_tentacle_config(available_tentacle, constants.TENTACLE_CONFIG_FILE_NAME) assert setup_config.installation_context == { constants.TENTACLE_INSTALLATION_CONTEXT_OCTOBOT_VERSION: "1.0.5" } setup_config = configuration.TentaclesSetupConfiguration() await setup_config.fill_tentacle_config(available_tentacle, constants.TENTACLE_CONFIG_FILE_NAME) assert setup_config.installation_context == { constants.TENTACLE_INSTALLATION_CONTEXT_OCTOBOT_VERSION: constants.TENTACLE_INSTALLATION_CONTEXT_OCTOBOT_VERSION_UNKNOWN } assert not api.are_tentacles_up_to_date(setup_config, constants.TENTACLE_INSTALLATION_CONTEXT_OCTOBOT_VERSION_UNKNOWN) assert not api.are_tentacles_up_to_date(setup_config, '1.0.0') setup_config.installation_context[constants.TENTACLE_INSTALLATION_CONTEXT_OCTOBOT_VERSION] = '2.0.0' assert not api.are_tentacles_up_to_date(setup_config, '2.1.0') assert api.are_tentacles_up_to_date(setup_config, '2.0.0') assert api.are_tentacles_up_to_date(setup_config, '2.0.0b1') _cleanup()
async def refresh_user_tentacles_setup_config_file( self, tentacles_setup_config_to_update=None, update_location=None, force_update_registered_tentacles=False, newly_installed_tentacles=None, uninstalled_tentacles=None): available_tentacle = util.load_tentacle_with_metadata( self.tentacle_setup_root_path) if not tentacles_setup_config_to_update: reference_tentacle_setup_config = configuration.TentaclesSetupConfiguration( bot_installation_path=self.bot_installation_path) # Do not read activation config to force default values generation and avoid side effects on # profiles activations reference_tentacle_setup_config.read_config( self.tentacle_setup_root_path, False) else: reference_tentacle_setup_config = tentacles_setup_config_to_update await reference_tentacle_setup_config.fill_tentacle_config( available_tentacle, self.default_tentacle_config, update_location=update_location, force_update_registered_tentacles=force_update_registered_tentacles, newly_installed_tentacles=newly_installed_tentacles, uninstalled_tentacles=uninstalled_tentacles) reference_tentacle_setup_config.save_config() reference_tentacle_setup_config.refresh_profile_tentacles_config( available_tentacle, newly_installed_tentacles=newly_installed_tentacles, uninstalled_tentacles=uninstalled_tentacles)
async def refresh_user_tentacles_setup_config_file( self, tentacles_setup_config_to_update=None, update_location=None, force_update_registered_tentacles=False, newly_installed_tentacles=None, uninstalled_tentacles=None): available_tentacle = util.load_tentacle_with_metadata( self.tentacle_setup_root_path) if not tentacles_setup_config_to_update: tentacle_setup_config = configuration.TentaclesSetupConfiguration( bot_installation_path=self.bot_installation_path) tentacle_setup_config.read_config(self.tentacle_setup_root_path) else: tentacle_setup_config = tentacles_setup_config_to_update await tentacle_setup_config.fill_tentacle_config( available_tentacle, self.default_tentacle_config, update_location=update_location, force_update_registered_tentacles=force_update_registered_tentacles, newly_installed_tentacles=newly_installed_tentacles, uninstalled_tentacles=uninstalled_tentacles) tentacle_setup_config.save_config() tentacle_setup_config.refresh_profile_tentacles_config( available_tentacle, newly_installed_tentacles=newly_installed_tentacles, uninstalled_tentacles=uninstalled_tentacles)
def get_tentacles_setup_config( config_path=constants.USER_REFERENCE_TENTACLE_CONFIG_FILE_PATH ) -> configuration.TentaclesSetupConfiguration: setup_config = configuration.TentaclesSetupConfiguration( config_path=config_path) setup_config.read_config() return setup_config
async def test_get_config(): _cleanup() async with aiohttp.ClientSession() as session: await api.install_all_tentacles(_tentacles_local_path(), aiohttp_session=session) from tentacles.Evaluator.RealTime import InstantFluctuationsEvaluator setup_config = configuration.TentaclesSetupConfiguration() assert get_config(setup_config, InstantFluctuationsEvaluator) == { "price_difference_threshold_percent": 1, "volume_difference_threshold_percent": 400 } from tentacles.Services import RedditService assert get_config(setup_config, RedditService) == {} _cleanup()
async def test_update_config(): async with aiohttp.ClientSession() as session: await install_all_tentacles(_tentacles_local_path(), aiohttp_session=session) from tentacles.Evaluator.RealTime import InstantFluctuationsEvaluator setup_config = configuration.TentaclesSetupConfiguration() config_update = {"price_difference_threshold_percent": 2, "plop": 42} update_config(setup_config, InstantFluctuationsEvaluator, config_update) assert get_config(setup_config, InstantFluctuationsEvaluator) == { "price_difference_threshold_percent": 2, "volume_difference_threshold_percent": 400, "plop": 42 } _cleanup()
def create_tentacles_setup_config_with_tentacles(*tentacles_classes): setup_config = configuration.TentaclesSetupConfiguration() setup_config.from_activated_tentacles_classes(*tentacles_classes) return setup_config