fix: allow config injection for sake of tests
per changes in wuttaweb, sideshow
This commit is contained in:
		
							parent
							
								
									198c3f77bb
								
							
						
					
					
						commit
						bad6ded72d
					
				
					 4 changed files with 45 additions and 14 deletions
				
			
		| 
						 | 
					@ -33,7 +33,7 @@ classifiers = [
 | 
				
			||||||
license = {text = "GNU General Public License v3+"}
 | 
					license = {text = "GNU General Public License v3+"}
 | 
				
			||||||
requires-python = ">= 3.8"
 | 
					requires-python = ">= 3.8"
 | 
				
			||||||
dependencies = [
 | 
					dependencies = [
 | 
				
			||||||
        "Sideshow>=0.6.0",
 | 
					        "Sideshow>=0.7.1",
 | 
				
			||||||
        "Wutta-COREPOS[web]>=0.3.0",
 | 
					        "Wutta-COREPOS[web]>=0.3.0",
 | 
				
			||||||
]
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -44,7 +44,8 @@ def main(global_config, **settings):
 | 
				
			||||||
    pyramid_config = base.make_pyramid_config(settings)
 | 
					    pyramid_config = base.make_pyramid_config(settings)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # configure DB sessions
 | 
					    # configure DB sessions
 | 
				
			||||||
    CoreOpSession.configure(bind=wutta_config.core_office_op_engine)
 | 
					    if hasattr(wutta_config, 'core_office_op_engine'):
 | 
				
			||||||
 | 
					        CoreOpSession.configure(bind=wutta_config.core_office_op_engine)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # bring in the rest of Sideshow
 | 
					    # bring in the rest of Sideshow
 | 
				
			||||||
    pyramid_config.include('sideshow.web')
 | 
					    pyramid_config.include('sideshow.web')
 | 
				
			||||||
| 
						 | 
					@ -53,15 +54,15 @@ def main(global_config, **settings):
 | 
				
			||||||
    return pyramid_config.make_wsgi_app()
 | 
					    return pyramid_config.make_wsgi_app()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def make_wsgi_app():
 | 
					def make_wsgi_app(config=None):
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    Make and return the WSGI app (generic entry point).
 | 
					    Make and return the WSGI app (generic entry point).
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    return base.make_wsgi_app(main)
 | 
					    return base.make_wsgi_app(main, config=config)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def make_asgi_app():
 | 
					def make_asgi_app(config=None):
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    Make and return the ASGI app (generic entry point).
 | 
					    Make and return the ASGI app (generic entry point).
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    return base.make_asgi_app(main)
 | 
					    return base.make_asgi_app(main, config=config)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										18
									
								
								tests/test_config.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								tests/test_config.py
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,18 @@
 | 
				
			||||||
 | 
					# -*- coding: utf-8; -*-
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from wuttjamaican.testing import ConfigTestCase
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from sideshow_corepos import config as mod
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class TestSideshowCoreposConfig(ConfigTestCase):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_basic(self):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        self.assertIsNone(self.config.get('wutta.batch.neworder.handler.spec'))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        ext = mod.SideshowCoreposConfig()
 | 
				
			||||||
 | 
					        ext.configure(self.config)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        self.assertEqual(self.config.get('wutta.batch.neworder.handler.spec'),
 | 
				
			||||||
 | 
					                         'sideshow_corepos.batch.neworder:NewOrderBatchHandler')
 | 
				
			||||||
| 
						 | 
					@ -1,32 +1,44 @@
 | 
				
			||||||
# -*- coding: utf-8; -*-
 | 
					# -*- coding: utf-8; -*-
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from wuttjamaican.testing import FileTestCase, ConfigTestCase
 | 
					import sqlalchemy as sa
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from wuttjamaican.testing import DataTestCase
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from asgiref.wsgi import WsgiToAsgi
 | 
					from asgiref.wsgi import WsgiToAsgi
 | 
				
			||||||
from pyramid.router import Router
 | 
					from pyramid.router import Router
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from wutta_corepos.web.db import CoreOpSession
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from sideshow_corepos.web import app as mod
 | 
					from sideshow_corepos.web import app as mod
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestMain(FileTestCase):
 | 
					class TestMain(DataTestCase):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_basic(self):
 | 
					    def test_basic(self):
 | 
				
			||||||
        global_config = None
 | 
					        global_config = None
 | 
				
			||||||
        myconf = self.write_file('my.conf', '')
 | 
					        settings = {'wutta_config': self.config}
 | 
				
			||||||
        settings = {'wutta.config': myconf}
 | 
					 | 
				
			||||||
        app = mod.main(global_config, **settings)
 | 
					        app = mod.main(global_config, **settings)
 | 
				
			||||||
        self.assertIsInstance(app, Router)
 | 
					        self.assertIsInstance(app, Router)
 | 
				
			||||||
 | 
					        self.assertIsNone(CoreOpSession.session_factory.kw['bind'])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_corepos_engine(self):
 | 
				
			||||||
 | 
					        engine = sa.create_engine('sqlite://')
 | 
				
			||||||
 | 
					        self.config.core_office_op_engine = engine
 | 
				
			||||||
 | 
					        settings = {'wutta_config': self.config}
 | 
				
			||||||
 | 
					        app = mod.main(None, **settings)
 | 
				
			||||||
 | 
					        self.assertIsInstance(app, Router)
 | 
				
			||||||
 | 
					        self.assertIs(CoreOpSession.session_factory.kw['bind'], engine)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestMakeWsgiApp(ConfigTestCase):
 | 
					class TestMakeWsgiApp(DataTestCase):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_basic(self):
 | 
					    def test_basic(self):
 | 
				
			||||||
        wsgi = mod.make_wsgi_app()
 | 
					        wsgi = mod.make_wsgi_app(config=self.config)
 | 
				
			||||||
        self.assertIsInstance(wsgi, Router)
 | 
					        self.assertIsInstance(wsgi, Router)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestMakeAsgiApp(ConfigTestCase):
 | 
					class TestMakeAsgiApp(DataTestCase):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_basic(self):
 | 
					    def test_basic(self):
 | 
				
			||||||
        asgi = mod.make_asgi_app()
 | 
					        asgi = mod.make_asgi_app(config=self.config)
 | 
				
			||||||
        self.assertIsInstance(asgi, WsgiToAsgi)
 | 
					        self.assertIsInstance(asgi, WsgiToAsgi)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue