diff --git a/etiquette/objects.py b/etiquette/objects.py index 1caf1ff..8237acd 100644 --- a/etiquette/objects.py +++ b/etiquette/objects.py @@ -22,9 +22,13 @@ from . import helpers BAIL = sentinel.Sentinel('BAIL') def normalize_db_row(db_row, table): + if isinstance(db_row, dict): + return db_row + if isinstance(db_row, (list, tuple)): - db_row = dict(zip(constants.SQL_COLUMNS[table], db_row)) - return db_row + return dict(zip(constants.SQL_COLUMNS[table], db_row)) + + raise TypeError(f'db_row should be {dict}, {list}, or {tuple}, not {type(db_row)}.') class ObjectBase: def __init__(self, photodb): @@ -581,7 +585,7 @@ class Bookmark(ObjectBase): url = url.strip() if not url: - raise ValueError(f'Invalid URL "{url}".') + raise ValueError(f'URL can not be blank.') return url diff --git a/etiquette/photodb.py b/etiquette/photodb.py index 1fbca5d..4ef1a73 100644 --- a/etiquette/photodb.py +++ b/etiquette/photodb.py @@ -1210,10 +1210,16 @@ class PDBUserMixin: raise exceptions.UserExists(existing_user) def assert_valid_password(self, password): + if not isinstance(password, bytes): + raise TypeError(f'Password must be {bytes}, not {type(password)}.') + if len(password) < self.config['user']['min_password_length']: raise exceptions.PasswordTooShort(min_length=self.config['user']['min_password_length']) def assert_valid_username(self, username): + if not isinstance(username, str): + raise TypeError(f'Username must be {str}, not {type(username)}.') + if len(username) < self.config['user']['min_username_length']: raise exceptions.UsernameTooShort( username=username, @@ -1287,7 +1293,7 @@ class PDBUserMixin: be workable but fails. ''' if user_obj_or_id is None: - author_id = None + return None elif isinstance(user_obj_or_id, objects.User): if user_obj_or_id.photodb != self: