From 7ecfc4bafc75a125c73e03bd630f065d9e4ed40c Mon Sep 17 00:00:00 2001 From: Navan Chauhan Date: Fri, 4 Jun 2021 21:29:42 +0530 Subject: added superuser --- app/__init__.py | 11 ++++++++++- app/config_dev.py | 4 +++- app/tests/test_cli.py | 3 ++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 1c759e7..9f025af 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -22,7 +22,16 @@ def create_database(): db.create_all() @database_cli.command("delete") def delete_database(): - db.drop_all() + db.drop_all() +@database_cli.command("admin-create") +def make_superuser_database(): + user = User( + first_name="Supersu", + email=app.config["ADMIN_EMAIL"], + password=app.config["ADMIN_PASSWORD"], + role="SUPERUSER") + db.session.add(user) + db.session.commit() app.cli.add_command(database_cli) diff --git a/app/config_dev.py b/app/config_dev.py index 801c0c2..e0b32a0 100644 --- a/app/config_dev.py +++ b/app/config_dev.py @@ -1,3 +1,5 @@ SQLALCHEMY_DATABASE_URI = 'sqlite:////tmp/test.db' SQLALCHEMY_TRACK_MODIFICATIONS = False -SECRET_KEY = "tchtchtch" \ No newline at end of file +SECRET_KEY = "tchtchtch" +ADMIN_EMAIL = "admin@example.com" +ADMIN_PASSWORD = "iamgroot" \ No newline at end of file diff --git a/app/tests/test_cli.py b/app/tests/test_cli.py index 7a5aa73..aec4cee 100644 --- a/app/tests/test_cli.py +++ b/app/tests/test_cli.py @@ -3,4 +3,5 @@ from app import database_cli def test_database_commands(app, client): runner = app.test_cli_runner() assert runner.invoke(database_cli,["delete"]).exit_code == 0 - assert runner.invoke(database_cli,["create"]).exit_code == 0 \ No newline at end of file + assert runner.invoke(database_cli,["create"]).exit_code == 0 + assert runner.invoke(database_cli,["admin-create"]).exit_code == 0 \ No newline at end of file -- cgit v1.2.3