Kill classes in test_testing

This commit is contained in:
Markus Unterwaditzer 2014-09-04 15:30:12 +02:00
parent 77d887526d
commit f8a778deae

View file

@ -16,9 +16,7 @@ import unittest
from flask._compat import text_type from flask._compat import text_type
class TestTestTools(object): def test_environ_defaults_from_config():
def test_environ_defaults_from_config(self):
app = flask.Flask(__name__) app = flask.Flask(__name__)
app.testing = True app.testing = True
app.config['SERVER_NAME'] = 'example.com:1234' app.config['SERVER_NAME'] = 'example.com:1234'
@ -33,7 +31,7 @@ class TestTestTools(object):
rv = c.get('/') rv = c.get('/')
assert rv.data == b'http://example.com:1234/foo/' assert rv.data == b'http://example.com:1234/foo/'
def test_environ_defaults(self): def test_environ_defaults():
app = flask.Flask(__name__) app = flask.Flask(__name__)
app.testing = True app.testing = True
@app.route('/') @app.route('/')
@ -46,7 +44,7 @@ class TestTestTools(object):
rv = c.get('/') rv = c.get('/')
assert rv.data == b'http://localhost/' assert rv.data == b'http://localhost/'
def test_redirect_keep_session(self): def test_redirect_keep_session():
app = flask.Flask(__name__) app = flask.Flask(__name__)
app.secret_key = 'testing' app.secret_key = 'testing'
@ -78,7 +76,7 @@ class TestTestTools(object):
rv = c.get('/getsession') rv = c.get('/getsession')
assert rv.data == b'foo' assert rv.data == b'foo'
def test_session_transactions(self): def test_session_transactions():
app = flask.Flask(__name__) app = flask.Flask(__name__)
app.testing = True app.testing = True
app.secret_key = 'testing' app.secret_key = 'testing'
@ -98,7 +96,7 @@ class TestTestTools(object):
assert len(sess) == 1 assert len(sess) == 1
assert sess['foo'] == [42] assert sess['foo'] == [42]
def test_session_transactions_no_null_sessions(self): def test_session_transactions_no_null_sessions():
app = flask.Flask(__name__) app = flask.Flask(__name__)
app.testing = True app.testing = True
@ -111,7 +109,7 @@ class TestTestTools(object):
else: else:
assert False, 'Expected runtime error' assert False, 'Expected runtime error'
def test_session_transactions_keep_context(self): def test_session_transactions_keep_context():
app = flask.Flask(__name__) app = flask.Flask(__name__)
app.testing = True app.testing = True
app.secret_key = 'testing' app.secret_key = 'testing'
@ -123,7 +121,7 @@ class TestTestTools(object):
with c.session_transaction(): with c.session_transaction():
assert req is flask.request._get_current_object() assert req is flask.request._get_current_object()
def test_session_transaction_needs_cookies(self): def test_session_transaction_needs_cookies():
app = flask.Flask(__name__) app = flask.Flask(__name__)
app.testing = True app.testing = True
c = app.test_client(use_cookies=False) c = app.test_client(use_cookies=False)
@ -135,7 +133,7 @@ class TestTestTools(object):
else: else:
assert False, 'Expected runtime error' assert False, 'Expected runtime error'
def test_test_client_context_binding(self): def test_test_client_context_binding():
app = flask.Flask(__name__) app = flask.Flask(__name__)
app.config['LOGGER_HANDLER_POLICY'] = 'never' app.config['LOGGER_HANDLER_POLICY'] = 'never'
@app.route('/') @app.route('/')
@ -166,7 +164,7 @@ class TestTestTools(object):
else: else:
raise AssertionError('some kind of exception expected') raise AssertionError('some kind of exception expected')
def test_reuse_client(self): def test_reuse_client():
app = flask.Flask(__name__) app = flask.Flask(__name__)
c = app.test_client() c = app.test_client()
@ -176,7 +174,7 @@ class TestTestTools(object):
with c: with c:
assert c.get('/').status_code == 404 assert c.get('/').status_code == 404
def test_test_client_calls_teardown_handlers(self): def test_test_client_calls_teardown_handlers():
app = flask.Flask(__name__) app = flask.Flask(__name__)
called = [] called = []
@app.teardown_request @app.teardown_request
@ -198,7 +196,7 @@ class TestTestTools(object):
assert called == [None] assert called == [None]
assert called == [None, None] assert called == [None, None]
def test_full_url_request(self): def test_full_url_request():
app = flask.Flask(__name__) app = flask.Flask(__name__)
app.testing = True app.testing = True
@ -212,46 +210,34 @@ class TestTestTools(object):
assert 'gin' in flask.request.form assert 'gin' in flask.request.form
assert 'vodka' in flask.request.args assert 'vodka' in flask.request.args
def test_subdomain():
class TestSubdomain(object):
@pytest.fixture
def app(self, request):
app = flask.Flask(__name__) app = flask.Flask(__name__)
app.config['SERVER_NAME'] = 'example.com' app.config['SERVER_NAME'] = 'example.com'
ctx = app.test_request_context()
ctx.push()
def teardown():
if ctx is not None:
ctx.pop()
request.addfinalizer(teardown)
return app
@pytest.fixture
def client(self, app):
return app.test_client()
def test_subdomain(self, app, client):
@app.route('/', subdomain='<company_id>') @app.route('/', subdomain='<company_id>')
def view(company_id): def view(company_id):
return company_id return company_id
with app.test_request_context():
url = flask.url_for('view', company_id='xxx') url = flask.url_for('view', company_id='xxx')
response = client.get(url)
with app.test_client() as c:
response = c.get(url)
assert 200 == response.status_code assert 200 == response.status_code
assert b'xxx' == response.data assert b'xxx' == response.data
def test_nosubdomain():
def test_nosubdomain(self, app, client): app = flask.Flask(__name__)
app.config['SERVER_NAME'] = 'example.com'
@app.route('/<company_id>') @app.route('/<company_id>')
def view(company_id): def view(company_id):
return company_id return company_id
with app.test_request_context():
url = flask.url_for('view', company_id='xxx') url = flask.url_for('view', company_id='xxx')
response = client.get(url)
with app.test_client() as c:
response = c.get(url)
assert 200 == response.status_code assert 200 == response.status_code
assert b'xxx' == response.data assert b'xxx' == response.data