def setUp(self):
        self.old_public_val = app.config['PUBLIC']
        app.config['PUBLIC'] = False
        self.app = app.test_client()

        self.old_instance_getter = models.Instance.get_by_name
        models.Instance.get_by_name = FakeInstance.get_by_name
示例#2
0
    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
示例#3
0
 def __init__(self, *args, **kwargs):
     self.tester = app.test_client()