def load(self): params = self.params.copy() params.update({'APPLICATION_URLS': self.urls}) settings = cms.get_settings(__file__, self.settings_file, **params) from djpsite.apps.geo import Geo from djpsite.apps.ws import WebSocketApps Geo.username = settings.GEOUSERNAME # Create the permission handler permissions = PermissionHandler(settings) permissions.auth_backends.append(SocialAuthBackend()) backend = permissions.auth_backends[0] # AUTHENTICATION MIDDLEWARE self.add_wsgi_middleware(permissions.header_authentication_middleware) self.add_wsgi_middleware(permissions.request_middleware()) self.add_response_middleware(permissions.response_middleware()) # WEB SOCKET MIDDLEWARE self.add_wsgi_middleware(ws.WebSocket(WebSocketApps('/ws/', settings))) # The root site site = cms.Site(settings, permissions=permissions) site.submit_data_middleware.add(cms.Referrer) # Add CSRF submit middleware site.submit_data_middleware.add(CSRF) # admin site settings = cms.get_settings(__file__, self.settings_file, APPLICATION_URLS=admin.make_admin_urls()) site.addsite(settings, route='/admin/') self.page_layouts(site) return site
def testAddLeaf(self): site = cms.Site() site1 = site.addsite(route='bla') self.assertFalse(site1.route.is_leaf) route = cms.Route('foo') self.assertTrue(route.is_leaf) site = self.assertRaises(ValueError, lambda: site.addsite(route=route))
def testMakeWithRoute(self): site = cms.Site(route='bla') site1 = site.addsite() self.assertNotEqual(site1.route, site1.rel_route) self.assertEqual(site1.path, '/bla/') self.assertEqual(site1.rel_route.path, '/') self.assertEqual(len(site), 1) self.assertFalse(site.isbound) self.assertRaises(cms.ImproperlyConfigured, site.load) self.assertFalse(site.isbound)
def testSearchApplication(self): from djpcms import cms from djpcms.apps import search engine = DummyEngine() app = search.Application('search/', engine=engine) self.assertTrue(app.forallsites) self.assertEqual(app.engine, engine) site = cms.Site() site.routes.append(app) self.assertFalse(site.isbound) self.assertEqual(site.search_engine, None) self.assertEqual(len(site.urls()), 1) self.assertEqual(site.search_engine, app) self.assertEqual(site.search_engine.engine, engine)
def testCreate(self): '''Simply make a site container''' site = cms.Site() self.assertEqual(site.route.rule, '') self.assertFalse(site) self.assertTrue(site.settings) self.assertEqual(site.Page, None) self.assertEqual(site.User, None) self.assertEqual(site.storage, None) self.assertEqual(site.search_engine, None) self.assertEqual(site.root, site) self.assertEqual(site.parent, None) self.assertFalse(site.isbound) self.assertRaises(cms.ImproperlyConfigured, site.urls) self.assertFalse(site.isbound)
def testSimple(self): '''Simple Tree testing''' site = cms.Site() self.assertFalse(site.isbound) self.assertEqual(site.path, '/') self.assertEqual(len(site), 0) si = [ site.addsite(route='/admin/secret/'), site.addsite(route='/admin/'), site.addsite() ] self.assertEqual(len(site), 3) sites = list(site) self.assertEqual(len(sites), 3) self.assertEqual(sites, si) self.assertFalse(site.isbound) self.assertRaises(cms.ImproperlyConfigured, site.urls) self.assertFalse(site.isbound)
def testContruction2(self): '''Construct an Application with 2 views''' view1 = views.View(renderer=lambda request: 'ciao') view2 = views.View('foo/', renderer=lambda request: 'foo') self.assertEqual(view1.appmodel,None) self.assertEqual(view2.appmodel,None) self.assertEqual(view1.path,'/') self.assertEqual(view2.path,'/foo/') app = views.Application('/', routes=(view2,view1)) self.assertEqual(view1.appmodel,None) self.assertEqual(view2.appmodel,None) self.assertFalse(app.isbound) self.assertEqual(app.parent, None) self.assertEqual(app.root, app) self.assertEqual(app.count(), 0) self.assertEqual(len(app), 0) site = cms.Site(routes=(app,)) site.load() self.assertEqual(app.count(), 2) self.assertEqual(len(app), 2) self.assertFalse(app.base_routes) # no base routes from metaclass # views get copied so instances are not the same self.assertNotEqual(app.root_view,view1) self.assertEqual(app.root_view.path,view1.path)
def testCreate2(self): '''Simply make a site container''' site = cms.Site(route='/bla/') self.assertEqual(site.route.rule, 'bla/') self.assertEqual(site.route, site.rel_route)
def load(self): settings = cms.get_settings(__file__, APPLICATION_URLS=self.urls) return cms.Site(settings)