Added SQLite support for PasswordType
This commit is contained in:
		| @@ -2,7 +2,7 @@ import weakref | ||||
|  | ||||
| import six | ||||
| from sqlalchemy import types | ||||
| from sqlalchemy.dialects import oracle, postgresql | ||||
| from sqlalchemy.dialects import oracle, postgresql, sqlite | ||||
| from sqlalchemy.ext.mutable import Mutable | ||||
|  | ||||
| from ..exceptions import ImproperlyConfigured | ||||
| @@ -192,14 +192,15 @@ class PasswordType(types.TypeDecorator, ScalarCoercible): | ||||
|         if dialect.name == 'postgresql': | ||||
|             # Use a BYTEA type for postgresql. | ||||
|             impl = postgresql.BYTEA(self.length) | ||||
|             return dialect.type_descriptor(impl) | ||||
|         if dialect.name == 'oracle': | ||||
|         elif dialect.name == 'oracle': | ||||
|             # Use a RAW type for oracle. | ||||
|             impl = oracle.RAW(self.length) | ||||
|             return dialect.type_descriptor(impl) | ||||
|  | ||||
|         # Use a VARBINARY for all other dialects. | ||||
|         impl = types.VARBINARY(self.length) | ||||
|         elif dialect.name == 'sqlite': | ||||
|             # Use a BLOB type for sqlite | ||||
|             impl = sqlite.BLOB(self.length) | ||||
|         else: | ||||
|             # Use a VARBINARY for all other dialects. | ||||
|             impl = types.VARBINARY(self.length) | ||||
|         return dialect.type_descriptor(impl) | ||||
|  | ||||
|     def process_bind_param(self, value, dialect): | ||||
|   | ||||
| @@ -1,6 +1,10 @@ | ||||
| import mock | ||||
| import pytest | ||||
| import sqlalchemy as sa | ||||
| import sqlalchemy.dialects.mysql | ||||
| import sqlalchemy.dialects.oracle | ||||
| import sqlalchemy.dialects.postgresql | ||||
| import sqlalchemy.dialects.sqlite | ||||
| from sqlalchemy import inspect | ||||
|  | ||||
| from sqlalchemy_utils import Password, PasswordType, types  # noqa | ||||
| @@ -52,6 +56,23 @@ def onload_callback(schemes, deprecated): | ||||
| @pytest.mark.skipif('types.password.passlib is None') | ||||
| class TestPasswordType(object): | ||||
|  | ||||
|     @pytest.mark.parametrize('dialect_module,impl', [ | ||||
|         (sqlalchemy.dialects.sqlite, sa.dialects.sqlite.BLOB), | ||||
|         (sqlalchemy.dialects.postgresql, sa.dialects.postgresql.BYTEA), | ||||
|         (sqlalchemy.dialects.oracle, sa.dialects.oracle.RAW), | ||||
|         (sqlalchemy.dialects.mysql, sa.VARBINARY), | ||||
|     ]) | ||||
|     def test_load_dialect_impl(self, dialect_module, impl): | ||||
|         """ | ||||
|         Should produce the same impl type as Alembic would expect after | ||||
|         inspecing a database | ||||
|         """ | ||||
|         password_type = PasswordType() | ||||
|         assert isinstance( | ||||
|             password_type.load_dialect_impl(dialect_module.dialect()), | ||||
|             impl | ||||
|         ) | ||||
|  | ||||
|     def test_encrypt(self, User): | ||||
|         """Should encrypt the password on setting the attribute.""" | ||||
|         obj = User() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Vlad Frolov
					Vlad Frolov