mirror of
https://github.com/wassname/flask-security.git
synced 2026-07-12 00:50:18 +08:00
Make test_app take kwargs
This commit is contained in:
+7
-3
@@ -5,20 +5,24 @@ from tests.test_app.sqlalchemy import create_app
|
||||
|
||||
class SecurityTest(TestCase):
|
||||
|
||||
APP_KWARGS = {
|
||||
'register_blueprint': True,
|
||||
}
|
||||
AUTH_CONFIG = None
|
||||
|
||||
def setUp(self):
|
||||
super(SecurityTest, self).setUp()
|
||||
|
||||
app = self._create_app(self.AUTH_CONFIG or {})
|
||||
app_kwargs = self.APP_KWARGS
|
||||
app = self._create_app(self.AUTH_CONFIG or {}, **app_kwargs)
|
||||
app.debug = False
|
||||
app.config['TESTING'] = True
|
||||
|
||||
self.app = app
|
||||
self.client = app.test_client()
|
||||
|
||||
def _create_app(self, auth_config, register_blueprint=True):
|
||||
return create_app(auth_config, register_blueprint)
|
||||
def _create_app(self, auth_config, **kwargs):
|
||||
return create_app(auth_config, **kwargs)
|
||||
|
||||
def _get(self, route, content_type=None, follow_redirects=None, headers=None):
|
||||
return self.client.get(route, follow_redirects=follow_redirects,
|
||||
|
||||
@@ -468,13 +468,14 @@ class AsyncMailTaskTests(SecurityTest):
|
||||
|
||||
class NoBlueprintTests(SecurityTest):
|
||||
|
||||
APP_KWARGS = {
|
||||
'register_blueprint': False,
|
||||
}
|
||||
|
||||
AUTH_CONFIG = {
|
||||
'USER_COUNT': 1
|
||||
}
|
||||
|
||||
def _create_app(self, auth_config):
|
||||
return super(NoBlueprintTests, self)._create_app(auth_config, False)
|
||||
|
||||
def test_login_endpoint_is_404(self):
|
||||
r = self._get('/login')
|
||||
self.assertEqual(404, r.status_code)
|
||||
@@ -483,3 +484,18 @@ class NoBlueprintTests(SecurityTest):
|
||||
auth = 'Basic ' + base64.b64encode("matt@lp.com:password")
|
||||
r = self._get('/http', headers={'Authorization': auth})
|
||||
self.assertIn('HTTP Authentication', r.data)
|
||||
|
||||
|
||||
class ExtendFormsTest(SecurityTest):
|
||||
|
||||
APP_KWARGS = {
|
||||
}
|
||||
|
||||
AUTH_CONFIG = {
|
||||
'SECURITY_REGISTERABLE': True,
|
||||
}
|
||||
|
||||
def test_register(self):
|
||||
r = self._get('/register')
|
||||
self.assertIn('<h1>Register</h1>', r.data)
|
||||
|
||||
|
||||
@@ -201,9 +201,9 @@ class DefaultSecurityTests(SecurityTest):
|
||||
|
||||
class MongoEngineSecurityTests(DefaultSecurityTests):
|
||||
|
||||
def _create_app(self, auth_config):
|
||||
def _create_app(self, auth_config, **kwargs):
|
||||
from tests.test_app.mongoengine import create_app
|
||||
return create_app(auth_config)
|
||||
return create_app(auth_config, **kwargs)
|
||||
|
||||
|
||||
class DefaultDatastoreTests(SecurityTest):
|
||||
@@ -231,6 +231,6 @@ class DefaultDatastoreTests(SecurityTest):
|
||||
|
||||
class MongoEngineDatastoreTests(DefaultDatastoreTests):
|
||||
|
||||
def _create_app(self, auth_config):
|
||||
def _create_app(self, auth_config, **kwargs):
|
||||
from tests.test_app.mongoengine import create_app
|
||||
return create_app(auth_config)
|
||||
return create_app(auth_config, **kwargs)
|
||||
|
||||
@@ -13,7 +13,7 @@ from flask.ext.security import Security, UserMixin, RoleMixin, \
|
||||
from tests.test_app import create_app as create_base_app, populate_data, \
|
||||
add_context_processors
|
||||
|
||||
def create_app(config):
|
||||
def create_app(config, **kwargs):
|
||||
app = create_base_app(config)
|
||||
|
||||
app.config['MONGODB_SETTINGS'] = dict(
|
||||
@@ -46,7 +46,7 @@ def create_app(config):
|
||||
Role.drop_collection()
|
||||
populate_data(app.config.get('USER_COUNT', None))
|
||||
|
||||
app.security = Security(app, MongoEngineUserDatastore(db, User, Role))
|
||||
app.security = Security(app, datastore=MongoEngineUserDatastore(db, User, Role), **kwargs)
|
||||
|
||||
add_context_processors(app.security)
|
||||
|
||||
|
||||
@@ -14,10 +14,11 @@ from flask.ext.security import Security, UserMixin, RoleMixin, \
|
||||
from tests.test_app import create_app as create_base_app, populate_data, \
|
||||
add_context_processors
|
||||
|
||||
def create_app(config, register_blueprint=True):
|
||||
def create_app(config, **kwargs):
|
||||
app = create_base_app(config)
|
||||
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://root@localhost/flask_security_test'
|
||||
#app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://root@localhost/flask_security_test'
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite://'
|
||||
|
||||
db = SQLAlchemy(app)
|
||||
|
||||
@@ -50,8 +51,7 @@ def create_app(config, register_blueprint=True):
|
||||
db.create_all()
|
||||
populate_data(app.config.get('USER_COUNT', None))
|
||||
|
||||
app.security = Security(app, SQLAlchemyUserDatastore(db, User, Role),
|
||||
register_blueprint=register_blueprint)
|
||||
app.security = Security(app, datastore=SQLAlchemyUserDatastore(db, User, Role), **kwargs)
|
||||
|
||||
add_context_processors(app.security)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user