From 8eda31cbbe21df783ab01b08341365a9936f5a3a Mon Sep 17 00:00:00 2001 From: s3lph Date: Wed, 6 Jun 2018 13:54:36 +0200 Subject: [PATCH] Renamed DatabaseFacade to MatematDatabase and added additional documentation. --- matemat/db/__init__.py | 2 +- matemat/db/facade.py | 18 +++++++++++++++--- matemat/db/test/test_facade.py | 4 ++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/matemat/db/__init__.py b/matemat/db/__init__.py index 0f2bc0a..93b6c8c 100644 --- a/matemat/db/__init__.py +++ b/matemat/db/__init__.py @@ -1,3 +1,3 @@ from .wrapper import DatabaseWrapper -from .facade import DatabaseFacade as Database +from .facade import MatematDatabase diff --git a/matemat/db/facade.py b/matemat/db/facade.py index 6640e9d..7df896a 100644 --- a/matemat/db/facade.py +++ b/matemat/db/facade.py @@ -8,21 +8,33 @@ from matemat.exceptions import AuthenticationError, DatabaseConsistencyError from matemat.db import DatabaseWrapper -class DatabaseFacade(object): +class MatematDatabase(object): + """ + This class provides a facade that abstracts every (TM) needed database access in high level functions. + + Usage example (creating a user, changing the users touchkey, login as that user and delete the user: + + with MatematDatabase('/srv/matemat/production.sqlite3') as db: + user: User = db.create_user('testuser', 'supersecurepassword') + db.change_touchkey(user, 'supersecurepassword', '048cdef') + user2: User = db.login('testuser', touchkey='048cdef') + db.delete_user(user2) + + """ def __init__(self, filename: str) -> None: """ Create a new database facade. This does not connect to the SQLite3 database yet. To actually open the connection, use the Context Manager 'with' syntax (PEP 343), e.g.: - with Database('path/to/database.sqlite3') as db: + with MatematDatabase('path/to/database.sqlite3') as db: db.foo() :param filename: The SQLite3 database file to use. """ self.db: DatabaseWrapper = DatabaseWrapper(filename) - def __enter__(self) -> 'DatabaseFacade': + def __enter__(self) -> 'MatematDatabase': # Pass context manager stuff through to the database wrapper self.db.__enter__() return self diff --git a/matemat/db/test/test_facade.py b/matemat/db/test/test_facade.py index 91096b8..c266feb 100644 --- a/matemat/db/test/test_facade.py +++ b/matemat/db/test/test_facade.py @@ -3,14 +3,14 @@ import unittest import bcrypt -from matemat.db import Database +from matemat.db import MatematDatabase from matemat.exceptions import AuthenticationError, DatabaseConsistencyError class DatabaseTest(unittest.TestCase): def setUp(self) -> None: - self.db = Database(':memory:') + self.db = MatematDatabase(':memory:') def test_create_user(self) -> None: with self.db as db: