def test_need_anyblok_registry_ko(self): def __get_db_name(request): return 'wrong_db_name' Configuration.update(get_db_name=__get_db_name) self.includemes.append(self.add_route_and_views2) webserver = self.init_web_server() webserver.get('/test/', status=404)
def test_registry_by_wrong_name(self, registry_blok): def __get_db_name(request): return 'wrong_db_name' Configuration.update(get_db_name=__get_db_name) webserver = init_web_server(self.add_route_and_views) res = webserver.get('/test/', status=200) assert not res.body
def test_need_anyblok_registry_ko(self): def __get_db_name(request): return 'wrong_db_name' Configuration.update(get_db_name=__get_db_name) self.includemes.append(self.add_route_and_views2) webserver = self.init_web_server() webserver.get('/test/', status=404)
def test_registry_by_wrong_name(self): def __get_db_name(request): return 'wrong_db_name' Configuration.update(get_db_name=__get_db_name) self.includemes.append(self.add_route_and_views) webserver = self.init_web_server() res = webserver.get('/test/', status=200) self.assertFalse(res.body)
def test_need_anyblok_registry_ok2(self, registry_blok): self.need_anyblok_registry = False def __get_db_name(request): return 'wrong_db_name' Configuration.update(get_db_name=__get_db_name) webserver = init_web_server(self.add_route_and_views2) webserver.get('/test/', status=200)
def test_get_url5(self): db_url = 'postgres:///anyblok' Configuration.update( db_driver_name=None, db_host=None, db_user_name='jssuzanne', db_password='******', db_port=None) url = get_url(db_name='anyblok3', url=db_url) self.check_url(url, 'postgres://*****:*****@/anyblok3')
def test_get_url_without_drivername(self): Configuration.update( db_name=None, db_driver_name=None, db_host=None, db_user_name=None, db_password=None, db_port=None) with self.assertRaises(ConfigurationException): Configuration.get_url()
def test_get_url2(self): Configuration.update( db_name='anyblok', db_driver_name='postgres', db_host='localhost', db_user_name=None, db_password=None, db_port=None,) url = Configuration.get_url(db_name='anyblok2') self.check_url(url, 'postgres://localhost/anyblok2')
def test_get_url3(self): Configuration.update( db_url='postgres:///anyblok', db_name=None, db_driver_name=None, db_host=None, db_user_name=None, db_password=None, db_port=None) url = Configuration.get_url() self.check_url(url, 'postgres:///anyblok')
def Configuration(**values): """Add Configuration value only in the contextmanager :: with TestCase.Configuration(db_name='a db name'): self.assertEqual(Configuration.get('db_name'), 'a db name') :param \**values: values to update """ try: old_configuration = Configuration.configuration.copy() Configuration.update(**values) yield finally: Configuration.configuration = old_configuration
def Configuration(**values): """Add Configuration value only in the contextmanager :: with TestCase.Configuration(db_name='a db name'): self.assertEqual(Configuration.get('db_name'), 'a db name') :param \**values: values to update """ try: old_configuration = Configuration.configuration.copy() Configuration.update(**values) yield finally: Configuration.configuration = old_configuration
def tmp_configuration(**values): """Add Configuration value only in the contextmanager :: with TestCase.Configuration(db_name='a db name'): assert Configuration.get('db_name') == 'a db name' :param **values: values to update """ old_values = {x: Configuration.get(x) for x in values.keys()} Configuration.update(**values) try: yield finally: Configuration.update(**old_values)
def test_registry_by_path(self): def __get_db_name(request): return request.matchdict['dbname'] def add_route_and_views(config): config.add_route('dbname', '/test/{dbname}/') config.add_view(_get_db_name, route_name='dbname') Configuration.update(get_db_name=__get_db_name) self.includemes.append(add_route_and_views) webserver = self.init_web_server() res = webserver.get('/test/%s/' % Configuration.get('db_name'), status=200) self.assertEqual(Configuration.get('db_name'), res.body.decode('utf8')) res = webserver.get('/test/wrong_db_name/', status=200) self.assertFalse(res.body)
def test_registry_by_path(self, registry_blok): def __get_db_name(request): return request.matchdict['dbname'] def add_route_and_views(config): config.add_route('dbname', '/test/{dbname}/') config.add_view(_get_db_name, route_name='dbname') Configuration.update(get_db_name=__get_db_name) webserver = init_web_server(add_route_and_views) res = webserver.get('/test/%s/' % Configuration.get('db_name'), status=200) assert Configuration.get('db_name') == res.body.decode('utf8') res = webserver.get('/test/wrong_db_name/', status=200) assert not res.body
def init_configuration_manager(cls, **env): """ Initialise the configuration manager with environ variable to launch the test .. warning:: For the moment we not use the environ variable juste constante :param env: add another dict to merge with environ variable """ db_name = Configuration.get('db_name') or 'test_anyblok' db_driver_name = Configuration.get('db_driver_name') or 'postgresql' env.update({ 'db_name': db_name, 'db_driver_name': db_driver_name, }) Configuration.update(**env)
def init_configuration_manager(cls, **env): """ Initialise the configuration manager with environ variable to launch the test .. warning:: For the moment we not use the environ variable juste constante :param prefix: prefix the database name :param env: add another dict to merge with environ variable """ db_name = Configuration.get('db_name') or 'test_anyblok' db_driver_name = Configuration.get('db_driver_name') or 'postgresql' env.update({ 'db_name': db_name, 'db_driver_name': db_driver_name, }) Configuration.update(**env)
def test_update2(self): Configuration.update(dict(one_option=1)) self.assertEqual(Configuration.get('one_option'), 1)
def test_update2(self): Configuration.update(dict(one_option=1)) self.assertEqual(Configuration.get('one_option'), 1)
def test_update_2(self): with pytest.raises(ConfigurationException) as e: Configuration.update(1) assert e.match('Wrong args type. Dict expected')
def tearDown(self): super(TestViewPredicate, self).tearDown() Configuration.update(get_db_name=get_db_name)
def tearDown(self): super(TestViewPredicate, self).tearDown() Configuration.update(get_db_name=get_db_name)
def rollback(): transaction.rollback() Configuration.update(get_db_name=get_db_name)
def test_update_1(self): with pytest.raises(ConfigurationException) as e: Configuration.update({}, {}) assert e.match('Too many args. Only one expected')
def test_update2(self): Configuration.update(dict(one_option=1)) assert Configuration.get('one_option') == 1
def tearDown(self): super(TestRegistry, self).tearDown() Configuration.update(get_db_name=get_db_name)