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. 38
      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.file_tool
import tools.config_tool
import test.constants as T
import tools.path_const as P
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

38
webflask/__init__.py

@ -1,4 +1,5 @@
import os
from flask import Flask
@ -7,7 +8,7 @@ def create_app(test_config=None):
app = Flask(__name__, instance_relative_config=True)
app.config.from_mapping(
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:
@ -23,35 +24,22 @@ def create_app(test_config=None):
except OSError:
pass
from . import db
db.init_app(app)
from . import auth
# a simple page that says hello
@app.route('/hello')
def hello():
return 'Hello, World from __init__!'
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)
from . import auth
app.register_blueprint(auth.bp)
from . import testcase
app.register_blueprint(testcase.bp)
from . import testsuite
app.register_blueprint(testsuite.bp)
from . import components
app.register_blueprint(components.bp)
from . import reports
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'

20
webflask/auth.py

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

3
webflask/datest.py

@ -7,7 +7,8 @@ from flask import (
)
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')

8
webflask/index.py

@ -3,11 +3,13 @@
import functools
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 webflask.db import get_db
# import webflask.db
#from webflask.db import get_db
bp = Blueprint('index', __name__, url_prefix='/')
@ -21,3 +23,5 @@ def index():
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>
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
<script type="text/javascript" src="{{ url_for('static', filename='script.js') }}"></script>
<script>
var jsonData = "{{ get_json() }}";
</script>
</head>
<body>
<nav>
<h1>Datest</h1>
<ul>
{% if g.user %}
<li><span>{{ g.user['username'] }}</span>
<li><a href="{{ url_for('testcase.overview') }}">Testcase</a>
<li><a href="{{ url_for('testsuite.overview') }}">Testsuite</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 %}
<li><a href="{{ url_for('testcase.overview') }}">Testcase</a>
<li><a href="{{ url_for('testsuite.overview') }}">Testsuite</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 %}
</ul>
</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/
# --------------------------------------------------------------
import functools
import utils.config_tool
import tools.config_tool
import model.testcase as entity
from flask import (
Blueprint, flash, g, redirect, render_template, request, session, url_for

Loading…
Cancel
Save