aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/auth/test_credentials.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2022-11-15 06:27:33 +0300
committerFrederick Muriuki Muriithi2022-11-15 06:27:33 +0300
commitd043cd59127a1031de20b12562712b6e3c50feef (patch)
treebefe3233dc4136158e300e8ffeef6db41b11e2ac /tests/unit/auth/test_credentials.py
parent3dc9a8a4f413d142e84a81f9c1abafedb779d7dd (diff)
downloadgenenetwork3-d043cd59127a1031de20b12562712b6e3c50feef.tar.gz
pylint: Fix a myriad of linting errors
Diffstat (limited to 'tests/unit/auth/test_credentials.py')
-rw-r--r--tests/unit/auth/test_credentials.py35
1 files changed, 19 insertions, 16 deletions
diff --git a/tests/unit/auth/test_credentials.py b/tests/unit/auth/test_credentials.py
index 1425eb2..f2a3d25 100644
--- a/tests/unit/auth/test_credentials.py
+++ b/tests/unit/auth/test_credentials.py
@@ -1,30 +1,36 @@
"""Test the credentials checks"""
-import sqlite3
-
import pytest
-from contextlib import closing
from yoyo.migrations import MigrationList
from hypothesis import given, settings, strategies, HealthCheck
-from tests.unit.auth.conftest import migrations_up_to
+from gn3.auth import db
from gn3.auth.authentication import credentials_in_database
from gn3.migrations import get_migration, apply_migrations, rollback_migrations
+from tests.unit.auth.conftest import migrations_up_to
+
@pytest.fixture
def with_credentials_table(backend, auth_testdb_path):
+ """
+ Fixture: Yield a connection object with the 'user_credentials' table
+ created.
+ """
migrations_dir = "migrations/auth"
migration = f"{migrations_dir}/20221103_02_sGrIs-create-user-credentials-table.py"
migrations = (migrations_up_to(migration, migrations_dir) +
MigrationList([get_migration(migration)]))
apply_migrations(backend, migrations)
- with closing(sqlite3.connect(auth_testdb_path)) as conn:
+ with db.connection(auth_testdb_path) as conn:
yield conn
rollback_migrations(backend, migrations)
@pytest.fixture
-def with_credentials(with_credentials_table):
- with closing(with_credentials_table.cursor()) as cursor:
+def with_credentials(with_credentials_table):# pylint: disable=redefined-outer-name
+ """
+ Fixture: Initialise the database with some user credentials.
+ """
+ with db.cursor(with_credentials_table) as cursor:
cursor.executemany(
"INSERT INTO users VALUES (:user_id, :email, :name)",
({"user_id": "82552014-21ee-4321-b96a-b8788b97b862",
@@ -56,14 +62,13 @@ def with_credentials(with_credentials_table):
@pytest.mark.unit_test
@given(strategies.emails(), strategies.text())
@settings(suppress_health_check=[HealthCheck.function_scoped_fixture])
-def test_credentials_not_in_database(with_credentials, email, password):
+def test_credentials_not_in_database(with_credentials, email, password):# pylint: disable=redefined-outer-name
"""
GIVEN: credentials that do not exist in the database
WHEN: the `credentials_in_database` function is run against the credentials
THEN: check that the function returns false in all cases.
"""
- with closing(with_credentials.cursor()) as cursor:
- results = credentials_in_database(cursor, email, password)
+ with db.cursor(with_credentials) as cursor:
assert credentials_in_database(cursor, email, password) is False
@pytest.mark.unit_test
@@ -71,14 +76,13 @@ def test_credentials_not_in_database(with_credentials, email, password):
"email,password",
(("first@test.user", "wrongpassword"),
("first@tes.user", "testuser01")))
-def test_partially_wrong_credentials(with_credentials, email, password):
+def test_partially_wrong_credentials(with_credentials, email, password):# pylint: disable=redefined-outer-name
"""
GIVEN: credentials that exist in the database
WHEN: the credentials are checked with partially wrong values
THEN: the check fails since the credentials are not correct
"""
- with closing(with_credentials.cursor()) as cursor:
- results = credentials_in_database(cursor, email, password)
+ with db.cursor(with_credentials) as cursor:
assert credentials_in_database(cursor, email, password) is False
@pytest.mark.unit_test
@@ -86,12 +90,11 @@ def test_partially_wrong_credentials(with_credentials, email, password):
"email,password",
(("first@test.user", "testuser01"),
("second@test.user", "testuser02")))
-def test_partially_correct_credentials(with_credentials, email, password):
+def test_partially_correct_credentials(with_credentials, email, password):# pylint: disable=redefined-outer-name
"""
GIVEN: credentials that exist in the database
WHEN: the credentials are checked with correct values
THEN: the check passes
"""
- with closing(with_credentials.cursor()) as cursor:
- results = credentials_in_database(cursor, email, password)
+ with db.cursor(with_credentials) as cursor:
assert credentials_in_database(cursor, email, password) is True