Browse Source

Use assert_false where appropriate

pull/739/head
Daniel Neuhäuser 12 years ago
parent
commit
62e7275bdf
  1. 3
      flask/testsuite/__init__.py
  2. 8
      flask/testsuite/basic.py
  3. 4
      flask/testsuite/config.py
  4. 10
      flask/testsuite/reqctx.py
  5. 2
      flask/testsuite/testing.py

3
flask/testsuite/__init__.py

@ -145,6 +145,9 @@ class FlaskTestCase(unittest.TestCase):
def assert_true(self, x, msg=None): def assert_true(self, x, msg=None):
self.assertTrue(x, msg) self.assertTrue(x, msg)
def assert_false(self, x, msg=None):
self.assertFalse(x, msg)
def assert_in(self, x, y): def assert_in(self, x, y):
self.assertIn(x, y) self.assertIn(x, y)

8
flask/testsuite/basic.py

@ -78,7 +78,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
self.assert_equal(sorted(rv.allow), ['GET', 'HEAD', 'OPTIONS']) self.assert_equal(sorted(rv.allow), ['GET', 'HEAD', 'OPTIONS'])
rv = c.head('/') rv = c.head('/')
self.assert_equal(rv.status_code, 200) self.assert_equal(rv.status_code, 200)
self.assert_true(not rv.data) # head truncates self.assert_false(rv.data) # head truncates
self.assert_equal(c.post('/more').data, b'POST') self.assert_equal(c.post('/more').data, b'POST')
self.assert_equal(c.get('/more').data, b'GET') self.assert_equal(c.get('/more').data, b'GET')
rv = c.delete('/more') rv = c.delete('/more')
@ -102,7 +102,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
self.assert_equal(sorted(rv.allow), ['GET', 'HEAD', 'OPTIONS']) self.assert_equal(sorted(rv.allow), ['GET', 'HEAD', 'OPTIONS'])
rv = c.head('/') rv = c.head('/')
self.assert_equal(rv.status_code, 200) self.assert_equal(rv.status_code, 200)
self.assert_true(not rv.data) # head truncates self.assert_false(rv.data) # head truncates
self.assert_equal(c.post('/more').data, b'POST') self.assert_equal(c.post('/more').data, b'POST')
self.assert_equal(c.get('/more').data, b'GET') self.assert_equal(c.get('/more').data, b'GET')
rv = c.delete('/more') rv = c.delete('/more')
@ -347,7 +347,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
app.secret_key = 'testkey' app.secret_key = 'testkey'
with app.test_request_context(): with app.test_request_context():
self.assert_true(not flask.session.modified) self.assert_false(flask.session.modified)
flask.flash('Zap') flask.flash('Zap')
flask.session.modified = False flask.session.modified = False
flask.flash('Zip') flask.flash('Zip')
@ -967,7 +967,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
@app.route('/') @app.route('/')
def index(): def index():
return 'Awesome' return 'Awesome'
self.assert_true(not app.got_first_request) self.assert_false(app.got_first_request)
self.assert_equal(app.test_client().get('/').data, b'Awesome') self.assert_equal(app.test_client().get('/').data, b'Awesome')
try: try:
@app.route('/foo') @app.route('/foo')

4
flask/testsuite/config.py

@ -60,7 +60,7 @@ class ConfigTestCase(FlaskTestCase):
self.assert_true("'FOO_SETTINGS' is not set" in str(e)) self.assert_true("'FOO_SETTINGS' is not set" in str(e))
else: else:
self.assert_true(0, 'expected exception') self.assert_true(0, 'expected exception')
self.assert_true(not app.config.from_envvar('FOO_SETTINGS', silent=True)) self.assert_false(app.config.from_envvar('FOO_SETTINGS', silent=True))
os.environ = {'FOO_SETTINGS': __file__.rsplit('.', 1)[0] + '.py'} os.environ = {'FOO_SETTINGS': __file__.rsplit('.', 1)[0] + '.py'}
self.assert_true(app.config.from_envvar('FOO_SETTINGS')) self.assert_true(app.config.from_envvar('FOO_SETTINGS'))
@ -97,7 +97,7 @@ class ConfigTestCase(FlaskTestCase):
self.assert_true(msg.endswith("missing.cfg'")) self.assert_true(msg.endswith("missing.cfg'"))
else: else:
self.assert_true(0, 'expected config') self.assert_true(0, 'expected config')
self.assert_true(not app.config.from_pyfile('missing.cfg', silent=True)) self.assert_false(app.config.from_pyfile('missing.cfg', silent=True))
def test_session_lifetime(self): def test_session_lifetime(self):
app = flask.Flask(__name__) app = flask.Flask(__name__)

10
flask/testsuite/reqctx.py

@ -97,8 +97,8 @@ class RequestContextTestCase(FlaskTestCase):
def test_context_test(self): def test_context_test(self):
app = flask.Flask(__name__) app = flask.Flask(__name__)
self.assert_true(not flask.request) self.assert_false(flask.request)
self.assert_true(not flask.has_request_context()) self.assert_false(flask.has_request_context())
ctx = app.test_request_context() ctx = app.test_request_context()
ctx.push() ctx.push()
try: try:
@ -132,14 +132,14 @@ class RequestContextTestCase(FlaskTestCase):
def index(): def index():
reqctx = flask._request_ctx_stack.top.copy() reqctx = flask._request_ctx_stack.top.copy()
def g(): def g():
self.assert_true(not flask.request) self.assert_false(flask.request)
self.assert_true(not flask.current_app) self.assert_false(flask.current_app)
with reqctx: with reqctx:
self.assert_true(flask.request) self.assert_true(flask.request)
self.assert_equal(flask.current_app, app) self.assert_equal(flask.current_app, app)
self.assert_equal(flask.request.path, '/') self.assert_equal(flask.request.path, '/')
self.assert_equal(flask.request.args['foo'], 'bar') self.assert_equal(flask.request.args['foo'], 'bar')
self.assert_true(not flask.request) self.assert_false(flask.request)
return 42 return 42
greenlets.append(greenlet(g)) greenlets.append(greenlet(g))
return 'Hello World!' return 'Hello World!'

2
flask/testsuite/testing.py

@ -152,7 +152,7 @@ class TestToolsTestCase(FlaskTestCase):
self.assert_equal(resp.status_code, 200) self.assert_equal(resp.status_code, 200)
resp = c.get('/other') resp = c.get('/other')
self.assert_true(not hasattr(flask.g, 'value')) self.assert_false(hasattr(flask.g, 'value'))
self.assert_in(b'Internal Server Error', resp.data) self.assert_in(b'Internal Server Error', resp.data)
self.assert_equal(resp.status_code, 500) self.assert_equal(resp.status_code, 500)
flask.g.value = 23 flask.g.value = 23

Loading…
Cancel
Save