async def test_install_all_tentacles_with_profile(clean): _enable_loggers() profile_path = os.path.join(commons_constants.USER_PROFILES_FOLDER, "many_traded_elements") assert not os.path.isfile(os.path.join(profile_path, commons_constants.PROFILE_CONFIG_FILE)) tentacles_path = os.path.join("tests", "static", "tentacles_with_profile.zip") await fetch_and_extract_tentacles(TEMP_DIR, tentacles_path, None) worker = InstallWorker(TEMP_DIR, TENTACLES_PATH, DEFAULT_BOT_PATH, False, None) worker.tentacles_path_or_url = tentacles_path worker.tentacles_setup_manager.default_tentacle_config = \ os.path.join("tests", "static", "default_tentacle_config.json") assert await worker.process() == 0 # test installed files to ensure tentacles installation got well trading_mode_files_count = sum(1 for _ in os.walk(os.path.join(TENTACLES_PATH, "Trading", "Mode"))) assert trading_mode_files_count == 5 config_files = [f for f in os.walk(os.path.join(profile_path, TENTACLES_SPECIFIC_CONFIG_FOLDER))] config_files_count = len(config_files) assert config_files_count == 1 assert "DailyTradingMode.json" in config_files[0][2] assert len(config_files[0][2]) == 18 # test installed profile assert os.path.isfile(os.path.join(profile_path, commons_constants.PROFILE_CONFIG_FILE)) assert os.path.isfile(os.path.join(profile_path, "default_profile.png")) assert os.path.isfile(os.path.join(profile_path, commons_constants.CONFIG_TENTACLES_FILE)) assert os.path.isfile(os.path.join(profile_path, TENTACLES_SPECIFIC_CONFIG_FOLDER, "DailyTradingMode.json")) assert os.path.isfile(os.path.join(profile_path, TENTACLES_SPECIFIC_CONFIG_FOLDER, "TwitterNewsEvaluator.json"))
async def test_uninstall_all_tentacles(clean): _enable_loggers() tentacles_path = os.path.join("tests", "static", "tentacles.zip") await fetch_and_extract_tentacles(TEMP_DIR, tentacles_path, None) install_worker = InstallWorker(TEMP_DIR, TENTACLES_PATH, DEFAULT_BOT_PATH, False, None) install_worker.tentacles_path_or_url = tentacles_path install_worker.tentacles_setup_manager.default_tentacle_config = \ os.path.join("tests", "static", "default_tentacle_config.json") assert await install_worker.process() == 0 tentacles_files_count = sum(1 for _ in os.walk(TENTACLES_PATH)) assert tentacles_files_count > 60 uninstall_worker = UninstallWorker(None, TENTACLES_PATH, DEFAULT_BOT_PATH, False, None) uninstall_worker.tentacles_setup_manager.default_tentacle_config = \ os.path.join("tests", "static", "default_tentacle_config.json") assert await uninstall_worker.process() == 0 tentacles_files_count = sum(1 for _ in os.walk(TENTACLES_PATH)) assert tentacles_files_count == 24 with open(USER_REFERENCE_TENTACLE_CONFIG_FILE_PATH, "r") as config_f: assert json.load(config_f) == { 'registered_tentacles': {}, 'tentacle_activation': { 'Backtesting': {}, 'Evaluator': {}, 'Services': {}, 'Trading': {} } }
async def test_profiles_update(clean, fake_profiles): _enable_loggers() tentacles_path = os.path.join("tests", "static", "tentacles.zip") await fetch_and_extract_tentacles(TEMP_DIR, tentacles_path, None) worker = InstallWorker(TEMP_DIR, TENTACLES_PATH, DEFAULT_BOT_PATH, False, None) worker.tentacles_path_or_url = tentacles_path worker.tentacles_setup_manager.default_tentacle_config = \ os.path.join("tests", "static", "default_tentacle_config.json") # install all tentacles assert await worker.process() == 0 # test tentacles setup config with open(USER_REFERENCE_TENTACLE_CONFIG_FILE_PATH) as config_f: ref_profile_config = json.load(config_f) # test profiles tentacles config with open( os.path.join( commons_constants.USER_PROFILES_FOLDER, commons_constants.DEFAULT_PROFILE, commons_constants.CONFIG_TENTACLES_FILE)) as default_c: assert ref_profile_config == json.load(default_c) with open( os.path.join( commons_constants.USER_PROFILES_FOLDER, OTHER_PROFILE, commons_constants.CONFIG_TENTACLES_FILE)) as other_c: assert ref_profile_config == json.load(other_c) # test specific tentacles config default_profile_tentacles_config = os.path.join( commons_constants.USER_PROFILES_FOLDER, commons_constants.DEFAULT_PROFILE, TENTACLES_SPECIFIC_CONFIG_FOLDER) other_profile_tentacles_config = os.path.join( commons_constants.USER_PROFILES_FOLDER, OTHER_PROFILE, TENTACLES_SPECIFIC_CONFIG_FOLDER) for tentacle_config in os.scandir( os.path.join( os.path.split(USER_REFERENCE_TENTACLE_CONFIG_FILE_PATH)[0], TENTACLES_SPECIFIC_CONFIG_FOLDER)): with open(tentacle_config) as ref_config_file: ref_config = json.load(ref_config_file) with open( os.path.join( default_profile_tentacles_config, tentacle_config.name)) as default_profile_config_file: assert ref_config == json.load(default_profile_config_file) with open( os.path.join( other_profile_tentacles_config, tentacle_config.name)) as other_profile_config_file: assert ref_config == json.load(other_profile_config_file)
async def test_install_all_tentacles(clean): _enable_loggers() tentacles_path = os.path.join("tests", "static", "tentacles.zip") await fetch_and_extract_tentacles(TEMP_DIR, tentacles_path, None) worker = InstallWorker(TEMP_DIR, TENTACLES_PATH, DEFAULT_BOT_PATH, False, None) worker.tentacles_path_or_url = tentacles_path worker.tentacles_setup_manager.default_tentacle_config = \ os.path.join("tests", "static", "default_tentacle_config.json") assert await worker.process() == 0 # test installed files trading_mode_files_count = sum( 1 for _ in os.walk(os.path.join(TENTACLES_PATH, "Trading", "Mode"))) assert trading_mode_files_count == 5 config_files = [ f for f in os.walk(USER_REFERENCE_TENTACLE_SPECIFIC_CONFIG_PATH) ] config_files_count = len(config_files) assert config_files_count == 1 assert "DailyTradingMode.json" in config_files[0][2] assert len(config_files[0][2]) == 5 # test tentacles config with open(USER_REFERENCE_TENTACLE_CONFIG_FILE_PATH, "r") as config_f: assert json.load(config_f) == { 'registered_tentacles': { 'OctoBot-Default-Tentacles': tentacles_path }, 'tentacle_activation': { 'Backtesting': { 'GenericExchangeDataImporter': True }, 'Evaluator': { 'InstantFluctuationsEvaluator': True, 'OtherInstantFluctuationsEvaluator': False, 'OverallStateAnalyser': True, 'RedditForumEvaluator': False, 'SecondOtherInstantFluctuationsEvaluator': False, 'SimpleMixedStrategyEvaluator': True, 'TextAnalysis': True }, 'Services': { 'RedditService': True, 'RedditServiceFeed': True }, 'Trading': { 'DailyTradingMode': True } } }
async def test_uninstall_two_tentacles(clean): _enable_loggers() tentacles_path = os.path.join("tests", "static", "tentacles.zip") await fetch_and_extract_tentacles(TEMP_DIR, tentacles_path, None) install_worker = InstallWorker(TEMP_DIR, TENTACLES_PATH, DEFAULT_BOT_PATH, False, None) install_worker.tentacles_path_or_url = tentacles_path install_worker.tentacles_setup_manager.default_tentacle_config \ = os.path.join("tests", "static", "default_tentacle_config.json") assert await install_worker.process() == 0 tentacles_files_count = sum(1 for _ in os.walk(TENTACLES_PATH)) assert tentacles_files_count > 60 uninstall_worker = UninstallWorker(None, TENTACLES_PATH, DEFAULT_BOT_PATH, False, None) uninstall_worker.tentacles_setup_manager.default_tentacle_config = \ os.path.join("tests", "static", "default_tentacle_config.json") assert await uninstall_worker.process( ["instant_fluctuations_evaluator", "generic_exchange_importer"]) == 0 tentacles_files_count = sum(1 for _ in os.walk(TENTACLES_PATH)) assert tentacles_files_count < 60 with open(USER_REFERENCE_TENTACLE_CONFIG_FILE_PATH, "r") as config_f: assert json.load(config_f) == { 'installation_context': { 'octobot_version': 'unknown' }, 'registered_tentacles': { 'OctoBot-Default-Tentacles': tentacles_path }, 'tentacle_activation': { 'Backtesting': {}, 'Evaluator': { 'OtherInstantFluctuationsEvaluator': False, 'OverallStateAnalyser': True, 'RedditForumEvaluator': False, 'SecondOtherInstantFluctuationsEvaluator': False, 'SimpleMixedStrategyEvaluator': True, 'TextAnalysis': True }, 'Services': { 'RedditService': True, 'RedditServiceFeed': True }, 'Trading': { 'DailyTradingMode': True } } }
async def test_profiles_update(clean, fake_profiles): _enable_loggers() tentacles_path = os.path.join("tests", "static", "tentacles.zip") await fetch_and_extract_tentacles(TEMP_DIR, tentacles_path, None) install_worker = InstallWorker(TEMP_DIR, TENTACLES_PATH, DEFAULT_BOT_PATH, False, None) install_worker.tentacles_path_or_url = tentacles_path install_worker.tentacles_setup_manager.default_tentacle_config \ = os.path.join("tests", "static", "default_tentacle_config.json") assert await install_worker.process() == 0 tentacles_files_count = sum(1 for _ in os.walk(TENTACLES_PATH)) assert tentacles_files_count > 60 ref_specific_tentacles_config = os.path.join( TENTACLES_PATH, TENTACLES_EVALUATOR_PATH, TENTACLES_EVALUATOR_REALTIME_PATH, "instant_fluctuations_evaluator", TENTACLE_CONFIG) with open( os.path.join(ref_specific_tentacles_config, "InstantFluctuationsEvaluator.json")) as ref_conf: instant_fluct_config = json.load(ref_conf) uninstall_worker = UninstallWorker(None, TENTACLES_PATH, DEFAULT_BOT_PATH, False, None) uninstall_worker.tentacles_setup_manager.default_tentacle_config = \ os.path.join("tests", "static", "default_tentacle_config.json") # uninstall 2 tentacles assert await uninstall_worker.process( ["instant_fluctuations_evaluator", "generic_exchange_importer"]) == 0 # test tentacles setup config with open(USER_REFERENCE_TENTACLE_CONFIG_FILE_PATH) as config_f: ref_profile_config = json.load(config_f) # test profiles tentacles config with open( os.path.join( commons_constants.USER_PROFILES_FOLDER, commons_constants.DEFAULT_PROFILE, commons_constants.CONFIG_TENTACLES_FILE)) as default_c: assert ref_profile_config == json.load(default_c) with open( os.path.join( commons_constants.USER_PROFILES_FOLDER, OTHER_PROFILE, commons_constants.CONFIG_TENTACLES_FILE)) as other_c: assert ref_profile_config == json.load(other_c)
async def test_install_two_tentacles(clean): _enable_loggers() tentacles_path = os.path.join("tests", "static", "tentacles.zip") await fetch_and_extract_tentacles(TEMP_DIR, tentacles_path, None) worker = InstallWorker(TEMP_DIR, TENTACLES_PATH, DEFAULT_BOT_PATH, False, None) worker.tentacles_path_or_url = tentacles_path worker.tentacles_setup_manager.default_tentacle_config = \ os.path.join("tests", "static", "default_tentacle_config.json") assert await worker.process( ["instant_fluctuations_evaluator", "generic_exchange_importer"]) == 0 # test installed files trading_mode_files_count = sum( 1 for _ in os.walk(os.path.join(TENTACLES_PATH, "Trading", "Mode"))) assert trading_mode_files_count == 1 backtesting_mode_files_count = sum(1 for _ in os.walk( os.path.join(TENTACLES_PATH, "Backtesting", "importers"))) assert backtesting_mode_files_count == 7 config_files = [ f for f in os.walk(USER_REFERENCE_TENTACLE_SPECIFIC_CONFIG_PATH) ] config_files_count = len(config_files) assert config_files_count == 1 assert "InstantFluctuationsEvaluator.json" in config_files[0][2] assert "DailyTradingMode.json" not in config_files[0][2] assert len(config_files[0][2]) == 1 # test tentacles config with open(USER_REFERENCE_TENTACLE_CONFIG_FILE_PATH, "r") as config_f: ref_profile_config = json.load(config_f) assert ref_profile_config == { 'registered_tentacles': { 'OctoBot-Default-Tentacles': tentacles_path }, 'tentacle_activation': { 'Backtesting': { 'GenericExchangeDataImporter': True }, 'Evaluator': { 'InstantFluctuationsEvaluator': True } } }