Skip to content

Commit

Permalink
Fight the generic asserts!
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed Aug 26, 2011
1 parent 2b830af commit 3069e2d
Show file tree
Hide file tree
Showing 8 changed files with 212 additions and 212 deletions.
212 changes: 106 additions & 106 deletions flask/testsuite/basic.py

Large diffs are not rendered by default.

74 changes: 37 additions & 37 deletions flask/testsuite/blueprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ def index():
return 'the index'
app.register_module(admin)
c = app.test_client()
assert c.get('/').data == 'the index'
assert c.get('/admin/').data == 'admin index'
assert c.get('/admin/login').data == 'admin login'
assert c.get('/admin/logout').data == 'admin logout'
self.assert_equal(c.get('/').data, 'the index')
self.assert_equal(c.get('/admin/').data, 'admin index')
self.assert_equal(c.get('/admin/login').data, 'admin login')
self.assert_equal(c.get('/admin/logout').data, 'admin logout')

@emits_module_deprecation_warning
def test_default_endpoint_name(self):
Expand All @@ -57,9 +57,9 @@ def index():
mod.add_url_rule('/', view_func=index)
app.register_module(mod)
rv = app.test_client().get('/')
assert rv.data == 'Awesome'
self.assert_equal(rv.data, 'Awesome')
with app.test_request_context():
assert flask.url_for('frontend.index') == '/'
self.assert_equal(flask.url_for('frontend.index'), '/')

@emits_module_deprecation_warning
def test_request_processing(self):
Expand Down Expand Up @@ -89,13 +89,13 @@ def index():
app.register_module(admin)
c = app.test_client()

assert c.get('/').data == 'the index'
assert catched == ['before-app', 'after-app']
self.assert_equal(c.get('/').data, 'the index')
self.assert_equal(catched, ['before-app', 'after-app'])
del catched[:]

assert c.get('/admin/').data == 'the admin'
assert catched == ['before-app', 'before-admin',
'after-admin', 'after-app']
self.assert_equal(c.get('/admin/').data, 'the admin')
self.assert_equal(catched, ['before-app', 'before-admin',
'after-admin', 'after-app'])

@emits_module_deprecation_warning
def test_context_processors(self):
Expand All @@ -118,8 +118,8 @@ def admin_index():
return flask.render_template_string('{{ a }}{{ b }}{{ c }}')
app.register_module(admin)
c = app.test_client()
assert c.get('/').data == '13'
assert c.get('/admin/').data == '123'
self.assert_equal(c.get('/').data, '13')
self.assert_equal(c.get('/admin/').data, '123')

@emits_module_deprecation_warning
def test_late_binding(self):
Expand All @@ -129,7 +129,7 @@ def test_late_binding(self):
def index():
return '42'
app.register_module(admin, url_prefix='/admin')
assert app.test_client().get('/admin/').data == '42'
self.assert_equal(app.test_client().get('/admin/').data, '42')

@emits_module_deprecation_warning
def test_error_handling(self):
Expand All @@ -150,27 +150,27 @@ def error():
app.register_module(admin)
c = app.test_client()
rv = c.get('/')
assert rv.status_code == 404
assert rv.data == 'not found'
self.assert_equal(rv.status_code, 404)
self.assert_equal(rv.data, 'not found')
rv = c.get('/error')
assert rv.status_code == 500
assert 'internal server error' == rv.data
self.assert_equal(rv.status_code, 500)
self.assert_equal('internal server error', rv.data)

def test_templates_and_static(self):
app = moduleapp
app.testing = True
c = app.test_client()

rv = c.get('/')
assert rv.data == 'Hello from the Frontend'
self.assert_equal(rv.data, 'Hello from the Frontend')
rv = c.get('/admin/')
assert rv.data == 'Hello from the Admin'
self.assert_equal(rv.data, 'Hello from the Admin')
rv = c.get('/admin/index2')
assert rv.data == 'Hello from the Admin'
self.assert_equal(rv.data, 'Hello from the Admin')
rv = c.get('/admin/static/test.txt')
assert rv.data.strip() == 'Admin File'
self.assert_equal(rv.data.strip(), 'Admin File')
rv = c.get('/admin/static/css/test.css')
assert rv.data.strip() == '/* nested file */'
self.assert_equal(rv.data.strip(), '/* nested file */')

with app.test_request_context():
assert flask.url_for('admin.static', filename='test.txt') \
Expand All @@ -180,12 +180,12 @@ def test_templates_and_static(self):
try:
flask.render_template('missing.html')
except TemplateNotFound, e:
assert e.name == 'missing.html'
self.assert_equal(e.name, 'missing.html')
else:
assert 0, 'expected exception'

with flask.Flask(__name__).test_request_context():
assert flask.render_template('nested/nested.txt') == 'I\'m nested'
self.assert_equal(flask.render_template('nested/nested.txt'), 'I\'m nested')

def test_safe_access(self):
app = moduleapp
Expand Down Expand Up @@ -245,8 +245,8 @@ def index():
app.register_module(module)

c = app.test_client()
assert c.get('/foo/').data == 'index'
assert c.get('/foo/bar').data == 'bar'
self.assert_equal(c.get('/foo/').data, 'index')
self.assert_equal(c.get('/foo/bar').data, 'bar')


class BlueprintTestCase(FlaskTestCase):
Expand Down Expand Up @@ -287,9 +287,9 @@ def app_forbidden(e):

c = app.test_client()

assert c.get('/frontend-no').data == 'frontend says no'
assert c.get('/backend-no').data == 'backend says no'
assert c.get('/what-is-a-sideend').data == 'application itself says no'
self.assert_equal(c.get('/frontend-no').data, 'frontend says no')
self.assert_equal(c.get('/backend-no').data, 'backend says no')
self.assert_equal(c.get('/what-is-a-sideend').data, 'application itself says no')

def test_blueprint_url_definitions(self):
bp = flask.Blueprint('test', __name__)
Expand Down Expand Up @@ -344,15 +344,15 @@ def test_templates_and_static(self):
c = app.test_client()

rv = c.get('/')
assert rv.data == 'Hello from the Frontend'
self.assert_equal(rv.data, 'Hello from the Frontend')
rv = c.get('/admin/')
assert rv.data == 'Hello from the Admin'
self.assert_equal(rv.data, 'Hello from the Admin')
rv = c.get('/admin/index2')
assert rv.data == 'Hello from the Admin'
self.assert_equal(rv.data, 'Hello from the Admin')
rv = c.get('/admin/static/test.txt')
assert rv.data.strip() == 'Admin File'
self.assert_equal(rv.data.strip(), 'Admin File')
rv = c.get('/admin/static/css/test.css')
assert rv.data.strip() == '/* nested file */'
self.assert_equal(rv.data.strip(), '/* nested file */')

with app.test_request_context():
assert flask.url_for('admin.static', filename='test.txt') \
Expand All @@ -362,12 +362,12 @@ def test_templates_and_static(self):
try:
flask.render_template('missing.html')
except TemplateNotFound, e:
assert e.name == 'missing.html'
self.assert_equal(e.name, 'missing.html')
else:
assert 0, 'expected exception'

with flask.Flask(__name__).test_request_context():
assert flask.render_template('nested/nested.txt') == 'I\'m nested'
self.assert_equal(flask.render_template('nested/nested.txt'), 'I\'m nested')

def test_templates_list(self):
from blueprintapp import app
Expand Down
4 changes: 2 additions & 2 deletions flask/testsuite/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
class ConfigTestCase(FlaskTestCase):

def common_object_test(self, app):
assert app.secret_key == 'devkey'
assert app.config['TEST_KEY'] == 'foo'
self.assert_equal(app.secret_key, 'devkey')
self.assert_equal(app.config['TEST_KEY'], 'foo')
assert 'ConfigTestCase' not in app.config

def test_config_from_file(self):
Expand Down
4 changes: 2 additions & 2 deletions flask/testsuite/deprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def foo():
return app.jinja_env.globals['foo']

c = app.test_client()
assert c.get('/').data == '42'
assert len(log) == 1
self.assert_equal(c.get('/').data, '42')
self.assert_equal(len(log), 1)
assert 'init_jinja_globals' in str(log[0]['message'])


Expand Down
Loading

0 comments on commit 3069e2d

Please sign in to comment.