continue tests

This commit is contained in:
2023-06-12 23:57:49 +02:00
parent ae80d8b87f
commit b3afd580e0
12 changed files with 252 additions and 38 deletions

View File

@@ -5,20 +5,28 @@ from beflask.models import Benchmark, User, db
class AuthActions(object):
guest_user = "guest"
guest_password = "patata"
def __init__(self, client):
self._client = client
def login(
self, username="guest", password="patata", follow_redirects=False
self,
username=None,
password=None,
follow_redirects=False,
):
username = username or self.guest_user
password = password or self.guest_password
return self._client.post(
"/login",
data={"username": username, "password": password},
follow_redirects=follow_redirects,
)
def logout(self):
return self._client.get("/logout")
def logout(self, follow_redirects=False):
return self._client.get("/logout", follow_redirects=follow_redirects)
@pytest.fixture
@@ -27,11 +35,11 @@ def auth(client):
@pytest.fixture
def app():
def app(admin_user, admin_password):
socketio, app = application.create_app("testing")
app.test_client_class = FlaskLoginClient
with app.app_context():
db_seed(db)
db_seed(db, admin_user, admin_password)
return socketio, app
@@ -45,13 +53,33 @@ def runner(app):
return app[1].test_cli_runner()
def db_seed(db):
@pytest.fixture
def admin_user():
return "rmontanana"
@pytest.fixture
def admin_password():
return "patito"
@pytest.fixture
def guest_user():
return AuthActions.guest_user
@pytest.fixture
def guest_password():
return AuthActions.guest_password
def db_seed(db, admin_user, admin_password):
db.drop_all()
db.create_all()
b = Benchmark(
name="discretizbench",
folder="/Users/rmontanana/Code/discretizbench",
description="Experiments with local discretization and Bayesian "
description="Experiments with local discretization and Bayesian"
"classifiers",
)
db.session.add(b)
@@ -68,19 +96,19 @@ def db_seed(db):
)
db.session.add(b)
u = User(
username="rmontanana",
username=admin_user,
email="rmontanana@gmail.com",
admin=True,
benchmark_id=1,
)
u.set_password("patito")
u.set_password(admin_password)
u1 = User(
username="guest",
username=AuthActions.guest_user,
email="guest@example.com",
admin=False,
benchmark_id=1,
)
u1.set_password("patata")
u1.set_password(AuthActions.guest_password)
db.session.add(b)
db.session.add(u)
db.session.add(u1)