Пример #1
0
    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)
Пример #2
0
    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
Пример #3
0
    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)
Пример #4
0
    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)
Пример #5
0
    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)
Пример #6
0
 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')
Пример #7
0
 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()
Пример #8
0
 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')
Пример #9
0
 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')
Пример #10
0
    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
Пример #11
0
    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
Пример #12
0
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)
Пример #13
0
    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)
Пример #14
0
    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
Пример #15
0
    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)
Пример #16
0
    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)
Пример #17
0
 def test_update2(self):
     Configuration.update(dict(one_option=1))
     self.assertEqual(Configuration.get('one_option'), 1)
Пример #18
0
 def test_update2(self):
     Configuration.update(dict(one_option=1))
     self.assertEqual(Configuration.get('one_option'), 1)
Пример #19
0
    def test_update_2(self):
        with pytest.raises(ConfigurationException) as e:
            Configuration.update(1)

        assert e.match('Wrong args type. Dict expected')
Пример #20
0
 def tearDown(self):
     super(TestViewPredicate, self).tearDown()
     Configuration.update(get_db_name=get_db_name)
Пример #21
0
 def tearDown(self):
     super(TestViewPredicate, self).tearDown()
     Configuration.update(get_db_name=get_db_name)
Пример #22
0
 def rollback():
     transaction.rollback()
     Configuration.update(get_db_name=get_db_name)
Пример #23
0
    def test_update_1(self):
        with pytest.raises(ConfigurationException) as e:
            Configuration.update({}, {})

        assert e.match('Too many args. Only one expected')
Пример #24
0
 def test_update2(self):
     Configuration.update(dict(one_option=1))
     assert Configuration.get('one_option') == 1
Пример #25
0
 def tearDown(self):
     super(TestRegistry, self).tearDown()
     Configuration.update(get_db_name=get_db_name)