Exemple #1
0
    def test_config_format_ini_commas(self):
        from pyramid.renderers import null_renderer as nr
        from pyramid.config import not_

        def view1(context, request): return 'view1'

        config = self._makeConfig(autocommit=True)
        config.add_route('foo', '/a/b')
        config.add_view(
            route_name='foo',
            view=view1,
            renderer=nr,
            request_method=not_('POST')
        )

        command = self._makeOne()

        L = []
        command.out = L.append
        command.bootstrap = dummy.DummyBootstrap(registry=config.registry)
        command.get_config_loader = dummy.DummyLoader(
            {'proutes': {'format': 'method,name'}})

        result = command.run()
        self.assertEqual(result, 0)
        self.assertEqual(len(L), 3)
        compare_to = L[-1].split()
        expected = ['!POST,*', 'foo']

        self.assertEqual(compare_to, expected)
        self.assertEqual(L[0].split(), ['Method', 'Name'])
Exemple #2
0
    def _makeOne(self):
        cmd = self._getTargetClass()([])
        cmd.bootstrap = dummy.DummyBootstrap()
        cmd.get_config_loader = dummy.DummyLoader()
        cmd.args.config_uri = '/foo/bar/myapp.ini#myapp'

        return cmd
Exemple #3
0
 def _makeOne(self, *args):
     effargs = ['pserve']
     effargs.extend(args)
     cmd = self._getTargetClass()(effargs)
     cmd.out = self.out
     self.loader = dummy.DummyLoader()
     cmd._get_config_loader = self.loader
     return cmd
Exemple #4
0
    def test_bad_args(self):
        cmd = self._getTargetClass()([])
        cmd.bootstrap = dummy.DummyBootstrap()
        cmd.get_config_loader = dummy.DummyLoader()
        cmd.args.config_uri = '/foo/bar/myapp.ini#myapp'
        cmd.args.config_vars = ('a',)
        route = dummy.DummyRoute('a', '/a')
        mapper = dummy.DummyMapper(route)
        cmd._get_mapper = lambda *arg: mapper

        self.assertRaises(ValueError, cmd.run)
Exemple #5
0
    def _makeOne(self, argv, headers=None):
        cmd = self._getTargetClass()(argv)

        def helloworld(environ, start_request):
            self._environ = environ
            self._path_info = environ['PATH_INFO']
            start_request('200 OK', headers or [])
            return [b'abc']
        self.loader = dummy.DummyLoader(app=helloworld)
        self._out = []
        cmd._get_config_loader = self.loader
        cmd.out = self.out
        return cmd
Exemple #6
0
 def test_good_args(self):
     cmd = self._getTargetClass()([])
     cmd.bootstrap = dummy.DummyBootstrap()
     cmd.get_config_loader = dummy.DummyLoader()
     cmd.args.config_uri = '/foo/bar/myapp.ini#myapp'
     cmd.args.config_args = ('a=1',)
     route = dummy.DummyRoute('a', '/a')
     mapper = dummy.DummyMapper(route)
     cmd._get_mapper = lambda *arg: mapper
     registry = self._makeRegistry()
     cmd.bootstrap = dummy.DummyBootstrap(registry=registry)
     L = []
     cmd.out = lambda msg: L.append(msg)
     cmd.run()
     self.assertTrue('<unknown>' in ''.join(L))
Exemple #7
0
    def _makeOne(self,
                 patch_bootstrap=True,
                 patch_loader=True,
                 patch_args=True,
                 patch_options=True):
        cmd = self._getTargetClass()([])

        if patch_bootstrap:
            self.bootstrap = dummy.DummyBootstrap()
            cmd.bootstrap = self.bootstrap
        if patch_loader:
            self.loader = dummy.DummyLoader()
            cmd.get_config_loader = self.loader
        if patch_args:

            class Args(object):
                pass

            self.args = Args()
            self.args.config_uri = '/foo/bar/myapp.ini#myapp'
            cmd.args.config_uri = self.args.config_uri
        if patch_options:

            class Options(object):
                pass

            self.options = Options()
            self.options.python_shell = ''
            self.options.setup = None
            self.options.list = None
            cmd.options = self.options

        # default to None to prevent side-effects from running tests in
        # unknown environments
        cmd.pystartup = None
        return cmd