Browse Source

Kill classes in test_testing

pull/1165/head
Markus Unterwaditzer 11 years ago
parent
commit
f8a778deae
  1. 60
      tests/test_testing.py

60
tests/test_testing.py

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

Loading…
Cancel
Save