tests versuch 2
This commit is contained in:
parent
fdf385fe06
commit
c88f7df83a
2363 changed files with 408191 additions and 0 deletions
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
BIN
tests/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
tests/__pycache__/__init__.cpython-311.pyc
Normal file
Binary file not shown.
BIN
tests/__pycache__/conftest.cpython-311-pytest-7.4.0.pyc
Normal file
BIN
tests/__pycache__/conftest.cpython-311-pytest-7.4.0.pyc
Normal file
Binary file not shown.
BIN
tests/__pycache__/test.cpython-311-pytest-7.4.0.pyc
Normal file
BIN
tests/__pycache__/test.cpython-311-pytest-7.4.0.pyc
Normal file
Binary file not shown.
BIN
tests/__pycache__/test.cpython-311.pyc
Normal file
BIN
tests/__pycache__/test.cpython-311.pyc
Normal file
Binary file not shown.
BIN
tests/__pycache__/test_conf.cpython-311-pytest-7.4.0.pyc
Normal file
BIN
tests/__pycache__/test_conf.cpython-311-pytest-7.4.0.pyc
Normal file
Binary file not shown.
BIN
tests/__pycache__/test_website.cpython-311-pytest-7.4.0.pyc
Normal file
BIN
tests/__pycache__/test_website.cpython-311-pytest-7.4.0.pyc
Normal file
Binary file not shown.
14
tests/data.sql
Normal file
14
tests/data.sql
Normal file
|
@ -0,0 +1,14 @@
|
|||
BEGIN TRANSACTION;
|
||||
CREATE TABLE IF NOT EXISTS "users" (
|
||||
"id" INTEGER NOT NULL,
|
||||
"username" TEXT NOT NULL,
|
||||
"balance" INTEGER NOT NULL,
|
||||
PRIMARY KEY("id")
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS "tags" (
|
||||
"tagid" INEGER NOT NULL,
|
||||
"userid" INTEGER,
|
||||
FOREIGN KEY("userid") REFERENCES "users"("id"),
|
||||
PRIMARY KEY("tagid")
|
||||
);
|
||||
COMMIT;
|
BIN
tests/flask_session/2029240f6d1128be89ddc32729463129
Normal file
BIN
tests/flask_session/2029240f6d1128be89ddc32729463129
Normal file
Binary file not shown.
38
tests/test_conf.py
Normal file
38
tests/test_conf.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
import os
|
||||
import tempfile
|
||||
|
||||
import pytest
|
||||
from Website import create_app
|
||||
from Website.db import get_db, init_db
|
||||
|
||||
with open(os.path.join(os.path.dirname(__file__), 'data.sql'), 'rb') as f:
|
||||
_data_sql = f.read().decode('utf8')
|
||||
|
||||
@pytest.fixture
|
||||
def app():
|
||||
db_fd, db_path = tempfile.mkstemp()
|
||||
|
||||
app = create_app({
|
||||
'TESTING': True,
|
||||
'DATABASE': "data.db",
|
||||
})["app"]
|
||||
|
||||
with app.app_context():
|
||||
init_db()
|
||||
get_db().executescript(_data_sql)
|
||||
|
||||
yield app
|
||||
|
||||
os.close(db_fd)
|
||||
os.unlink(db_path)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client(app):
|
||||
return app.test_client()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def runner(app):
|
||||
return app.test_cli_runner()
|
||||
|
92
tests/test_website.py
Normal file
92
tests/test_website.py
Normal file
|
@ -0,0 +1,92 @@
|
|||
from pydoc import cli
|
||||
from urllib import response
|
||||
from Website import create_app
|
||||
import json
|
||||
import pdb
|
||||
from Website.db import get_db
|
||||
from .test_conf import client, app
|
||||
|
||||
|
||||
def test_config():
|
||||
assert not create_app()["app"].testing
|
||||
assert create_app({'TESTING': True})["app"].testing
|
||||
|
||||
#/adduser
|
||||
def test_adduser(client):
|
||||
response = client.get('/adduser/user')
|
||||
assert "418" in response.data.decode('utf-8')
|
||||
|
||||
def test_adduser_new(app, client):
|
||||
with app.app_context():
|
||||
db = get_db()
|
||||
assert db is get_db()
|
||||
response = client.get('/adduser/user?username=test')
|
||||
c = db.cursor()
|
||||
c.execute("SELECT * FROM users WHERE username = ?", ["test"])
|
||||
data = c.fetchone()
|
||||
assert "tag was sucsesfully added" in response.data.decode('utf-8')
|
||||
assert data[0] == 1
|
||||
assert data[1] == "test"
|
||||
assert data[2] == 0
|
||||
|
||||
def test_adduser_allreadyexists(client):
|
||||
response = client.get('/adduser/user?username=test')
|
||||
assert "Error: 757" in response.data.decode('utf-8')
|
||||
|
||||
#/addtag
|
||||
def test_addtag(client):
|
||||
response = client.get('/addtag')
|
||||
assert response.data.decode('utf-8') == "Error: 095"
|
||||
|
||||
def test_addtag_userid_nan(client):
|
||||
response = client.get('/addtag?id=test')
|
||||
assert response.data.decode('utf-8') == "Error: 095"
|
||||
|
||||
def test_addtag(app, client):
|
||||
response_addtag = client.get('/addtag?id=1')
|
||||
with app.app_context():
|
||||
None
|
||||
response_tagid = client.get('/api/tag_id?id=12345678')
|
||||
|
||||
#/api
|
||||
def test_api_change(client):
|
||||
response = client.get('/api/change')
|
||||
assert json.loads(response.data.decode('utf-8')) == {"mode":"error", "error":"043"}
|
||||
|
||||
def test_api_change_wrong_user(client):
|
||||
response = client.get('/api/change?id=2')
|
||||
assert json.loads(response.data.decode('utf-8')) == {"mode":"error", "error":"043"}
|
||||
|
||||
def test_api_change_nan(client):
|
||||
response = client.get('/api/change?id=1&?change=test')
|
||||
assert json.loads(response.data.decode('utf-8')) == {"mode":"balance", "username":"test", "balance":-1}
|
||||
|
||||
def test_api_change_none(client):
|
||||
response = client.get('/api/change?id=1')
|
||||
assert json.loads(response.data.decode('utf-8')) == {"mode":"balance", "username":"test", "balance":-2}
|
||||
|
||||
def test_api_change_right_positiv(app, client):
|
||||
response = client.get('/api/change?id=1&change=7')
|
||||
with app.app_context():
|
||||
db = get_db()
|
||||
assert db is get_db()
|
||||
c = db.cursor()
|
||||
c.execute("SELECT * FROM users WHERE username = ?", ["test"])
|
||||
data = c.fetchone()
|
||||
assert json.loads(response.data.decode('utf-8')) == {"mode":"balance", "username":"test", "balance":5}
|
||||
assert data[0] == 1
|
||||
assert data[1] == "test"
|
||||
assert data[2] == 5
|
||||
|
||||
def test_api_change_right_negativ(app, client):
|
||||
response = client.get('/api/change?id=1&change=-5')
|
||||
with app.app_context():
|
||||
db = get_db()
|
||||
assert db is get_db()
|
||||
c = db.cursor()
|
||||
c.execute("SELECT * FROM users WHERE username = ?", ["test"])
|
||||
data = c.fetchone()
|
||||
assert json.loads(response.data.decode('utf-8')) == {"mode":"balance", "username":"test", "balance":0}
|
||||
assert data[0] == 1
|
||||
assert data[1] == "test"
|
||||
assert data[2] == 0
|
Loading…
Add table
Add a link
Reference in a new issue