def test_fetch_amazon_config(self): # Retrieve config props amazon_config = config.fetch_bot_config(env='local')['amazon_config'] # Assert Amazon prop self.assertEquals(amazon_config['associate_tag'], 'gearstack-20') self.assertEquals(amazon_config['cat_starter_node'], 11965861)
def setUpClass(cls): all_configs = config_utils.fetch_bot_config(env='local') amazon_configs = all_configs['amazon_config'] bot_db_configs = all_configs['db_config']['bot_db_props'] app_db_configs = all_configs['db_config']['app_db_props'] cls.cat_retriever = GearTypeRetriever(amazon_config=amazon_configs, bot_db_configs=bot_db_configs, app_db_configs=app_db_configs)
def test_fetch_db_config(self): # Retrieve config props db_config = config.fetch_bot_config(env='local')['db_config'] # Assert an application database prop self.assertEquals(db_config['app_db_props']['db_name'], 'gearstack') # Assert a log database prop self.assertEquals(db_config['bot_log_db_props']['db_name'], 'gearstack_bot_logs') # Assert a bot database prop self.assertEquals(db_config['bot_db_props']['db_name'], 'gearstack_bot')
def setUpClass(cls): bot_db_configs = config_utils.fetch_bot_config(env='local')['db_config']['bot_db_props'] cls.dao = GearTypeRetrievedDAO(bot_db_configs=bot_db_configs)
def setUpClass(cls): cls.db_configs = config_utils.fetch_bot_config( env="local")['db_config']
def setUpClass(cls): app_db_config = config_utils.fetch_bot_config( env='local')['db_config']['app_db_props'] cls.dao = GearDAO(app_db_config)
def setUpClass(cls): configs = config_utils.fetch_bot_config(env='local') cls.retriever = GearRetriever( amazon_config=configs['amazon_config'], app_db_config=configs['db_config']['app_db_props'], exclusion_keys=config_utils.fetch_data_config('excluded_keywords'))
def main(argv): # Gather command line args env = None log_level = None usage = 'geartype_rbt_runner.py --env <local | dev | prod> --log_level <info | debug | warning | error>' try: opts, args = getopt.getopt(argv, "h", ["env=", "log_level="]) except getopt.GetoptError: print('An invalid argument was specified!') sys.exit(2) for opt, arg in opts: if opt == '-h': print(usage) sys.exit(0) elif opt == '--env': env = arg elif opt == '--log_level': log_level = arg # Validate command line args try: # env arg if env.lower() not in ('local', 'dev', 'prod'): print('An invalid value {0} was specified for arg [--env]'.format( env)) print(usage) sys.exit(2) # log_level arg if log_level.lower() not in ('info', 'debug', 'warning', 'error', 'critical'): print('An invalid value {0} was specified for arg [--log_level]'. format(log_level)) print(usage) sys.exit(2) except AttributeError: print('An invalid argument was specified!') print(usage) sys.exit(2) # Create logger and log options specified logger = log_utils.init_root_logger(logger_name="gearstack_rbt", log_path='../log/geartype_rbt.log', log_level=log_level) logger.info('Gearstack Gear Type Bot') logger.info('Environment: {0}'.format(env.upper())) logger.info('Log Level: {0}'.format(log_level.upper())) # Fetch configuration data for specified environment bot_configs = config_utils.fetch_bot_config(env) types = config_utils.fetch_data_config('cat_data_keys') # Instantiate retriever object type_retriever = GearTypeRetriever( amazon_config=bot_configs['amazon_config'], bot_db_configs=bot_configs['db_config']['bot_db_props'], app_db_configs=bot_configs['db_config']['app_db_props']) # Iterate through types list and persist try: for type in types: nodes_for_type = config_utils.fetch_data_config(config_name=type) type_retriever.save_geartypes(node_ids=nodes_for_type) logger.info('Finished persisting gear types!') except Exception: logger.exception('An error occurred during persistence of gear types!') finally: log_utils.close_logger(logger)
def test_fetch_config_fail(self): # Attempt to retrieve config props from bogus environment # Use assertRaises as context manager here to avoid failure due to exception with self.assertRaises(InvalidEnvException): config.fetch_bot_config(env='bogus')
def main(argv): # Gather command line args env = None log_level = None browse_node = None usage = "gear_rbt_runner.py --env <local|dev|prod> --log_level <info|debug|warning|error> " \ "--browse_node <browse_node_id>" try: opts, args = getopt.getopt(argv, "h", ["env=", "log_level=", "browse_node="]) except getopt.GetoptError: print('An invalid argument was specified!') sys.exit(2) for opt, arg in opts: if opt == '-h': print(usage) sys.exit(0) elif opt == '--env': env = arg elif opt == '--log_level': log_level = arg elif opt == '--browse_node': browse_node = arg # Validate command line args try: # env arg if env.lower() not in ('local', 'dev', 'prod'): print('An invalid value {0} was specified for arg [--env]'.format( env)) print(usage) sys.exit(2) # log_level arg if log_level.lower() not in ('info', 'debug', 'warning', 'error', 'critical'): print('An invalid value {0} was specified for arg [--log_level]'. format(log_level)) print(usage) sys.exit(2) # browse_node arg browse_node = int(browse_node) except (AttributeError, ValueError): print('An invalid argument was specified!') print(usage) sys.exit(2) # Create logger and log options specified logger = log_utils.init_root_logger(logger_name="gear_rbt_logger", log_path='../log/gear_rbt.log', log_level=log_level) logger.info('Gearstack Gear Bot') logger.info('Environment: {0}'.format(env.upper())) logger.info('Log Level: {0}'.format(log_level.upper())) logger.info('Amazon Browse Node: {0}'.format(browse_node)) # Fetch configuration data for specified environment bot_configs = config_utils.fetch_bot_config(env) # Instantiate gear retriever instance gear_retriever = GearRetriever( amazon_config=bot_configs['amazon_config'], app_db_config=bot_configs['db_config']['app_db_props'], exclusion_keys=config_utils.fetch_data_config('excluded_keywords')) # Loop through nodes_to_search list and execute amazon API search # and item save try: fetched_items = gear_retriever.search_items(browse_node_id=browse_node) gear_retriever.save_gear(item_list=fetched_items, browse_node=browse_node) logger.info("Finished DB population for browse node {0}!!!".format( browse_node)) except Exception: logger.exception( 'Gear Retriever bot encountered an exception during execution!') finally: log_utils.close_logger(logger)