def setup_class(cls): cls.krakens_pool = {} logging.info("Initing the tests {}, let's pop the krakens".format( cls.__name__)) cls.launch_all_krakens() instances_config_files = cls.create_dummy_json() i_manager.configuration_files = instances_config_files i_manager.initialisation() #we block the stat manager not to send anything to rabbit mq def mock_publish(self, stat): pass #we don't want to initialize rabbit for test. def mock_init(): pass StatManager.publish_request = mock_publish StatManager._init_rabbitmq = mock_init #we don't want to have anything to do with the jormun database either class bob: @classmethod def mock_get_token(cls, token, valid_until): #note, since get_from_token is a class method, we need to wrap it. #change that with a real mock framework pass User.get_from_token = bob.mock_get_token @property def mock_journey_order(self): return 'arrival_time' Instance.journey_order = mock_journey_order
def setup_class(cls): cls.tester = app.test_client() cls.krakens_pool = {} cls.uid = uuid.uuid1() logging.info("Initing the tests {}, let's pop the krakens".format( cls.__name__)) cls.global_jormun_setup() cls.launch_all_krakens() instances_config_files = cls.create_dummy_json() i_manager.configuration_files = instances_config_files i_manager.initialisation() cls.mocks = [] for name in cls.krakens_pool: priority = cls.data_sets[name].get('priority', 0) logging.info('instance %s has priority %s', name, priority) is_free = cls.data_sets[name].get('is_free', False) is_open_data = cls.data_sets[name].get('is_open_data', False) scenario = cls.data_sets[name].get('scenario', 'new_default') poi_dataset = cls.data_sets[name].get('poi_dataset', None) cls.mocks.append( mock.patch.object( i_manager.instances[name], 'get_models', return_value=FakeModel(priority, is_free, is_open_data, scenario, poi_dataset=poi_dataset), )) for m in cls.mocks: m.start() # we check that all instances are up for name in cls.krakens_pool: instance = i_manager.instances[name] try: retrying.Retrying(stop_max_delay=5000, wait_fixed=10, retry_on_result=lambda x: not instance. is_initialized).call(instance.init) except RetryError: logging.exception('impossible to start kraken {}'.format(name)) assert False, 'impossible to start a kraken' # we don't want to have anything to do with the jormun database either class bob: @classmethod def mock_get_token(cls, token, valid_until): # note, since get_from_token is a class method, we need to wrap it. # change that with a real mock framework pass User.get_from_token = bob.mock_get_token @property def mock_journey_order(self): return 'arrival_time' Instance.journey_order = mock_journey_order
def setup_class(cls): cls.krakens_pool = {} logging.info("Initing the tests {}, let's pop the krakens".format( cls.__name__)) cls.launch_all_krakens() instances_config_files = cls.create_dummy_json() i_manager.configuration_files = instances_config_files i_manager.initialisation() cls.mocks = [] for name in cls.krakens_pool: priority = cls.data_sets[name].get('priority', 0) logging.info('instance %s has priority %s', name, priority) is_free = cls.data_sets[name].get('is_free', False) cls.mocks.append( mock.patch.object(i_manager.instances[name], 'get_models', return_value=FakeModel(priority, is_free))) for m in cls.mocks: m.start() # we check that all instances are up for name in cls.krakens_pool: instance = i_manager.instances[name] try: retrying.Retrying( stop_max_delay=5000, wait_fixed=10, retry_on_result=lambda x: not instance.is_up).call( instance.init) except RetryError: logging.exception('impossible to start kraken {}'.format(name)) assert False, 'impossible to start a kraken' #we block the stat manager not to send anything to rabbit mq def mock_publish(self, stat): pass #we don't want to initialize rabbit for test. def mock_init(): pass StatManager.publish_request = mock_publish StatManager._init_rabbitmq = mock_init #we don't want to have anything to do with the jormun database either class bob: @classmethod def mock_get_token(cls, token, valid_until): #note, since get_from_token is a class method, we need to wrap it. #change that with a real mock framework pass User.get_from_token = bob.mock_get_token @property def mock_journey_order(self): return 'arrival_time' Instance.journey_order = mock_journey_order