Compare commits
No commits in common. "bb7168e3cabdb44fa154ae70b15d727f94b29742" and "5c9b5fa56d8c2abbb113201276650add0979d1ab" have entirely different histories.
bb7168e3ca
...
5c9b5fa56d
4 changed files with 20 additions and 68 deletions
|
@ -44,7 +44,7 @@ def create_app(test_config=None):
|
||||||
# app.logger.info("Website exited")
|
# app.logger.info("Website exited")
|
||||||
|
|
||||||
#var
|
#var
|
||||||
user_queue = queue.Queue()
|
users = queue.Queue()
|
||||||
|
|
||||||
#website
|
#website
|
||||||
@app.route('/favicon.ico')
|
@app.route('/favicon.ico')
|
||||||
|
@ -216,13 +216,14 @@ def create_app(test_config=None):
|
||||||
|
|
||||||
@app.route("/addtag", methods=['GET'])
|
@app.route("/addtag", methods=['GET'])
|
||||||
def get_addtag_request():
|
def get_addtag_request():
|
||||||
|
global users
|
||||||
try:
|
try:
|
||||||
user_id = int(request.args.get("id"))
|
user_id = int(request.args.get("id"))
|
||||||
except: #except im Normalen Code!
|
except: #except im Normalen Code!
|
||||||
return "Error: 095"
|
return "Error: 095"
|
||||||
session_id = uuid.uuid4()
|
session_id = uuid.uuid4()
|
||||||
session[id] = session_id
|
session[id] = session_id
|
||||||
user_queue.put([user_id, "add", session_id])
|
users.put([user_id, "add", session_id])
|
||||||
return render_template("addtag.html", user=user_id)
|
return render_template("addtag.html", user=user_id)
|
||||||
|
|
||||||
@socketio.on('addtag')
|
@socketio.on('addtag')
|
||||||
|
@ -230,8 +231,8 @@ def create_app(test_config=None):
|
||||||
global finished
|
global finished
|
||||||
global message
|
global message
|
||||||
join_room(session[id])
|
join_room(session[id])
|
||||||
if len(user_queue.queue) > 0:
|
if len(users.queue) > 0:
|
||||||
user = user_queue.queue[len(user_queue.queue) - 1]
|
user = users.queue[len(users.queue) - 1]
|
||||||
if user == [data["data"], "add", session[id]]:
|
if user == [data["data"], "add", session[id]]:
|
||||||
socketio.emit("wait", "wait", to=session[id])
|
socketio.emit("wait", "wait", to=session[id])
|
||||||
i = 0
|
i = 0
|
||||||
|
@ -240,7 +241,7 @@ def create_app(test_config=None):
|
||||||
i += 1
|
i += 1
|
||||||
if i > 20:
|
if i > 20:
|
||||||
socketio.emit("error", "352", to=session[id])
|
socketio.emit("error", "352", to=session[id])
|
||||||
notimportant = user_queue.get()
|
notimportant = users.get()
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
finished = None
|
finished = None
|
||||||
|
@ -254,13 +255,14 @@ def create_app(test_config=None):
|
||||||
|
|
||||||
@app.route("/removetag", methods=['GET'])
|
@app.route("/removetag", methods=['GET'])
|
||||||
def get_removetag_request():
|
def get_removetag_request():
|
||||||
|
global users
|
||||||
try:
|
try:
|
||||||
user_id = int(request.args.get("id"))
|
user_id = int(request.args.get("id"))
|
||||||
except: #except im Normalen Code!
|
except: #except im Normalen Code!
|
||||||
return "Wrong user id!"
|
return "Wrong user id!"
|
||||||
session_id = uuid.uuid4()
|
session_id = uuid.uuid4()
|
||||||
session[id] = session_id
|
session[id] = session_id
|
||||||
user_queue.put([user_id, "remove", session_id])
|
users.put([user_id, "remove", session_id])
|
||||||
return render_template("removetag.html", user=user_id)
|
return render_template("removetag.html", user=user_id)
|
||||||
|
|
||||||
@socketio.on('removetag')
|
@socketio.on('removetag')
|
||||||
|
@ -268,8 +270,8 @@ def create_app(test_config=None):
|
||||||
global finished
|
global finished
|
||||||
global message
|
global message
|
||||||
join_room(session[id])
|
join_room(session[id])
|
||||||
if len(user_queue.queue) > 0:
|
if len(users.queue) > 0:
|
||||||
queue_item = user_queue.queue[len(user_queue.queue) - 1]
|
queue_item = users.queue[len(users.queue) - 1]
|
||||||
user = queue_item[0]
|
user = queue_item[0]
|
||||||
if queue_item == [data["data"], "remove", session[id]]:
|
if queue_item == [data["data"], "remove", session[id]]:
|
||||||
socketio.emit("wait", "wait", to=session[id])
|
socketio.emit("wait", "wait", to=session[id])
|
||||||
|
@ -279,7 +281,7 @@ def create_app(test_config=None):
|
||||||
i += 1
|
i += 1
|
||||||
if i > 20:
|
if i > 20:
|
||||||
socketio.emit("error", "352", to=session[id])
|
socketio.emit("error", "352", to=session[id])
|
||||||
notimportant = user_queue.get()
|
notimportant = users.get()
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
finished = None
|
finished = None
|
||||||
|
@ -325,8 +327,8 @@ def create_app(test_config=None):
|
||||||
c.execute(f"SELECT * FROM tags WHERE tagid=?", [tag_id])
|
c.execute(f"SELECT * FROM tags WHERE tagid=?", [tag_id])
|
||||||
|
|
||||||
tag_list = c.fetchall()
|
tag_list = c.fetchall()
|
||||||
if user_queue.qsize() > 0:
|
if users.qsize() > 0:
|
||||||
queue_item = user_queue.get()
|
queue_item = users.get()
|
||||||
user = queue_item[0]
|
user = queue_item[0]
|
||||||
|
|
||||||
state = queue_item[1]
|
state = queue_item[1]
|
||||||
|
@ -369,7 +371,7 @@ def create_app(test_config=None):
|
||||||
user_list = c.fetchall()
|
user_list = c.fetchall()
|
||||||
if user_list != []:
|
if user_list != []:
|
||||||
balance_old = user_list[0][2]
|
balance_old = user_list[0][2]
|
||||||
if user_queue.qsize() == 0:
|
if users.qsize() == 0:
|
||||||
c.execute(f"UPDATE users SET balance = balance - 1 WHERE id={tag[1]}")
|
c.execute(f"UPDATE users SET balance = balance - 1 WHERE id={tag[1]}")
|
||||||
db.commit()
|
db.commit()
|
||||||
c.execute(f"SELECT * FROM users WHERE id={tag[1]}")
|
c.execute(f"SELECT * FROM users WHERE id={tag[1]}")
|
||||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -43,22 +43,10 @@ def test_addtag_userid_nan(client):
|
||||||
response = client.get('/addtag?id=test')
|
response = client.get('/addtag?id=test')
|
||||||
assert response.data.decode('utf-8') == "Error: 095"
|
assert response.data.decode('utf-8') == "Error: 095"
|
||||||
|
|
||||||
def test_add_tag_direktli(app):
|
def test_addtag(app, client):
|
||||||
with app.app_context():
|
response_addtag = client.get('/addtag?id=1')
|
||||||
db = get_db()
|
#hier muss der userque was hinzugefügt werden!
|
||||||
assert db is get_db()
|
response_tagid = client.get('/api/tag_id?id=12345678')
|
||||||
c = db.cursor()
|
|
||||||
c.execute("INSERT INTO tags (tagid, userid) VALUES (12345678, 1)")
|
|
||||||
c.execute("INSERT INTO tags (tagid, userid) VALUES (23456789, 1)")
|
|
||||||
db.commit()
|
|
||||||
c.execute("SELECT * FROM tags WHERE tagid = 12345678")
|
|
||||||
data_1 = c.fetchone()
|
|
||||||
c.execute("SELECT * FROM tags WHERE tagid = 23456789")
|
|
||||||
data_2 = c.fetchone()
|
|
||||||
assert data_1[0] == 12345678
|
|
||||||
assert data_1[1] == 1
|
|
||||||
assert data_2[0] == 23456789
|
|
||||||
assert data_2[1] == 1
|
|
||||||
|
|
||||||
#/api
|
#/api
|
||||||
def test_api_change(client):
|
def test_api_change(client):
|
||||||
|
@ -102,41 +90,3 @@ def test_api_change_right_negativ(app, client):
|
||||||
assert data[0] == 1
|
assert data[0] == 1
|
||||||
assert data[1] == "test"
|
assert data[1] == "test"
|
||||||
assert data[2] == 0
|
assert data[2] == 0
|
||||||
|
|
||||||
def test_api_tagid(app, client):
|
|
||||||
response = client.get("/api/tag_id")
|
|
||||||
assert json.loads(response.data.decode('utf-8')) == {'error': '054', 'mode': 'error'}
|
|
||||||
|
|
||||||
def test_api_tagid_NaN(app, client):
|
|
||||||
response = client.get("/api/tag_id?id=test")
|
|
||||||
assert json.loads(response.data.decode('utf-8')) == {'error': '054', 'mode': 'error'}
|
|
||||||
|
|
||||||
def test_api_tagid_wrong_id(app, client):
|
|
||||||
response = client.get("/api/tag_id?id=1234")
|
|
||||||
assert json.loads(response.data.decode('utf-8')) == {'error': '054', 'mode': 'error'}
|
|
||||||
|
|
||||||
def test_api_tagid_right_firsttag(app, client):
|
|
||||||
response = client.get("/api/tag_id?id=12345678")
|
|
||||||
with app.app_context():
|
|
||||||
db = get_db()
|
|
||||||
assert db is get_db()
|
|
||||||
c = db.cursor()
|
|
||||||
c.execute("SELECT * FROM users WHERE id = 1")
|
|
||||||
data = c.fetchone()
|
|
||||||
assert data[0] == 1
|
|
||||||
assert data[1] == "test"
|
|
||||||
assert data[2] == -1
|
|
||||||
assert json.loads(response.data.decode('utf-8')) == {'balance': -1, 'mode': 'balance', 'username': 'test'}
|
|
||||||
|
|
||||||
def test_api_tagid_right_seconttag(app, client):
|
|
||||||
response = client.get("/api/tag_id?id=23456789")
|
|
||||||
with app.app_context():
|
|
||||||
db = get_db()
|
|
||||||
assert db is get_db()
|
|
||||||
c = db.cursor()
|
|
||||||
c.execute("SELECT * FROM users WHERE id = 1")
|
|
||||||
data = c.fetchone()
|
|
||||||
assert data[0] == 1
|
|
||||||
assert data[1] == "test"
|
|
||||||
assert data[2] == -2
|
|
||||||
assert json.loads(response.data.decode('utf-8')) == {'balance': -2, 'mode': 'balance', 'username': 'test'}
|
|
Loading…
Reference in a new issue