mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 01:05:42 +00:00
Merge branch 'development' of gitlab.ub.uni-bielefeld.de:sfb1288inf/opaque into development
This commit is contained in:
commit
8afb6404e7
@ -18,7 +18,11 @@ class DevelopmentConfig(Config):
|
|||||||
SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'data_dev.sqlite')
|
SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'data_dev.sqlite')
|
||||||
|
|
||||||
|
|
||||||
# class TestingConfig(Config):
|
class TestingConfig(Config):
|
||||||
|
TESTING = True
|
||||||
|
SQLALCHEMY_DATABASE_URI = os.environ.get('TEST_DATABASE_URL') or \
|
||||||
|
'sqlite://'
|
||||||
|
WTF_CSRF_ENABLED = False
|
||||||
|
|
||||||
|
|
||||||
# class ProductionConfig(Config):
|
# class ProductionConfig(Config):
|
||||||
@ -26,7 +30,7 @@ class DevelopmentConfig(Config):
|
|||||||
|
|
||||||
config = {
|
config = {
|
||||||
'development': DevelopmentConfig,
|
'development': DevelopmentConfig,
|
||||||
# 'testing': TestingConfig,
|
'testing': TestingConfig,
|
||||||
# 'production': ProductionConfig,
|
# 'production': ProductionConfig,
|
||||||
|
|
||||||
'default': DevelopmentConfig
|
'default': DevelopmentConfig
|
||||||
|
@ -11,3 +11,11 @@ migrate = Migrate(app, db)
|
|||||||
@app.shell_context_processor
|
@app.shell_context_processor
|
||||||
def make_shell_context():
|
def make_shell_context():
|
||||||
return dict(db=db, User=User, Role=Role)
|
return dict(db=db, User=User, Role=Role)
|
||||||
|
|
||||||
|
|
||||||
|
@app.cli.command()
|
||||||
|
def test():
|
||||||
|
"""Run the unit tests."""
|
||||||
|
import unittest
|
||||||
|
tests = unittest.TestLoader().discover('tests')
|
||||||
|
unittest.TextTestRunner(verbosity=2).run(tests)
|
||||||
|
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
22
tests/test_basics.py
Normal file
22
tests/test_basics.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import unittest
|
||||||
|
from flask import current_app
|
||||||
|
from app import create_app, db
|
||||||
|
|
||||||
|
|
||||||
|
class BasicsTestCase(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.app = create_app('testing')
|
||||||
|
self.app_context = self.app.app_context()
|
||||||
|
self.app_context.push()
|
||||||
|
db.create_all()
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
db.session.remove()
|
||||||
|
db.drop_all()
|
||||||
|
self.app_context.pop()
|
||||||
|
|
||||||
|
def test_app_exists(self):
|
||||||
|
self.assertFalse(current_app is None)
|
||||||
|
|
||||||
|
def test_app_is_testing(self):
|
||||||
|
self.assertTrue(current_app.config['TESTING'])
|
23
tests/test_user_model.py
Normal file
23
tests/test_user_model.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import unittest
|
||||||
|
from app.models import User
|
||||||
|
|
||||||
|
|
||||||
|
class UserModelTestCase(unittest.TestCase):
|
||||||
|
def test_password_setter(self):
|
||||||
|
u = User(password='cat')
|
||||||
|
self.assertTrue(u.password_hash is not None)
|
||||||
|
|
||||||
|
def test_no_password_getter(self):
|
||||||
|
u = User(password='cat')
|
||||||
|
with self.assertRaises(AttributeError):
|
||||||
|
u.password
|
||||||
|
|
||||||
|
def test_password_verification(self):
|
||||||
|
u = User(password='cat')
|
||||||
|
self.assertTrue(u.verify_password('cat'))
|
||||||
|
self.assertFalse(u.verify_password('dog'))
|
||||||
|
|
||||||
|
def test_password_salts_are_random(self):
|
||||||
|
u = User(password='cat')
|
||||||
|
u2 = User(password='cat')
|
||||||
|
self.assertTrue(u.password_hash != u2.password_hash)
|
Loading…
Reference in New Issue
Block a user