Skip to content

Commit

Permalink
updates ngwidgets for proper test stop
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfgangFahl committed Nov 4, 2023
1 parent 5fc9b4f commit a05de2b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 49 deletions.
2 changes: 1 addition & 1 deletion frontend/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def enableFrontend(self,siteName:str,appWrap=None,debug:bool=False):
if self.frontendConfigs is None:
raise Exception('No frontend configurations loaded yet')
if siteName not in self.siteLookup:
raise Exception('frontend for site %s not configured yet' % siteName)
raise Exception(f'frontend for site {siteName} not configured yet')
frontend = Frontend(siteName)
self.frontends[siteName]=frontend
config=self.siteLookup[siteName]
Expand Down
32 changes: 4 additions & 28 deletions frontend/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
@author: wf
'''
#import jinja2
import os
import sys

class Site(object):
'''
Expand Down Expand Up @@ -37,38 +34,17 @@ def configure(self,config:dict):
'''
self.wikiId=config['wikiId']
self.defaultPage=config['defaultPage']
self.template=config['template']
if "packageName" in config:
self.packageName=config["packageName"]
else:
self.packageName=self.name
if "packageFolder" in config:
self.packageFolder=config["packageFolder"]
else:
self.packageFolder=self.name
self.configured=True

def open(self,appWrap=None):
def open(self,ws=None):
'''
open this site
Args:
appWrap(appWrap): optional fb4 Application Wrapper
ws: Nicegui Webserver
'''
if not self.configured:
raise Exception("need to configure site before opening it")
# https://stackoverflow.com/a/14276993/1497139
# http://code.nabla.net/doc/jinja2/api/jinja2/loaders/jinja2.loaders.PackageLoader.html
if self.debug:
print("adding %s to PYTHON PATH" % self.packageFolder)
sys.path.insert(1,self.packageFolder)
if appWrap is not None:
templatePath="%s/%s/templates" % (self.packageFolder,self.packageName)
if os.path.isdir(templatePath):
appWrap.addTemplatePath(templatePath)
# TODO: use a more elaborate loader concept if need be
# self.templateEnv = jinja2.Environment( loader=jinja2.PackageLoader(self.packageName))

pass
raise Exception("need to configure site before opening it")
self.ws=ws


2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ readme = "README.md"
license = {text = "Apache-2.0"}
dependencies = [
# https://github.com/WolfgangFahl/nicegui_widgets
"ngwidgets>=0.2.8",
"ngwidgets>=0.3.0",
# https://pypi.org/project/pylodstorage/
"pyLodStorage>=0.4.7",
# https://pypi.org/project/SQLAlchemy/
Expand Down
26 changes: 7 additions & 19 deletions tests/test_webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,23 @@
'''
import warnings
from frontend.server import Server
from frontend.webserver import WebServer
from frontend.webserver import CmsWebServer
from tests.test_wikicms import TestWikiCMS
import tempfile
from ngwidgets.webserver_test import WebserverTest
from frontend.cmsmain import WebserverCmd
from frontend.cmsmain import CmsMain

class TestWebServer(WebserverTest):
"""
test the pyWikiCms Server
"""

def setUp(self,debug=False, profile=True):
server_class=WebServer
cmd_class=WebserverCmd
server_class=CmsWebServer
cmd_class=CmsMain
WebserverTest.setUp(self, server_class, cmd_class, debug=debug, profile=profile)
self.server=TestWebServer.initServer()
# make sure tests run in travis
sites=['or','cr','sharks','www']
sites=['cr','sharks','www']
self.ws.enableSites(sites)
pass

Expand All @@ -36,32 +35,20 @@ def initServer():
server=Server()
server.logo="https://upload.wikimedia.org/wikipedia/commons/thumb/6/65/Desmond_Llewelyn_01.jpg/330px-Desmond_Llewelyn_01.jpg"
server.frontendConfigs=[
{
'site':'or',
'wikiId':'orclone',
'template':'bootstrap.html',
'defaultPage':'Frontend'
},
{
'site': 'cr',
'wikiId':'cr',
'template':'bootstrap.html',
'defaultPage':'Main Page'
},
{
'site': 'sharks',
'wikiId':'wiki',
'template':'bootstrap.html',
'defaultPage':'Sharks'
},
{
'site': 'www',
'wikiId':'wiki',
'template':'design.html',
'defaultPage':'Welcome',
'packageFolder': '%s/www.wikicms' % tempfile.gettempdir(),
'packageName': 'bitplan_webfrontend',
'templateFolder': 'templates'
}
]
for frontendConfigs in server.frontendConfigs:
Expand Down Expand Up @@ -91,7 +78,7 @@ def test_extract_site_and_path(self):

for index, test_path in enumerate(paths):
# Extract site and path using the Webserver method.
site, path = WebServer.extract_site_and_path(test_path)
site, path = CmsWebServer.extract_site_and_path(test_path)

# If debugging is enabled, print the results.
if getattr(self, 'debug', False):
Expand All @@ -103,6 +90,7 @@ def test_extract_site_and_path(self):
# Assert that the results match the expectations.
self.assertEqual(expected_site, site)
self.assertEqual(expected_path, path)

def testWebServer(self):
'''
test the WebServer
Expand Down

0 comments on commit a05de2b

Please sign in to comment.