From b0d4aeb29c059c6dea85a7993149fa1e0697f702 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Tue, 15 Nov 2022 04:22:17 +0300 Subject: pylint: Fix linting errors. --- gn3/auth/authorisation/groups.py | 1 + gn3/auth/db.py | 18 +++++++++++++----- main.py | 7 ++++--- tests/unit/conftest.py | 3 ++- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/gn3/auth/authorisation/groups.py b/gn3/auth/authorisation/groups.py index ad30763..5290196 100644 --- a/gn3/auth/authorisation/groups.py +++ b/gn3/auth/authorisation/groups.py @@ -8,6 +8,7 @@ from . import authorised_p ("create-group",), success_message="Successfully created group.", error_message="Failed to create group.") def create_group(conn, group_name): + """Create a group""" with db.cursor(conn) as cursor: group_id = uuid.uuid4() cursor.execute( diff --git a/gn3/auth/db.py b/gn3/auth/db.py index c0d0415..e732a03 100644 --- a/gn3/auth/db.py +++ b/gn3/auth/db.py @@ -4,16 +4,24 @@ import contextlib @contextlib.contextmanager def connection(db_path: str): - connection = sqlite3.connect(db_path) + """Create the connection to the auth database.""" + conn = sqlite3.connect(db_path) try: - yield connection + yield conn + except: # pylint: disable=bare-except + conn.rollback() finally: - connection.close() + conn.commit() + conn.close() @contextlib.contextmanager -def cursor(connection): - cur = connection.cursor() +def cursor(conn): + """Get a cursor from the given connection to the auth database.""" + cur = conn.cursor() try: yield cur + except: # pylint: disable=bare-except + conn.rollback() finally: + conn.commit() cur.close() diff --git a/main.py b/main.py index aaa51da..8d03148 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,7 @@ """Main entry point for project""" +from yoyo import get_backend, read_migrations +from gn3 import migrations from gn3.app import create_app app = create_app() @@ -8,9 +10,8 @@ app = create_app() @app.cli.command() def apply_migrations(): - from yoyo import get_backend, read_migrations - from gn3.migrations import apply_migrations - apply_migrations( + """Apply the dabasase migrations.""" + migrations.apply_migrations( get_backend(f'sqlite:///{app.config["AUTH_DB"]}'), read_migrations(app.config["AUTH_MIGRATIONS"])) diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py index 9660c32..e5d941d 100644 --- a/tests/unit/conftest.py +++ b/tests/unit/conftest.py @@ -9,6 +9,7 @@ from gn3.app import create_app @pytest.fixture(scope="session") def test_app(): + """Fixture: setup the test app""" # Do some setup with TemporaryDirectory() as testdir: testdb = Path(testdir).joinpath( @@ -21,7 +22,7 @@ def test_app(): testdb.unlink(missing_ok=True) @pytest.fixture(scope="session") -def client(test_app): +def client(test_app): # pylint: disable=redefined-outer-name """Create a test client fixture for tests""" with test_app.app_context(): yield test_app.test_client() -- cgit v1.2.3