Skip to content

Commit

Permalink
chore(unittests) Improve performance of unit tests (#52)
Browse files Browse the repository at this point in the history
Use mongomock rather than real mongodb - this improves speed and makes it easy and self contained to run all unit tests

By default, use 'plaintext' as password hash for unit tests. This halves the test time.

Thanks pahrohfit for the code in: pallets-eco/flask-security#811
  • Loading branch information
jwag956 committed May 2, 2019
1 parent 322262c commit c3fdb73
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ cache:
- apt
- pip

services:
- mongodb

env:
- REQUIREMENTS=lowest
- REQUIREMENTS=release
Expand Down
6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,23 @@

tests_require = [
'Flask-CLI>=0.4.0',
'Flask-Mongoengine>=0.7.0',
'Flask-Mongoengine>=0.9.5',
'Flask-Peewee>=0.6.5',
'Flask-SQLAlchemy>=2.3',
'bcrypt>=3.1.0',
'check-manifest>=0.25',
'coverage>=4.0',
'isort>=4.2.2',
'mock>=1.3.0',
'mongoengine>=0.10.0',
'mongoengine>=0.12.0',
'mongomock>=3.14.0',
'msgcheck>=2.9',
'pony>=0.7.4',
'pydocstyle>=1.0.0',
'pytest-cache>=1.0',
'pytest-cov>=2.4.0',
'pytest-flakes>=1.0.1',
'pytest-mongo>=1.2.1',
'pytest-pep8>=1.0.6',
'pytest>=3.3.0',
'sqlalchemy>=1.1.0',
Expand Down
4 changes: 3 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ def app(request):
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

app.config['SECURITY_PASSWORD_SALT'] = 'salty'
# Make this plaintext for most tests - reduces unit test time by 50%
app.config['SECURITY_PASSWORD_HASH'] = 'plaintext'

for opt in ['changeable', 'recoverable', 'registerable',
'trackable', 'passwordless', 'confirmable']:
Expand Down Expand Up @@ -154,7 +156,7 @@ def mongoengine_datastore(app):
db_name = 'flask_security_test_%s' % str(time.time()).replace('.', '_')
app.config['MONGODB_SETTINGS'] = {
'db': db_name,
'host': 'localhost',
'host': 'mongomock://localhost',
'port': 27017,
'alias': db_name
}
Expand Down

0 comments on commit c3fdb73

Please sign in to comment.