From b9d2f72f863d30713ca18e45b96471d208e4c2aa Mon Sep 17 00:00:00 2001 From: vincenzoarcidiacono Date: Wed, 7 Aug 2024 15:31:07 +0200 Subject: [PATCH] fix(form): Correct form test cases. --- examples/length_converter/converter.ipynb | 220 ++---------------- .../static/schedula/forms/index-ui.json | 45 +--- schedula/utils/base.py | 8 +- tests/utils/test_form.py | 11 +- 4 files changed, 32 insertions(+), 252 deletions(-) diff --git a/examples/length_converter/converter.ipynb b/examples/length_converter/converter.ipynb index a3ec05f6b..c06711f0b 100644 --- a/examples/length_converter/converter.ipynb +++ b/examples/length_converter/converter.ipynb @@ -18,12 +18,12 @@ "cell_type": "code", "execution_count": 1, "metadata": {}, - "outputs": [], "source": [ "import schedula as sh\n", "from converter import converter, metric, imperial\n", "from form import form" - ] + ], + "outputs": [] }, { "cell_type": "markdown", @@ -36,28 +36,11 @@ "cell_type": "code", "execution_count": 2, "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - "\n" - ], - "text/plain": [ - "Site(SiteMap([(Metric, SiteMap())]), host='localhost', port=0, depth=-1, index=True, root_path=None)" - ] - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" - } - ], "source": [ "# Click on the graph to see the model.\n", "metric.register().plot(view=False, engine='neato', body={'style': 'filled'}).site()" - ] + ], + "outputs": [] }, { "cell_type": "markdown", @@ -70,28 +53,11 @@ "cell_type": "code", "execution_count": 3, "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - "\n" - ], - "text/plain": [ - "Site(SiteMap([(Imperial, SiteMap())]), host='localhost', port=0, depth=-1, index=True, root_path=None)" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], "source": [ "# Click on the graph to see the model.\n", "imperial.register().plot(view=False, engine='neato', body={'style': 'filled'}).site()" - ] + ], + "outputs": [] }, { "cell_type": "markdown", @@ -104,29 +70,12 @@ "cell_type": "code", "execution_count": 4, "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - "\n" - ], - "text/plain": [ - "Site(SiteMap([(LengthConverter, SiteMap())]), host='localhost', port=0, depth=-1, index=True, root_path=None)" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], "source": [ "dsp = converter.register()\n", "# Click on the graph to see the model.\n", "dsp.plot(view=False, engine='neato', body={'style': 'filled'}).site()" - ] + ], + "outputs": [] }, { "cell_type": "markdown", @@ -139,29 +88,12 @@ "cell_type": "code", "execution_count": 5, "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - "\n" - ], - "text/plain": [ - "Site(SiteMap([(LengthConverterForm, SiteMap())]), host='localhost', port=0, depth=-1, index=True, root_path=None)" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], "source": [ "form = form.register()\n", "# Click on the graph to see the model.\n", "form.plot(view=False, graph_attr={'rankdir': 'LR'}).site()" - ] + ], + "outputs": [] }, { "cell_type": "markdown", @@ -176,49 +108,21 @@ "metadata": { "scrolled": true }, - "outputs": [ - { - "data": { - "text/plain": [ - "Solution([('cm', 2.5), ('mm', 25.0), ('km', 2.5e-05)])" - ] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" - } - ], "source": [ "sol = dsp.dispatch(inputs={'cm': 2.5}, outputs=['km'])\n", "sol" - ] + ], + "outputs": [] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - "\n" - ], - "text/plain": [ - "Site(SiteMap([(LengthConverter, SiteMap())]), host='localhost', port=0, depth=-1, index=True, root_path=None)" - ] - }, - "execution_count": 10, - "metadata": {}, - "output_type": "execute_result" - } - ], "source": [ "# Click on the graph to see the model.\n", "sol.plot(view=False, body={'style': 'filled'}).site()" - ] + ], + "outputs": [] }, { "cell_type": "markdown", @@ -231,103 +135,11 @@ "cell_type": "code", "execution_count": 8, "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "\n", - "\n" - ], - "text/plain": [ - "Site(FormMap([(LengthConverterForm, FormMap())]), host='localhost', port=57318, depth=-1, index=True, root_path=None)" - ] - }, - "execution_count": 8, - "metadata": {}, - "output_type": "execute_result" - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "127.0.0.1 - - [13/Jun/2024 11:29:46] \"GET / HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:46] \"GET /static/schedula/props/js/index.js HTTP/1.1\" 404 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:46] \"GET /static/schedula/js/main.d0ca5de4.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:46] \"GET /static/schedula/css/main.13e13505.css HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:46] \"GET /static/schedula/props/js/index.js HTTP/1.1\" 404 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:47] \"GET /static/schedula/css/main.13e13505.css HTTP/1.1\" 304 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /locales/en_US/messages HTTP/1.1\" 404 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /locales/en/messages HTTP/1.1\" 404 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/forms/index-ui.json HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/forms/index-schema.json HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/3793.313eeae4.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/6562.c35d9b86.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/8568.40698121.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/3508.517796c7.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/5899.94aff875.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/474.c952ad64.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/2556.190d88d8.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/1940.a41328ce.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/7364.4924a21c.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/2931.0adcab7f.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/9894.c6e247c9.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/7049.216ec413.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/8620.8ca4d683.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/5870.6625ca31.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/1692.5ec0ad01.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/7505.521439e5.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/4692.4e2c6b7c.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/7124.7e1f21cf.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/6558.dbc62c6d.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/3581.4022e93c.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/9862.c9a0d52e.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/3070.44089e71.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/6834.399ca706.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/4424.32264c0f.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/8715.5d8dc348.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/8294.1eee2cd8.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/1748.ea52717d.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/4303.c3a825e2.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/7928.d01f28f2.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/835.48267712.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/2065.0d5474a7.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/4842.2a7e5fdf.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/8152.6127376f.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/js/5387.37f8f61e.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:48] \"GET /static/schedula/css/5387.911e2e10.chunk.css HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/js/1745.833f0cff.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/js/3281.35755d96.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/js/2506.f185d23a.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/css/1745.dba1d253.chunk.css HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/js/132.a4de6573.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/js/9558.d129bc13.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/js/1279.be357b2b.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/js/2894.f1c4622f.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/js/1678.c61f118f.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/js/7828.85a7d563.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/js/4673.ce2e8e85.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/js/1082.a90979a4.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/js/6569.6299f80c.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/css/5398.d984bdf8.chunk.css HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/js/5398.edabcec0.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/js/1362.0594020f.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/js/5349.33d4a824.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/css/1362.a0725ba9.chunk.css HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/js/9559.52882117.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/js/2846.dd67d512.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/js/2179.62b3c7e9.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/js/9486.74b2ad72.chunk.js HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/css/2696.fbac7eeb.chunk.css HTTP/1.1\" 200 -\n", - "127.0.0.1 - - [13/Jun/2024 11:29:49] \"GET /static/schedula/js/2696.2bee98cb.chunk.js HTTP/1.1\" 200 -\n" - ] - } - ], "source": [ "# Click RUN to see the output.\n", "form.form(directory='.', view=False) " - ] + ], + "outputs": [] } ], "metadata": { diff --git a/examples/length_converter/static/schedula/forms/index-ui.json b/examples/length_converter/static/schedula/forms/index-ui.json index 0441ebfc4..9eebbedb8 100644 --- a/examples/length_converter/static/schedula/forms/index-ui.json +++ b/examples/length_converter/static/schedula/forms/index-ui.json @@ -13,6 +13,7 @@ } } }, + "ui:onlyChildren": true, "ui:layout": { "component": "App", "props": { @@ -27,42 +28,6 @@ "global": { "tabEnableClose": false }, - "borders": [ - { - "type": "border", - "location": "left", - "enableDrop": false, - "size": 1200, - "selected": 0, - "children": [ - { - "type": "tab", - "enableClose": false, - "enableDrag": false, - "enableFloat": true, - "name": "Debug", - "component": 3 - } - ] - }, - { - "type": "border", - "location": "right", - "enableDrop": false, - "size": 400, - "selected": 0, - "children": [ - { - "type": "tab", - "enableClose": false, - "enableDrag": false, - "enableFloat": false, - "name": "Errors", - "component": 2 - } - ] - } - ], "layout": { "type": "row", "children": [ @@ -222,14 +187,6 @@ ] } ] - }, - { - "component": "Errors", - "force_render": true - }, - { - "component": "Debug", - "force_render": true } ] } diff --git a/schedula/utils/base.py b/schedula/utils/base.py index 4c1f30cd6..38083d813 100644 --- a/schedula/utils/base.py +++ b/schedula/utils/base.py @@ -121,7 +121,7 @@ def web(self, depth=-1, node_data=NONE, node_function=NONE, directory=None, def form(self, depth=1, node_data=NONE, node_function=NONE, directory=None, sites=None, run=True, view=True, get_context=NONE, get_data=NONE, - subsite_idle_timeout=600, basic_app_config=None, + subsite_idle_timeout=600, basic_app_config=None, debug=False, stripe_event_handler=lambda event: None): """ Creates a dispatcher Form Flask app. @@ -171,6 +171,10 @@ def form(self, depth=1, node_data=NONE, node_function=NONE, directory=None, Flask app config object. :type basic_app_config: object, optional + :param debug: + Enable debug chart backend server? + :type debug: bool, optional + :param stripe_event_handler: Stripe event handler function. :type stripe_event_handler: function, optional @@ -201,7 +205,7 @@ def form(self, depth=1, node_data=NONE, node_function=NONE, directory=None, if v is not NONE: setattr(formmap, f'_{k}', v) if sites is not None or run or view: - site = formmap.site(view=view) + site = formmap.site(view=view, debug=debug) site = run and not view and site.run() or site if sites is None: return site diff --git a/tests/utils/test_form.py b/tests/utils/test_form.py index 9e798e5a7..6f825cf0c 100755 --- a/tests/utils/test_form.py +++ b/tests/utils/test_form.py @@ -77,7 +77,7 @@ def test_form1(self): sites = set() self.dsp.form( directory=self.form_dir, run=True, sites=sites, view=False, - get_context=lambda: { + debug=True, get_context=lambda: { 'runnable': False, 'userInfo': {} }, get_data=lambda: { @@ -138,9 +138,14 @@ def _run(btn): with self.assertRaises(NoSuchElementException): _btn('debug-button', 'ant-menu-item-disabled') _clean() - if EXTRAS in ('all',): + if EXTRAS in ('form',): _run('debug-button') self.assertTrue(_btn('debug-button', 'ant-menu-item-disabled')) + WebDriverWait(driver, 30).until( + EC.element_to_be_clickable(( + By.XPATH, "//button[@class='ant-drawer-close']" + )) + ).click() _clean() @unittest.skipIf( @@ -157,6 +162,8 @@ def stripe_event_handler(event): if event['type'] == 'payment_intent.created': status[0] = True + import os + os.environ['SCHEDULA_CREDITS_ENABLED'] = 'true' self.stripe_site = sh.Dispatcher().form( directory=self.stripe_form_dir, run=False, view=False, stripe_event_handler=stripe_event_handler