Browse Source

flask initial test - without new functionality

refactor
Ulrich 1 year ago
parent
commit
e9a4a587c5
  1. 1
      basic/program.py
  2. 49
      basic/user.py
  3. 40
      webflask/__init__.py
  4. 20
      webflask/auth.py
  5. 3
      webflask/datest.py
  6. 8
      webflask/index.py
  7. 9
      webflask/templates/base.html
  8. 0
      webflask/templates/selection.html
  9. 5
      webflask/templates/testcase/selection.html
  10. 3
      webflask/testcase.py

1
basic/program.py

@ -24,7 +24,6 @@ import tools.date_tool
import tools.path_tool import tools.path_tool
import tools.file_tool import tools.file_tool
import tools.config_tool import tools.config_tool
import test.constants as T
import tools.path_const as P import tools.path_const as P
import tools.job_tool import tools.job_tool

49
basic/user.py

@ -1,49 +0,0 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------------------------------------
# Author : Ulrich Carmesin
# Source : gitea.ucarmesin.de
# ---------------------------------------------------------------------------------------------------------
import basic.toolHandling
import utils.data_const as D
import basic.constants as B
import model.entity
ddl = {
"user": {
"id": {
D.DDL_TYPE: D.TYPE_PK,
},
"username": {
D.DDL_TYPE: D.TYPE_STR,
},
"password": {
D.DDL_TYPE: D.TYPE_STRING,
}
}
}
class User(model.entity.Entity):
username = ""
password = ""
def __init__(self, job):
"""
to be initialized by readSpec
:param job:
"""
self.job = job
self.conf = {}
self.conf[B.TOPIC_CONN] = self.getDbAttr(job)
self.conf[B.DATA_NODE_DDL] = self.getDdl(job, ddl)
self.m = job.m
def get_schema(self):
dbtype = self.job.conf[B.TOPIC_NODE_DB][B.ATTR_TYPE]
dbi = basic.toolHandling.getDbTool(self.job, None, dbtype)
sql = dbi.getCreateTable("user")
sql += dbi.getSchemaAttribut("id", "id")+","
sql += dbi.getSchemaAttribut("username", D.TYPE_STR)+","
sql += dbi.getSchemaAttribut("password", D.TYPE_STR)
sql += ");\n"
return sql

40
webflask/__init__.py

@ -1,4 +1,5 @@
import os import os
from flask import Flask from flask import Flask
@ -7,7 +8,7 @@ def create_app(test_config=None):
app = Flask(__name__, instance_relative_config=True) app = Flask(__name__, instance_relative_config=True)
app.config.from_mapping( app.config.from_mapping(
SECRET_KEY='dev', SECRET_KEY='dev',
DATABASE=os.path.join(app.instance_path, 'flaskr.sqlite'), DATABASE=os.path.join(app.instance_path, 'webflask.sqlite'),
) )
if test_config is None: if test_config is None:
@ -23,35 +24,22 @@ def create_app(test_config=None):
except OSError: except OSError:
pass pass
from . import db # a simple page that says hello
db.init_app(app) @app.route('/hello')
from . import auth def hello():
return 'Hello, World from __init__!'
from . import index from . import index
from . import testcase
from . import testsuite
from . import components
from . import reports
from . import environment
app.register_blueprint(auth.bp)
app.register_blueprint(index.bp) app.register_blueprint(index.bp)
from . import auth
app.register_blueprint(auth.bp)
from . import testcase
app.register_blueprint(testcase.bp) app.register_blueprint(testcase.bp)
from . import testsuite
app.register_blueprint(testsuite.bp) app.register_blueprint(testsuite.bp)
from . import components
app.register_blueprint(components.bp) app.register_blueprint(components.bp)
from . import reports
app.register_blueprint(reports.bp) app.register_blueprint(reports.bp)
app.register_blueprint(environment.bp)
# a simple page that says hello
@app.route('/hello')
def hello():
return 'Hello, World!'
return app
@app.route('/')
def index():
return 'Index Page'
@app.route('/index')
def index():
return 'Index Page 2'
return app

20
webflask/auth.py

@ -2,17 +2,15 @@
# -------------------------------------------------------------- # --------------------------------------------------------------
import functools import functools
import traceback import traceback
import basic.user import os
import basic.program
import basic.constants as B
import basic.toolHandling
from flask import ( from flask import (
Blueprint, flash, g, redirect, render_template, request, session, url_for Blueprint, flash, g, redirect, render_template, request, session, url_for
) )
from werkzeug.security import check_password_hash, generate_password_hash from werkzeug.security import check_password_hash, generate_password_hash
import basic.program import basic.program
import basic.constants as B
import basic.toolHandling
import model.user
from webflask.db import get_db from webflask.db import get_db
bp = Blueprint('auth', __name__, url_prefix='/auth') bp = Blueprint('auth', __name__, url_prefix='/auth')
@ -24,8 +22,8 @@ def login():
password = request.form['password'] password = request.form['password']
job = basic.program.Job("webflask", {}) job = basic.program.Job("webflask", {})
session['datest_job'] = job session['datest_job'] = job
dbtype = job.conf.confs[B.TOPIC_NODE_DB][B.ATTR_TYPE] dbtype = job.conf[B.TOPIC_NODE_DB][B.ATTR_TYPE]
userentity = basic.user.User(job) userentity = model.user.User()
dbi = basic.toolHandling.getDbTool(job, userentity, dbtype) dbi = basic.toolHandling.getDbTool(job, userentity, dbtype)
error = None error = None
row = dbi.selectRows("user", job, "WHERE username = \'" + username + "\'") row = dbi.selectRows("user", job, "WHERE username = \'" + username + "\'")
@ -51,7 +49,7 @@ def register():
username = request.form['username'] username = request.form['username']
password = request.form['password'] password = request.form['password']
job = basic.program.Job("webflask", {}) job = basic.program.Job("webflask", {})
dbtype = job.conf.confs[B.TOPIC_NODE_DB][B.ATTR_TYPE] dbtype = job.conf[B.TOPIC_NODE_DB][B.ATTR_TYPE]
dbi = basic.toolHandling.getDbTool(job, None, "mysql") dbi = basic.toolHandling.getDbTool(job, None, "mysql")
# db = get_db() # db = get_db()
error = None error = None
@ -65,7 +63,7 @@ def register():
try: try:
sql = "INSERT INTO datest.user (username, password) " sql = "INSERT INTO datest.user (username, password) "
sql += "VALUES ( '"+username+"', '"+generate_password_hash(password)+"');" sql += "VALUES ( '"+username+"', '"+generate_password_hash(password)+"');"
dbi.execStatement(job.conf.confs[B.TOPIC_NODE_DB], sql ) dbi.execStatement(job.conf[B.TOPIC_NODE_DB], sql )
#db.commit() #db.commit()
except Exception as e: except Exception as e:
error = str(e) error = str(e)
@ -85,7 +83,7 @@ def load_logged_in_user():
g.user = None g.user = None
else: else:
job = basic.program.Job("webflask", {}) job = basic.program.Job("webflask", {})
dbtype = job.conf.confs[B.TOPIC_NODE_DB][B.ATTR_TYPE] dbtype = job.conf[B.TOPIC_NODE_DB][B.ATTR_TYPE]
userentity = basic.user.User(job) userentity = basic.user.User(job)
dbi = basic.toolHandling.getDbTool(job, userentity, dbtype) dbi = basic.toolHandling.getDbTool(job, userentity, dbtype)
error = None error = None

3
webflask/datest.py

@ -7,7 +7,8 @@ from flask import (
) )
from werkzeug.security import check_password_hash, generate_password_hash from werkzeug.security import check_password_hash, generate_password_hash
from webflask.db import get_db #from webflask.db import get_db
from . import db
bp = Blueprint('testcase', __name__, url_prefix='/testcase') bp = Blueprint('testcase', __name__, url_prefix='/testcase')

8
webflask/index.py

@ -3,11 +3,13 @@
import functools import functools
from flask import ( from flask import (
Blueprint, flash, g, redirect, render_template, request, session, url_for Blueprint, app, flash, g, redirect, render_template, request, session, url_for
) )
from werkzeug.security import check_password_hash, generate_password_hash from werkzeug.security import check_password_hash, generate_password_hash
from webflask.db import get_db # import webflask.db
#from webflask.db import get_db
bp = Blueprint('index', __name__, url_prefix='/') bp = Blueprint('index', __name__, url_prefix='/')
@ -21,3 +23,5 @@ def index():
return render_template('index.html') return render_template('index.html')
if __name__ == "__main__":
app.run()

9
webflask/templates/base.html

@ -3,28 +3,19 @@
<title>{% block title %}{% endblock %} - Datest</title> <title>{% block title %}{% endblock %} - Datest</title>
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}"> <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
<script type="text/javascript" src="{{ url_for('static', filename='script.js') }}"></script> <script type="text/javascript" src="{{ url_for('static', filename='script.js') }}"></script>
<script>
var jsonData = "{{ get_json() }}";
</script>
</head> </head>
<body> <body>
<nav> <nav>
<h1>Datest</h1> <h1>Datest</h1>
<ul> <ul>
{% if g.user %} {% if g.user %}
<li><span>{{ g.user['username'] }}</span>
<li><a href="{{ url_for('testcase.overview') }}">Testcase</a> <li><a href="{{ url_for('testcase.overview') }}">Testcase</a>
<li><a href="{{ url_for('testsuite.overview') }}">Testsuite</a> <li><a href="{{ url_for('testsuite.overview') }}">Testsuite</a>
<li><a href="{{ url_for('reports.overview') }}">Reports</a> <li><a href="{{ url_for('reports.overview') }}">Reports</a>
<li><a href="{{ url_for('components.overview') }}">Components</a>
<li><a href="{{ url_for('auth.logout') }}">Log Out</a>
{% else %} {% else %}
<li><a href="{{ url_for('testcase.overview') }}">Testcase</a> <li><a href="{{ url_for('testcase.overview') }}">Testcase</a>
<li><a href="{{ url_for('testsuite.overview') }}">Testsuite</a> <li><a href="{{ url_for('testsuite.overview') }}">Testsuite</a>
<li><a href="{{ url_for('reports.overview') }}">Reports</a> <li><a href="{{ url_for('reports.overview') }}">Reports</a>
<li><a href="{{ url_for('components.overview') }}">Components</a>
<li><a href="{{ url_for('auth.register') }}">Register</a>
<li><a href="{{ url_for('auth.login') }}">Log In</a>
{% endif %} {% endif %}
</ul> </ul>
</nav> </nav>

0
webflask/templates/selection.html

5
webflask/templates/testcase/selection.html

@ -0,0 +1,5 @@
{% extends 'base.html' %}
{% block header %}
<h1>{% block title %}Overview{% endblock %}</h1>
{% endblock %}

3
webflask/testcase.py

@ -1,7 +1,8 @@
# https://flask.palletsprojects.com/en/2.0.x/tutorial/views/ # https://flask.palletsprojects.com/en/2.0.x/tutorial/views/
# -------------------------------------------------------------- # --------------------------------------------------------------
import functools import functools
import utils.config_tool import tools.config_tool
import model.testcase as entity
from flask import ( from flask import (
Blueprint, flash, g, redirect, render_template, request, session, url_for Blueprint, flash, g, redirect, render_template, request, session, url_for

Loading…
Cancel
Save