コード例 #1
0
    def test_registration_noapp(self):
        Registry(app=self.app)

        self.app.extensions['registry']['myns'] = ModuleDiscoveryRegistry(
            'notimportant', )

        self.assertRaises(RegistryError,
                          self.app.extensions['registry']['myns'].discover)
コード例 #2
0
    def test_missing_module(self):
        Registry(app=self.app)

        self.app.extensions['registry'].update(
            pathns=ImportPathRegistry(initial=['flask_registry.*']),
            myns=ModuleDiscoveryRegistry('some_non_existing_module',
                                         registry_namespace='pathns'))

        with self.app.app_context():
            self.app.extensions['registry']['myns'].discover()
            assert len(self.app.extensions['registry']['myns']) == 0
コード例 #3
0
    def test_broken_module(self):
        Registry(app=self.app)

        self.app.extensions['registry'].update(
            pathns=ImportPathRegistry(initial=['tests']),
            myns=ModuleDiscoveryRegistry('broken_module',
                                         registry_namespace='pathns'))

        with self.app.app_context():
            self.assertRaises(ImportError,
                              self.app.extensions['registry']['myns'].discover)
            assert len(self.app.extensions['registry']['myns']) == 0
コード例 #4
0
    def test_syntaxerror_module(self):
        Registry(app=self.app)

        self.app.extensions['registry'].update(
            pathns=ImportPathRegistry(initial=['tests']),
            myns=ModuleDiscoveryRegistry('syntaxerror_module',
                                         registry_namespace='pathns'))

        with self.app.app_context():
            self.assertRaises(SyntaxError,
                              self.app.extensions['registry']['myns'].discover)
            assert len(self.app.extensions['registry']['myns']) == 0

        # Silence the error
        self.app.extensions['registry']['myns_silent'] = \
            ModuleDiscoveryRegistry('syntaxerror_module',
                                    registry_namespace='pathns',
                                    silent=True)

        with self.app.app_context():
            self.app.extensions['registry']['myns_silent'].discover()
            assert len(self.app.extensions['registry']['myns_silent']) == 0
コード例 #5
0
    def test_modules_namespace(self):
        from flask_registry import registries
        Registry(app=self.app)

        self.app.extensions['registry']['pathns'] = ModuleRegistry()
        self.app.extensions['registry']['pathns'].register(registries)

        self.app.extensions['registry']['myns'] = \
            ModuleDiscoveryRegistry('appdiscovery',
                                    registry_namespace='pathns')

        with self.app.app_context():
            self.app.extensions['registry']['myns'].discover()
            assert len(self.app.extensions['registry']['myns']) == 1
            from flask_registry.registries import appdiscovery
            assert self.app.extensions['registry']['myns'][0] == appdiscovery
コード例 #6
0
    def test_exclude(self):
        Registry(app=self.app)

        # Set exclude config
        self.app.config['PATH_NS_APPDISCOVERY_EXCLUDE'] = [
            'flask_registry.registries',
        ]

        self.app.extensions['registry'].update({
            'path.ns':
            ImportPathRegistry(initial=['flask_registry.*']),
            'myns':
            ModuleDiscoveryRegistry('appdiscovery',
                                    registry_namespace='path.ns')
        })

        with self.app.app_context():
            self.app.extensions['registry']['myns'].discover()
            assert len(self.app.extensions['registry']['myns']) == 0
コード例 #7
0
    def test_registration(self):
        Registry(app=self.app)

        self.app.extensions['registry'].update(pathns=ImportPathRegistry(
            initial=['flask_registry.*']))

        self.assertEquals(3, len(self.app.extensions['registry']['pathns']))

        self.app.extensions['registry']['myns'] = \
            ModuleDiscoveryRegistry(
                'appdiscovery',
                registry_namespace='pathns')

        with self.app.app_context():
            self.app.extensions['registry']['myns'].discover()
            assert len(self.app.extensions['registry']['myns']) == 1
            from flask_registry.registries import appdiscovery
            assert self.app.extensions['registry']['myns'][0] == appdiscovery

        self.app.extensions['registry']['myns'].discover(app=self.app)
コード例 #8
0
    def test_proxy_ns(self):
        Registry(app=self.app)

        proxy = RegistryProxy('pathns',
                              ImportPathRegistry,
                              initial=['flask_registry.*'])

        with self.app.app_context():
            assert 'pathns' not in self.app.extensions['registry']

            self.app.extensions['registry']['myns'] = \
                ModuleDiscoveryRegistry('appdiscovery',
                                        registry_namespace=proxy)

            assert 'pathns' in self.app.extensions['registry']
            self.assertEqual(3, len(self.app.extensions['registry']['pathns']))

            self.app.extensions['registry']['myns'].discover()

            assert len(self.app.extensions['registry']['myns']) == 1
            from flask_registry.registries import appdiscovery
            assert self.app.extensions['registry']['myns'][0] == appdiscovery