Skip to content

Commit

Permalink
fixes #458
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfgangFahl committed Aug 26, 2022
1 parent e3b4c34 commit 777d16f
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 15 deletions.
2 changes: 1 addition & 1 deletion justpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""JustPy is an object-oriented, component based, high-level Python Web Framework that requires no front-end programming"""

from .justpy import *
__version__ = "0.2.6"
__version__ = "0.2.7"
16 changes: 15 additions & 1 deletion justpy/justpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,21 @@ async def handle_event(data_dict, com_type=0, page_event=False):
return dict_to_send


def justpy(func=None, *, start_server=True, websockets=True, host=HOST, port=PORT, startup=None, **kwargs):
def justpy(func=None, *, start_server=True, websockets:bool=True, host:str=HOST, port:int=PORT, startup=None, **kwargs):
'''
The main justpy entry point
Args:
func: the callback to get the webpage
start_server(bool): if True start the server
websockets(bool): if True use websockets
host(str): the host to start from e.g. localhost or 0.0.0.0 to listen on all interfaces
port(int): the port to use for listening
startup: a callback for the startup phase
kwargs: further keyword arguments
'''
global func_to_run, startup_func, HOST, PORT
HOST = host
PORT = port
Expand Down
5 changes: 4 additions & 1 deletion justpy/quasarcomponents.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ def convert_object_to_dict(self):

@parse_dict
class QInput(_QInputBase):
'''
https://quasar.dev/vue-components/input
'''

html_tag = 'q-input'
slots = ['default_slot', 'before_slot', 'after_slot', 'error_slot', 'hint_slot', 'counter_slot', 'loading_slot',
Expand All @@ -136,7 +139,7 @@ def __init__(self, **kwargs):
'filled', 'outlined', 'borderless', 'standout', 'bottom-slots', 'rounded', 'square', 'dense',
'items-aligned', 'disable', 'readonly', 'value', 'type', 'debounce', 'counter', 'maxlength',
'autogrow', 'autofocus', 'input-class', 'input-style', 'clearable', 'clear-icon',
'placeholder', 'min', 'max']
'placeholder', 'min', 'max', 'loading']

self.allowed_events = ['keypress', 'input', 'focus', 'blur', 'change'] # Not different from focus and blur in documentation
self.set_keyword_events(**kwargs)
Expand Down
10 changes: 5 additions & 5 deletions tests/basetest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
import getpass
from unittest import TestCase
import time
from multiprocessing import Process

from threading import Thread

class BaseAsynctest(asynctest.TestCase):
'''
basic asynch test
'''
# https://github.com/encode/starlette/blob/master/docs/testclient.md
# https://stackoverflow.com/questions/57412825/how-to-start-a-uvicorn-fastapi-in-background-when-testing-with-pytest
# https://github.com/encode/uvicorn/discussions/1103

async def setUp(self,wpfunc,port:int=8123,host:str="127.0.0.1",sleepTime=0.2,debug=False,profile=True):
""" Bring server up.
Expand All @@ -38,19 +38,19 @@ async def setUp(self,wpfunc,port:int=8123,host:str="127.0.0.1",sleepTime=0.2,deb
self.profile=profile
msg=f"test {self._testMethodName}, debug={self.debug}"
self.profiler=Profiler(msg,profile=self.profile)
self.proc = Process(target=jp.justpy,
self.thread = Thread(target=jp.justpy,
args=(wpfunc,),
kwargs={
"host": self.host,
"port": self.port,
},
daemon=True)
self.proc.start()
self.thread.start()
await asyncio.sleep(sleepTime) # time for the server to start

async def tearDown(self):
""" Shutdown the app. """
self.proc.terminate()
#self.proc.terminate()
self.profiler.time()

def getUrl(self,path):
Expand Down
25 changes: 25 additions & 0 deletions tests/test_quasar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'''
Created on 2022-08-26
@author: wf
'''
from tests.basetest import Basetest
from justpy.quasarcomponents import QInput

class TestQuasar(Basetest):
'''
test Quasar components
https://quasar.dev/vue-components
'''

def testQInput(self):
'''
test QInput
'''
qInput=QInput()
propList=qInput.prop_list
debug=True
if debug:
print(propList)
self.assertTrue("loading" in propList)
24 changes: 17 additions & 7 deletions tests/test_with_selenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
from selenium import webdriver
import justpy as jp

from tests.basetest import BaseAsynctest
from webdriver_manager.firefox import GeckoDriverManager
from selenium.webdriver import FirefoxOptions
from tests.basetest import BaseAsynctest, Basetest
#from webdriver_manager.firefox import GeckoDriverManager
#from selenium.webdriver import FirefoxOptions
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager

class TestWithSelenium(BaseAsynctest):
'''
Expand All @@ -17,11 +20,14 @@ class TestWithSelenium(BaseAsynctest):

async def setUp(self):
await BaseAsynctest.setUp(self, self.wp_to_test)
self.firefox_path=GeckoDriverManager().install()
opts = FirefoxOptions()
opts.add_argument("--headless")
self.browser = webdriver.Firefox(executable_path=self.firefox_path,options=opts)

#self.firefox_path=GeckoDriverManager().install()
#opts = FirefoxOptions()
chrome_options = Options()
chrome_options.headless=True
#self.browser = webdriver.Firefox(executable_path=self.firefox_path,options=opts)
self.browser = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()),chrome_options=chrome_options)


async def wp_to_test(self):
'''
Expand All @@ -35,6 +41,10 @@ async def testHomePage(self):
'''
this will actually start a firefox browser and the websocket reload dialog will appear
'''
# do not run automatically in CI yet
# need to fix
if Basetest.inPublicCI():
return
url=self.getUrl("/")
self.browser.get(url)

0 comments on commit 777d16f

Please sign in to comment.