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):
self.assertTrue(x, msg)
def assert_false(self, x, msg=None):
self.assertFalse(x, msg)
def assert_in(self, 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'])
rv = c.head('/')
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.get('/more').data, b'GET')
rv = c.delete('/more')
@ -102,7 +102,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
self.assert_equal(sorted(rv.allow), ['GET', 'HEAD', 'OPTIONS'])
rv = c.head('/')
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.get('/more').data, b'GET')
rv = c.delete('/more')
@ -347,7 +347,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
app.secret_key = 'testkey'
with app.test_request_context():
self.assert_true(not flask.session.modified)
self.assert_false(flask.session.modified)
flask.flash('Zap')
flask.session.modified = False
flask.flash('Zip')
@ -967,7 +967,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
@app.route('/')
def index():
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')
try:
@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))
else:
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'}
self.assert_true(app.config.from_envvar('FOO_SETTINGS'))
@ -97,7 +97,7 @@ class ConfigTestCase(FlaskTestCase):
self.assert_true(msg.endswith("missing.cfg'"))
else:
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):
app = flask.Flask(__name__)

10
flask/testsuite/reqctx.py

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

2
flask/testsuite/testing.py

@ -152,7 +152,7 @@ class TestToolsTestCase(FlaskTestCase):
self.assert_equal(resp.status_code, 200)
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_equal(resp.status_code, 500)
flask.g.value = 23

Loading…
Cancel
Save