Fight the generic asserts!
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Armin Ronacher · committed by Armin Ronacher · parent 2b830af · Browse files · 8 files·+212 added−212 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
8 files+212 added−212 removed
- other:+212 added−212 removed
Provenance
- Commit
3069e2d- Tree
0ad8cbc- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
2b830af
8 files changed+212 added−212 removed
modified:flask/testsuite/basic.py+106 added-106 removed
24 unmodified lines25 @app.route('/', methods=['GET', 'POST'])26 def index():27 return 'Hello World'28 rv = app.test_client().open('/', method='OPTIONS')29- assert sorted(rv.allow) == ['GET', 'HEAD', 'OPTIONS', 'POST']30- assert rv.data == ''29+ self.assert_equal(sorted(rv.allow), ['GET', 'HEAD', 'OPTIONS', 'POST'])30+ self.assert_equal(rv.data, '')31 32 def test_options_on_multiple_rules(self):33 app = flask.Flask(__name__)34 @app.route('/', methods=['GET', 'POST'])2 unmodified lines37 @app.route('/', methods=['PUT'])38 def index_put():39 return 'Aha!'40 rv = app.test_client().open('/', method='OPTIONS')41- assert sorted(rv.allow) == ['GET', 'HEAD', 'OPTIONS', 'POST', 'PUT']41+ self.assert_equal(sorted(rv.allow), ['GET', 'HEAD', 'OPTIONS', 'POST', 'PUT'])42 43 def test_options_handling_disabled(self):44 app = flask.Flask(__name__)45 def index():46 return 'Hello World!'47 index.provide_automatic_options = False48 app.route('/')(index)49 rv = app.test_client().open('/', method='OPTIONS')50- assert rv.status_code == 40550+ self.assert_equal(rv.status_code, 405)51 52 app = flask.Flask(__name__)53 def index2():54 return 'Hello World!'55 index2.provide_automatic_options = True56 app.route('/', methods=['OPTIONS'])(index2)57 rv = app.test_client().open('/', method='OPTIONS')58- assert sorted(rv.allow) == ['OPTIONS']58+ self.assert_equal(sorted(rv.allow), ['OPTIONS'])59 60 def test_request_dispatching(self):61 app = flask.Flask(__name__)62 @app.route('/')3 unmodified lines66 def more():67 return flask.request.method68 69 c = app.test_client()70- assert c.get('/').data == 'GET'70+ self.assert_equal(c.get('/').data, 'GET')71 rv = c.post('/')72- assert rv.status_code == 40573- assert sorted(rv.allow) == ['GET', 'HEAD', 'OPTIONS']72+ self.assert_equal(rv.status_code, 405)73+ self.assert_equal(sorted(rv.allow), ['GET', 'HEAD', 'OPTIONS'])74 rv = c.head('/')75- assert rv.status_code == 20075+ self.assert_equal(rv.status_code, 200)76 assert not rv.data # head truncates77- assert c.post('/more').data == 'POST'78- assert c.get('/more').data == 'GET'77+ self.assert_equal(c.post('/more').data, 'POST')78+ self.assert_equal(c.get('/more').data, 'GET')79 rv = c.delete('/more')80- assert rv.status_code == 40581- assert sorted(rv.allow) == ['GET', 'HEAD', 'OPTIONS', 'POST']80+ self.assert_equal(rv.status_code, 405)81+ self.assert_equal(sorted(rv.allow), ['GET', 'HEAD', 'OPTIONS', 'POST'])82 83 def test_url_mapping(self):84 app = flask.Flask(__name__)85 def index():4 unmodified lines90 app.add_url_rule('/', 'index', index)91 app.add_url_rule('/more', 'more', more, methods=['GET', 'POST'])92 93 c = app.test_client()94- assert c.get('/').data == 'GET'94+ self.assert_equal(c.get('/').data, 'GET')95 rv = c.post('/')96- assert rv.status_code == 40597- assert sorted(rv.allow) == ['GET', 'HEAD', 'OPTIONS']96+ self.assert_equal(rv.status_code, 405)97+ self.assert_equal(sorted(rv.allow), ['GET', 'HEAD', 'OPTIONS'])98 rv = c.head('/')99- assert rv.status_code == 20099+ self.assert_equal(rv.status_code, 200)100 assert not rv.data # head truncates101- assert c.post('/more').data == 'POST'102- assert c.get('/more').data == 'GET'101+ self.assert_equal(c.post('/more').data, 'POST')102+ self.assert_equal(c.get('/more').data, 'GET')103 rv = c.delete('/more')104- assert rv.status_code == 405105- assert sorted(rv.allow) == ['GET', 'HEAD', 'OPTIONS', 'POST']104+ self.assert_equal(rv.status_code, 405)105+ self.assert_equal(sorted(rv.allow), ['GET', 'HEAD', 'OPTIONS', 'POST'])106 107 def test_werkzeug_routing(self):108 from werkzeug.routing import Submount, Rule109 app = flask.Flask(__name__)8 unmodified lines118 app.view_functions['bar'] = bar119 app.view_functions['index'] = index120 121 c = app.test_client()122- assert c.get('/foo/').data == 'index'123- assert c.get('/foo/bar').data == 'bar'122+ self.assert_equal(c.get('/foo/').data, 'index')123+ self.assert_equal(c.get('/foo/bar').data, 'bar')124 125 def test_endpoint_decorator(self):126 from werkzeug.routing import Submount, Rule127 app = flask.Flask(__name__)10 unmodified lines138 def index():139 return 'index'140 141 c = app.test_client()142- assert c.get('/foo/').data == 'index'143- assert c.get('/foo/bar').data == 'bar'142+ self.assert_equal(c.get('/foo/').data, 'index')143+ self.assert_equal(c.get('/foo/bar').data, 'bar')144 145 def test_session(self):146 app = flask.Flask(__name__)147 app.secret_key = 'testkey'5 unmodified lines153 def get():154 return flask.session['value']155 156 c = app.test_client()157- assert c.post('/set', data={'value': '42'}).data == 'value set'158- assert c.get('/get').data == '42'157+ self.assert_equal(c.post('/set', data={'value': '42'}).data, 'value set')158+ self.assert_equal(c.get('/get').data, '42')159 160 def test_session_using_server_name(self):161 app = flask.Flask(__name__)162 app.config.update(77 unmodified lines240 assert 'set-cookie' in rv.headers241 match = re.search(r'\bexpires=([^;]+)', rv.headers['set-cookie'])242 expires = parse_date(match.group())243 expected = datetime.utcnow() + app.permanent_session_lifetime244- assert expires.year == expected.year245- assert expires.month == expected.month246- assert expires.day == expected.day244+ self.assert_equal(expires.year, expected.year)245+ self.assert_equal(expires.month, expected.month)246+ self.assert_equal(expires.day, expected.day)247 248 rv = client.get('/test')249- assert rv.data == 'True'249+ self.assert_equal(rv.data, 'True')250 251 permanent = False252 rv = app.test_client().get('/')253 assert 'set-cookie' in rv.headers9 unmodified lines263 flask.flash('Zap')264 flask.session.modified = False265 flask.flash('Zip')266 assert flask.session.modified267- assert list(flask.get_flashed_messages()) == ['Zap', 'Zip']267+ self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip'])268 269 def test_extended_flashing(self):270 app = flask.Flask(__name__)271 app.secret_key = 'testkey'7 unmodified lines279 280 @app.route('/test')281 def test():282 messages = flask.get_flashed_messages(with_categories=True)283- assert len(messages) == 3284- assert messages[0] == ('message', u'Hello World')285- assert messages[1] == ('error', u'Hello World')286- assert messages[2] == ('warning', flask.Markup(u'<em>Testing</em>'))283+ self.assert_equal(len(messages), 3)284+ self.assert_equal(messages[0], ('message', u'Hello World'))285+ self.assert_equal(messages[1], ('error', u'Hello World'))286+ self.assert_equal(messages[2], ('warning', flask.Markup(u'<em>Testing</em>')))287 return ''288 messages = flask.get_flashed_messages()289- assert len(messages) == 3290- assert messages[0] == u'Hello World'291- assert messages[1] == u'Hello World'292- assert messages[2] == flask.Markup(u'<em>Testing</em>')289+ self.assert_equal(len(messages), 3)290+ self.assert_equal(messages[0], u'Hello World')291+ self.assert_equal(messages[1], u'Hello World')292+ self.assert_equal(messages[2], flask.Markup(u'<em>Testing</em>'))293 294 c = app.test_client()295 c.get('/')296 c.get('/test')16 unmodified lines313 return 'request'314 assert 'after' not in evts315 rv = app.test_client().get('/').data316 assert 'after' in evts317- assert rv == 'request|after'317+ self.assert_equal(rv, 'request|after')318 319 def test_teardown_request_handler(self):320 called = []321 app = flask.Flask(__name__)4 unmodified lines326 @app.route('/')327 def root():328 return "Response"329 rv = app.test_client().get('/')330- assert rv.status_code == 200330+ self.assert_equal(rv.status_code, 200)331 assert 'Response' in rv.data332- assert len(called) == 1332+ self.assert_equal(len(called), 1)333 334 def test_teardown_request_handler_debug_mode(self):335 called = []336 app = flask.Flask(__name__)5 unmodified lines342 @app.route('/')343 def root():344 return "Response"345 rv = app.test_client().get('/')346- assert rv.status_code == 200346+ self.assert_equal(rv.status_code, 200)347 assert 'Response' in rv.data348- assert len(called) == 1348+ self.assert_equal(len(called), 1)349 350 def test_teardown_request_handler_error(self):351 called = []352 app = flask.Flask(__name__)353 @app.teardown_request354 def teardown_request1(exc):355- assert type(exc) == ZeroDivisionError355+ self.assert_equal(type(exc), ZeroDivisionError)356 called.append(True)357 # This raises a new error and blows away sys.exc_info(), so we can358 # test that all teardown_requests get passed the same original359 # exception.2 unmodified lines362 except:363 pass364 @app.teardown_request365 def teardown_request2(exc):366- assert type(exc) == ZeroDivisionError366+ self.assert_equal(type(exc), ZeroDivisionError)367 called.append(True)368 # This raises a new error and blows away sys.exc_info(), so we can369 # test that all teardown_requests get passed the same original370 # exception.4 unmodified lines375 @app.route('/')376 def fails():377 1/0378 rv = app.test_client().get('/')379- assert rv.status_code == 500379+ self.assert_equal(rv.status_code, 500)380 assert 'Internal Server Error' in rv.data381- assert len(called) == 2381+ self.assert_equal(len(called), 2)382 383 def test_before_after_request_order(self):384 called = []385 app = flask.Flask(__name__)20 unmodified lines406 @app.route('/')407 def index():408 return '42'409 rv = app.test_client().get('/')410- assert rv.data == '42'411- assert called == [1, 2, 3, 4, 5, 6]410+ self.assert_equal(rv.data, '42')411+ self.assert_equal(called, [1, 2, 3, 4, 5, 6])412 413 def test_error_handling(self):414 app = flask.Flask(__name__)415 @app.errorhandler(404)9 unmodified lines425 def error():426 1 // 0427 c = app.test_client()428 rv = c.get('/')429- assert rv.status_code == 404430- assert rv.data == 'not found'429+ self.assert_equal(rv.status_code, 404)430+ self.assert_equal(rv.data, 'not found')431 rv = c.get('/error')432- assert rv.status_code == 500433- assert 'internal server error' == rv.data432+ self.assert_equal(rv.status_code, 500)433+ self.assert_equal('internal server error', rv.data)434 435 def test_before_request_and_routing_errors(self):436 app = flask.Flask(__name__)437 @app.before_request2 unmodified lines440 @app.errorhandler(404)441 def return_something(error):442 return flask.g.something, 404443 rv = app.test_client().get('/')444- assert rv.status_code == 404445- assert rv.data == 'value'444+ self.assert_equal(rv.status_code, 404)445+ self.assert_equal(rv.data, 'value')446 447 def test_user_error_handling(self):448 class MyException(Exception):449 pass7 unmodified lines457 def index():458 raise MyException()459 460 c = app.test_client()461- assert c.get('/').data == '42'461+ self.assert_equal(c.get('/').data, '42')462 463 def test_trapping_of_bad_request_key_errors(self):464 app = flask.Flask(__name__)465 app.testing = True466 @app.route('/fail')467 def fail():468 flask.request.form['missing_key']469 c = app.test_client()470- assert c.get('/fail').status_code == 400470+ self.assert_equal(c.get('/fail').status_code, 400)471 472 app.config['TRAP_BAD_REQUEST_ERRORS'] = True473 c = app.test_client()474 try:47 unmodified lines522 buffer.append(exception)523 524 ctx = app.test_request_context()525 ctx.push()526- assert buffer == []526+ self.assert_equal(buffer, [])527 ctx.pop()528- assert buffer == [None]528+ self.assert_equal(buffer, [None])529 530 def test_response_creation(self):531 app = flask.Flask(__name__)532 @app.route('/unicode')5 unmodified lines538 @app.route('/args')539 def from_tuple():540 return 'Meh', 400, {'X-Foo': 'Testing'}, 'text/plain'541 c = app.test_client()542- assert c.get('/unicode').data == u'Hällo Wörld'.encode('utf-8')543- assert c.get('/string').data == u'Hällo Wörld'.encode('utf-8')542+ self.assert_equal(c.get('/unicode').data, u'Hällo Wörld'.encode('utf-8'))543+ self.assert_equal(c.get('/string').data, u'Hällo Wörld'.encode('utf-8'))544 rv = c.get('/args')545- assert rv.data == 'Meh'546- assert rv.headers['X-Foo'] == 'Testing'547- assert rv.status_code == 400548- assert rv.mimetype == 'text/plain'545+ self.assert_equal(rv.data, 'Meh')546+ self.assert_equal(rv.headers['X-Foo'], 'Testing')547+ self.assert_equal(rv.status_code, 400)548+ self.assert_equal(rv.mimetype, 'text/plain')549 550 def test_make_response(self):551 app = flask.Flask(__name__)552 with app.test_request_context():553 rv = flask.make_response()554- assert rv.status_code == 200555- assert rv.data == ''556- assert rv.mimetype == 'text/html'554+ self.assert_equal(rv.status_code, 200)555+ self.assert_equal(rv.data, '')556+ self.assert_equal(rv.mimetype, 'text/html')557 558 rv = flask.make_response('Awesome')559- assert rv.status_code == 200560- assert rv.data == 'Awesome'561- assert rv.mimetype == 'text/html'559+ self.assert_equal(rv.status_code, 200)560+ self.assert_equal(rv.data, 'Awesome')561+ self.assert_equal(rv.mimetype, 'text/html')562 563 rv = flask.make_response('W00t', 404)564- assert rv.status_code == 404565- assert rv.data == 'W00t'566- assert rv.mimetype == 'text/html'564+ self.assert_equal(rv.status_code, 404)565+ self.assert_equal(rv.data, 'W00t')566+ self.assert_equal(rv.mimetype, 'text/html')567 568 def test_url_generation(self):569 app = flask.Flask(__name__)570 @app.route('/hello/<name>', methods=['POST'])571 def hello():572 pass573 with app.test_request_context():574- assert flask.url_for('hello', name='test x') == '/hello/test%20x'574+ self.assert_equal(flask.url_for('hello', name='test x'), '/hello/test%20x')575 assert flask.url_for('hello', name='test x', _external=True) \576 == 'http://localhost/hello/test%20x'577 578 def test_custom_converters(self):9 unmodified lines588 @app.route('/<list:args>')589 def index(args):590 return '|'.join(args)591 c = app.test_client()592- assert c.get('/1,2,3').data == '1|2|3'592+ self.assert_equal(c.get('/1,2,3').data, '1|2|3')593 594 def test_static_files(self):595 app = flask.Flask(__name__)596 rv = app.test_client().get('/static/index.html')597- assert rv.status_code == 200598- assert rv.data.strip() == '<h1>Hello World!</h1>'597+ self.assert_equal(rv.status_code, 200)598+ self.assert_equal(rv.data.strip(), '<h1>Hello World!</h1>')599 with app.test_request_context():600 assert flask.url_for('static', filename='index.html') \601 == '/static/index.html'602 4 unmodified lines607 return None608 try:609 app.test_client().get('/')610 except ValueError, e:611- assert str(e) == 'View function did not return a response'611+ self.assert_equal(str(e), 'View function did not return a response')612 pass613 else:614 assert "Expected ValueError"615 15 unmodified lines631 def sub():632 return None633 634 with app.test_request_context('/'):635- assert flask.url_for('index', _external=True) == 'http://localhost.localdomain:5000/'635+ self.assert_equal(flask.url_for('index', _external=True), 'http://localhost.localdomain:5000/')636 637 with app.test_request_context('/'):638- assert flask.url_for('sub', _external=True) == 'http://foo.localhost.localdomain:5000/'638+ self.assert_equal(flask.url_for('sub', _external=True), 'http://foo.localhost.localdomain:5000/')639 640 try:641 with app.test_request_context('/', environ_overrides={'HTTP_HOST': 'localhost'}):642 pass643 except Exception, e:644 assert isinstance(e, ValueError)645- assert str(e) == "the server name provided " + \645+ self.assert_equal(str(e), "the server name provided " +646 "('localhost.localdomain:5000') does not match the " + \647- "server name from the WSGI environment ('localhost')", str(e)647+ "server name from the WSGI environment ('localhost')")648 649 try:650 app.config.update(SERVER_NAME='localhost')651 with app.test_request_context('/', environ_overrides={'SERVER_NAME': 'localhost'}):26 unmodified lines678 return 'Foo SubDomain'679 680 try:681 rv = app.test_client().get('/')682- assert rv.data == 'Foo'682+ self.assert_equal(rv.data, 'Foo')683 except ValueError, e:684 raise ValueError(685 "No ValueError exception should have been raised \"%s\"" % e686 )687 688 try:689 rv = app.test_client().get('/', 'http://localhost.localdomain:5000')690- assert rv.data == 'Foo'690+ self.assert_equal(rv.data, 'Foo')691 except ValueError, e:692 raise ValueError(693 "No ValueError exception should have been raised \"%s\"" % e694 )695 696 try:697 rv = app.test_client().get('/', 'https://localhost.localdomain:5000')698- assert rv.data == 'Foo'698+ self.assert_equal(rv.data, 'Foo')699 except ValueError, e:700 raise ValueError(701 "No ValueError exception should have been raised \"%s\"" % e702 )703 704 try:705 app.config.update(SERVER_NAME='localhost.localdomain')706 rv = app.test_client().get('/', 'https://localhost.localdomain')707- assert rv.data == 'Foo'707+ self.assert_equal(rv.data, 'Foo')708 except ValueError, e:709 raise ValueError(710 "No ValueError exception should have been raised \"%s\"" % e711 )712 713 try:714 app.config.update(SERVER_NAME='localhost.localdomain:443')715 rv = app.test_client().get('/', 'https://localhost.localdomain')716- assert rv.data == 'Foo'716+ self.assert_equal(rv.data, 'Foo')717 except ValueError, e:718- assert str(e) == "the server name provided " + \718+ self.assert_equal(str(e), "the server name provided " +719 "('localhost.localdomain:443') does not match the " + \720- "server name from the WSGI environment ('localhost.localdomain')", str(e)720+ "server name from the WSGI environment ('localhost.localdomain')")721 722 try:723 app.config.update(SERVER_NAME='localhost.localdomain')724 app.test_client().get('/', 'http://foo.localhost')725 except ValueError, e:726- assert str(e) == "the server name provided " + \726+ self.assert_equal(str(e), "the server name provided " + \727 "('localhost.localdomain') does not match the " + \728- "server name from the WSGI environment ('foo.localhost')", str(e)728+ "server name from the WSGI environment ('foo.localhost')")729 730 try:731 rv = app.test_client().get('/', 'http://foo.localhost.localdomain')732- assert rv.data == 'Foo SubDomain'732+ self.assert_equal(rv.data, 'Foo SubDomain')733 except ValueError, e:734 raise ValueError(735 "No ValueError exception should have been raised \"%s\"" % e736 )13 unmodified lines750 pass751 else:752 self.fail('expected exception')753 else:754- assert c.get('/').status_code == 500754+ self.assert_equal(c.get('/').status_code, 500)755 756 # we have to run this test in an isolated thread because if the757 # debug flag is set to true and an exception happens the context is758 # not torn down. This causes other tests that run after this fail19 unmodified lines778 return '42'779 780 c = app.test_client()781 rv = c.post('/accept', data={'myfile': 'foo' * 100})782- assert rv.data == '42'782+ self.assert_equal(rv.data, '42')783 784 def test_url_processors(self):785 app = flask.Flask(__name__)786 98 unmodified lines885 def meh():886 return flask.request.url887 888 with app.test_request_context('/?name=World'):889- assert index() == 'Hello World!'889+ self.assert_equal(index(), 'Hello World!')890 with app.test_request_context('/meh'):891- assert meh() == 'http://localhost/meh'891+ self.assert_equal(meh(), 'http://localhost/meh')892 assert flask._request_ctx_stack.top is None893 894 def test_context_test(self):895 app = flask.Flask(__name__)14 unmodified lines910 return 'Hello %s!' % flask.request.args['name']911 912 ctx = app.test_request_context('/?name=World')913 ctx.push()914- assert index() == 'Hello World!'914+ self.assert_equal(index(), 'Hello World!')915 ctx.pop()916 try:917 index()918 except RuntimeError:15 unmodified lines934 return 'test index'935 936 c = app.test_client()937 rv = c.get('/', 'http://localhost/')938- assert rv.data == 'normal index'938+ self.assert_equal(rv.data, 'normal index')939 940 rv = c.get('/', 'http://test.localhost/')941- assert rv.data == 'test index'941+ self.assert_equal(rv.data, 'test index')942 943 @emits_module_deprecation_warning944 def test_module_static_path_subdomain(self):945 app = flask.Flask(__name__)1 unmodified line947 from subdomaintestmodule import mod948 app.register_module(mod)949 c = app.test_client()950 rv = c.get('/static/hello.txt', 'http://foo.example.com/')951- assert rv.data.strip() == 'Hello Subdomain'951+ self.assert_equal(rv.data.strip(), 'Hello Subdomain')952 953 def test_subdomain_matching(self):954 app = flask.Flask(__name__)955 app.config['SERVER_NAME'] = 'localhost'2 unmodified lines958 return 'index for %s' % user959 960 c = app.test_client()961 rv = c.get('/', 'http://mitsuhiko.localhost/')962- assert rv.data == 'index for mitsuhiko'962+ self.assert_equal(rv.data, 'index for mitsuhiko')963 964 @emits_module_deprecation_warning965 def test_module_subdomain_support(self):966 app = flask.Flask(__name__)11 unmodified lines978 app.register_module(mod)979 980 c = app.test_client()981 rv = c.get('/test', 'http://testing.localhost/')982- assert rv.data == 'Test'982+ self.assert_equal(rv.data, 'Test')983 rv = c.get('/outside', 'http://xtesting.localhost/')984- assert rv.data == 'Outside'984+ self.assert_equal(rv.data, 'Outside')985 986 987 def suite():988 suite = unittest.TestSuite()4 unmodified linesmodified:flask/testsuite/blueprints.py+37 added-37 removed
41 unmodified lines42 def index():43 return 'the index'44 app.register_module(admin)45 c = app.test_client()46- assert c.get('/').data == 'the index'47- assert c.get('/admin/').data == 'admin index'48- assert c.get('/admin/login').data == 'admin login'49- assert c.get('/admin/logout').data == 'admin logout'46+ self.assert_equal(c.get('/').data, 'the index')47+ self.assert_equal(c.get('/admin/').data, 'admin index')48+ self.assert_equal(c.get('/admin/login').data, 'admin login')49+ self.assert_equal(c.get('/admin/logout').data, 'admin logout')50 51 @emits_module_deprecation_warning52 def test_default_endpoint_name(self):53 app = flask.Flask(__name__)2 unmodified lines56 return 'Awesome'57 mod.add_url_rule('/', view_func=index)58 app.register_module(mod)59 rv = app.test_client().get('/')60- assert rv.data == 'Awesome'60+ self.assert_equal(rv.data, 'Awesome')61 with app.test_request_context():62- assert flask.url_for('frontend.index') == '/'62+ self.assert_equal(flask.url_for('frontend.index'), '/')63 64 @emits_module_deprecation_warning65 def test_request_processing(self):66 catched = []21 unmodified lines88 return 'the index'89 app.register_module(admin)90 c = app.test_client()91 92- assert c.get('/').data == 'the index'93- assert catched == ['before-app', 'after-app']92+ self.assert_equal(c.get('/').data, 'the index')93+ self.assert_equal(catched, ['before-app', 'after-app'])94 del catched[:]95 96- assert c.get('/admin/').data == 'the admin'97- assert catched == ['before-app', 'before-admin',98- 'after-admin', 'after-app']96+ self.assert_equal(c.get('/admin/').data, 'the admin')97+ self.assert_equal(catched, ['before-app', 'before-admin',98+ 'after-admin', 'after-app'])99 100 @emits_module_deprecation_warning101 def test_context_processors(self):102 app = flask.Flask(__name__)14 unmodified lines117 def admin_index():118 return flask.render_template_string('{{ a }}{{ b }}{{ c }}')119 app.register_module(admin)120 c = app.test_client()121- assert c.get('/').data == '13'122- assert c.get('/admin/').data == '123'121+ self.assert_equal(c.get('/').data, '13')122+ self.assert_equal(c.get('/admin/').data, '123')123 124 @emits_module_deprecation_warning125 def test_late_binding(self):126 app = flask.Flask(__name__)1 unmodified line128 @admin.route('/')129 def index():130 return '42'131 app.register_module(admin, url_prefix='/admin')132- assert app.test_client().get('/admin/').data == '42'132+ self.assert_equal(app.test_client().get('/admin/').data, '42')133 134 @emits_module_deprecation_warning135 def test_error_handling(self):136 app = flask.Flask(__name__)12 unmodified lines149 1 // 0150 app.register_module(admin)151 c = app.test_client()152 rv = c.get('/')153- assert rv.status_code == 404154- assert rv.data == 'not found'153+ self.assert_equal(rv.status_code, 404)154+ self.assert_equal(rv.data, 'not found')155 rv = c.get('/error')156- assert rv.status_code == 500157- assert 'internal server error' == rv.data156+ self.assert_equal(rv.status_code, 500)157+ self.assert_equal('internal server error', rv.data)158 159 def test_templates_and_static(self):160 app = moduleapp161 app.testing = True162 c = app.test_client()163 164 rv = c.get('/')165- assert rv.data == 'Hello from the Frontend'165+ self.assert_equal(rv.data, 'Hello from the Frontend')166 rv = c.get('/admin/')167- assert rv.data == 'Hello from the Admin'167+ self.assert_equal(rv.data, 'Hello from the Admin')168 rv = c.get('/admin/index2')169- assert rv.data == 'Hello from the Admin'169+ self.assert_equal(rv.data, 'Hello from the Admin')170 rv = c.get('/admin/static/test.txt')171- assert rv.data.strip() == 'Admin File'171+ self.assert_equal(rv.data.strip(), 'Admin File')172 rv = c.get('/admin/static/css/test.css')173- assert rv.data.strip() == '/* nested file */'173+ self.assert_equal(rv.data.strip(), '/* nested file */')174 175 with app.test_request_context():176 assert flask.url_for('admin.static', filename='test.txt') \177 == '/admin/static/test.txt'1 unmodified line179 with app.test_request_context():180 try:181 flask.render_template('missing.html')182 except TemplateNotFound, e:183- assert e.name == 'missing.html'183+ self.assert_equal(e.name, 'missing.html')184 else:185 assert 0, 'expected exception'186 187 with flask.Flask(__name__).test_request_context():188- assert flask.render_template('nested/nested.txt') == 'I\'m nested'188+ self.assert_equal(flask.render_template('nested/nested.txt'), 'I\'m nested')189 190 def test_safe_access(self):191 app = moduleapp192 51 unmodified lines244 245 app.register_module(module)246 247 c = app.test_client()248- assert c.get('/foo/').data == 'index'249- assert c.get('/foo/bar').data == 'bar'248+ self.assert_equal(c.get('/foo/').data, 'index')249+ self.assert_equal(c.get('/foo/bar').data, 'bar')250 251 252 class BlueprintTestCase(FlaskTestCase):253 32 unmodified lines286 return 'application itself says no', 403287 288 c = app.test_client()289 290- assert c.get('/frontend-no').data == 'frontend says no'291- assert c.get('/backend-no').data == 'backend says no'292- assert c.get('/what-is-a-sideend').data == 'application itself says no'290+ self.assert_equal(c.get('/frontend-no').data, 'frontend says no')291+ self.assert_equal(c.get('/backend-no').data, 'backend says no')292+ self.assert_equal(c.get('/what-is-a-sideend').data, 'application itself says no')293 294 def test_blueprint_url_definitions(self):295 bp = flask.Blueprint('test', __name__)296 46 unmodified lines343 from blueprintapp import app344 c = app.test_client()345 346 rv = c.get('/')347- assert rv.data == 'Hello from the Frontend'347+ self.assert_equal(rv.data, 'Hello from the Frontend')348 rv = c.get('/admin/')349- assert rv.data == 'Hello from the Admin'349+ self.assert_equal(rv.data, 'Hello from the Admin')350 rv = c.get('/admin/index2')351- assert rv.data == 'Hello from the Admin'351+ self.assert_equal(rv.data, 'Hello from the Admin')352 rv = c.get('/admin/static/test.txt')353- assert rv.data.strip() == 'Admin File'353+ self.assert_equal(rv.data.strip(), 'Admin File')354 rv = c.get('/admin/static/css/test.css')355- assert rv.data.strip() == '/* nested file */'355+ self.assert_equal(rv.data.strip(), '/* nested file */')356 357 with app.test_request_context():358 assert flask.url_for('admin.static', filename='test.txt') \359 == '/admin/static/test.txt'1 unmodified line361 with app.test_request_context():362 try:363 flask.render_template('missing.html')364 except TemplateNotFound, e:365- assert e.name == 'missing.html'365+ self.assert_equal(e.name, 'missing.html')366 else:367 assert 0, 'expected exception'368 369 with flask.Flask(__name__).test_request_context():370- assert flask.render_template('nested/nested.txt') == 'I\'m nested'370+ self.assert_equal(flask.render_template('nested/nested.txt'), 'I\'m nested')371 372 def test_templates_list(self):373 from blueprintapp import app374 templates = sorted(app.jinja_env.list_templates())49 unmodified linesmodified:flask/testsuite/config.py+2 added-2 removed
21 unmodified lines22 23 class ConfigTestCase(FlaskTestCase):24 25 def common_object_test(self, app):26- assert app.secret_key == 'devkey'27- assert app.config['TEST_KEY'] == 'foo'26+ self.assert_equal(app.secret_key, 'devkey')27+ self.assert_equal(app.config['TEST_KEY'], 'foo')28 assert 'ConfigTestCase' not in app.config29 30 def test_config_from_file(self):31 app = flask.Flask(__name__)146 unmodified linesmodified:flask/testsuite/deprecations.py+2 added-2 removed
25 unmodified lines26 def foo():27 return app.jinja_env.globals['foo']28 29 c = app.test_client()30- assert c.get('/').data == '42'31- assert len(log) == 130+ self.assert_equal(c.get('/').data, '42')31+ self.assert_equal(len(log), 1)32 assert 'init_jinja_globals' in str(log[0]['message'])33 34 35 def suite():3 unmodified linesmodified:flask/testsuite/helpers.py+39 added-39 removed
45 unmodified lines46 47 c = app.test_client()48 resp = c.get('/', data=u'"Hällo Wörld"'.encode('iso-8859-15'),49 content_type='application/json; charset=iso-8859-15')50- assert resp.data == u'Hällo Wörld'.encode('utf-8')50+ self.assert_equal(resp.data, u'Hällo Wörld'.encode('utf-8'))51 52 def test_jsonify(self):53 d = dict(a=23, b=42, c=[1, 2, 3])54 app = flask.Flask(__name__)5 unmodified lines60 return flask.jsonify(d)61 c = app.test_client()62 for url in '/kw', '/dict':63 rv = c.get(url)64- assert rv.mimetype == 'application/json'65- assert flask.json.loads(rv.data) == d64+ self.assert_equal(rv.mimetype, 'application/json')65+ self.assert_equal(flask.json.loads(rv.data), d)66 67 def test_json_attr(self):68 app = flask.Flask(__name__)69 @app.route('/add', methods=['POST'])1 unmodified line71 return unicode(flask.request.json['a'] + flask.request.json['b'])72 c = app.test_client()73 rv = c.post('/add', data=flask.json.dumps({'a': 1, 'b': 2}),74 content_type='application/json')75- assert rv.data == '3'75+ self.assert_equal(rv.data, '3')76 77 def test_template_escaping(self):78 app = flask.Flask(__name__)79 render = flask.render_template_string80 with app.test_request_context():81 rv = render('{{ "</script>"|tojson|safe }}')82- assert rv == '"<\\/script>"'82+ self.assert_equal(rv, '"<\\/script>"')83 rv = render('{{ "<\0/script>"|tojson|safe }}')84- assert rv == '"<\\u0000\\/script>"'84+ self.assert_equal(rv, '"<\\u0000\\/script>"')85 86 def test_modified_url_encoding(self):87 class ModifiedRequest(flask.Request):88 url_charset = 'euc-kr'5 unmodified lines94 def index():95 return flask.request.args['foo']96 97 rv = app.test_client().get(u'/?foo=정상처리'.encode('euc-kr'))98- assert rv.status_code == 20099- assert rv.data == u'정상처리'.encode('utf-8')98+ self.assert_equal(rv.status_code, 200)99+ self.assert_equal(rv.data, u'정상처리'.encode('utf-8'))100 101 if not has_encoding('euc-kr'):102 test_modified_url_encoding = None103 4 unmodified lines108 app = flask.Flask(__name__)109 with app.test_request_context():110 rv = flask.send_file('static/index.html')111 assert rv.direct_passthrough112- assert rv.mimetype == 'text/html'112+ self.assert_equal(rv.mimetype, 'text/html')113 with app.open_resource('static/index.html') as f:114- assert rv.data == f.read()114+ self.assert_equal(rv.data, f.read())115 116 def test_send_file_xsendfile(self):117 app = flask.Flask(__name__)118 app.use_x_sendfile = True119 with app.test_request_context():120 rv = flask.send_file('static/index.html')121 assert rv.direct_passthrough122 assert 'x-sendfile' in rv.headers123- assert rv.headers['x-sendfile'] == \124- os.path.join(app.root_path, 'static/index.html')125- assert rv.mimetype == 'text/html'123+ self.assert_equal(rv.headers['x-sendfile'],124+ os.path.join(app.root_path, 'static/index.html'))125+ self.assert_equal(rv.mimetype, 'text/html')126 127 def test_send_file_object(self):128 app = flask.Flask(__name__)129 with catch_warnings() as captured:130 with app.test_request_context():131 f = open(os.path.join(app.root_path, 'static/index.html'))132 rv = flask.send_file(f)133 with app.open_resource('static/index.html') as f:134- assert rv.data == f.read()135- assert rv.mimetype == 'text/html'134+ self.assert_equal(rv.data, f.read())135+ self.assert_equal(rv.mimetype, 'text/html')136 # mimetypes + etag137- assert len(captured) == 2137+ self.assert_equal(len(captured), 2)138 139 app.use_x_sendfile = True140 with catch_warnings() as captured:141 with app.test_request_context():142 f = open(os.path.join(app.root_path, 'static/index.html'))143 rv = flask.send_file(f)144- assert rv.mimetype == 'text/html'144+ self.assert_equal(rv.mimetype, 'text/html')145 assert 'x-sendfile' in rv.headers146- assert rv.headers['x-sendfile'] == \147- os.path.join(app.root_path, 'static/index.html')146+ self.assert_equal(rv.headers['x-sendfile'],147+ os.path.join(app.root_path, 'static/index.html'))148 # mimetypes + etag149- assert len(captured) == 2149+ self.assert_equal(len(captured), 2)150 151 app.use_x_sendfile = False152 with app.test_request_context():153 with catch_warnings() as captured:154 f = StringIO('Test')155 rv = flask.send_file(f)156- assert rv.data == 'Test'157- assert rv.mimetype == 'application/octet-stream'156+ self.assert_equal(rv.data, 'Test')157+ self.assert_equal(rv.mimetype, 'application/octet-stream')158 # etags159- assert len(captured) == 1159+ self.assert_equal(len(captured), 1)160 with catch_warnings() as captured:161 f = StringIO('Test')162 rv = flask.send_file(f, mimetype='text/plain')163- assert rv.data == 'Test'164- assert rv.mimetype == 'text/plain'163+ self.assert_equal(rv.data, 'Test')164+ self.assert_equal(rv.mimetype, 'text/plain')165 # etags166- assert len(captured) == 1166+ self.assert_equal(len(captured), 1)167 168 app.use_x_sendfile = True169 with catch_warnings() as captured:170 with app.test_request_context():171 f = StringIO('Test')172 rv = flask.send_file(f)173 assert 'x-sendfile' not in rv.headers174 # etags175- assert len(captured) == 1175+ self.assert_equal(len(captured), 1)176 177 def test_attachment(self):178 app = flask.Flask(__name__)179 with catch_warnings() as captured:180 with app.test_request_context():181 f = open(os.path.join(app.root_path, 'static/index.html'))182 rv = flask.send_file(f, as_attachment=True)183 value, options = parse_options_header(rv.headers['Content-Disposition'])184- assert value == 'attachment'184+ self.assert_equal(value, 'attachment')185 # mimetypes + etag186- assert len(captured) == 2186+ self.assert_equal(len(captured), 2)187 188 with app.test_request_context():189- assert options['filename'] == 'index.html'189+ self.assert_equal(options['filename'], 'index.html')190 rv = flask.send_file('static/index.html', as_attachment=True)191 value, options = parse_options_header(rv.headers['Content-Disposition'])192- assert value == 'attachment'193- assert options['filename'] == 'index.html'192+ self.assert_equal(value, 'attachment')193+ self.assert_equal(options['filename'], 'index.html')194 195 with app.test_request_context():196 rv = flask.send_file(StringIO('Test'), as_attachment=True,197 attachment_filename='index.txt',198 add_etags=False)199- assert rv.mimetype == 'text/plain'199+ self.assert_equal(rv.mimetype, 'text/plain')200 value, options = parse_options_header(rv.headers['Content-Disposition'])201- assert value == 'attachment'202- assert options['filename'] == 'index.txt'201+ self.assert_equal(value, 'attachment')202+ self.assert_equal(options['filename'], 'index.txt')203 204 205 class LoggingTestCase(FlaskTestCase):206 207 def test_logger_cache(self):208 app = flask.Flask(__name__)209 logger1 = app.logger210 assert app.logger is logger1211- assert logger1.name == __name__211+ self.assert_equal(logger1.name, __name__)212 app.logger_name = __name__ + '/test_logger_cache'213 assert app.logger is not logger1214 215 def test_debug_log(self):37 unmodified lines253 def index():254 1/0255 256 rv = app.test_client().get('/')257- assert rv.status_code == 500257+ self.assert_equal(rv.status_code, 500)258 assert 'Internal Server Error' in rv.data259 260 err = out.getvalue()261 assert 'Exception on / [GET]' in err19 unmodified lines281 def internal_server_error(e):282 return 'Hello Server Error', 500283 for trigger in 'before', 'after':284 rv = app.test_client().get('/')285- assert rv.status_code == 500286- assert rv.data == 'Hello Server Error'285+ self.assert_equal(rv.status_code, 500)286+ self.assert_equal(rv.data, 'Hello Server Error')287 288 289 def suite():290 suite = unittest.TestSuite()5 unmodified linesmodified:flask/testsuite/signals.py+9 added-9 removed
27 unmodified lines28 29 flask.template_rendered.connect(record, app)30 try:31 app.test_client().get('/')32- assert len(recorded) == 132+ self.assert_equal(len(recorded), 1)33 template, context = recorded[0]34- assert template.name == 'simple_template.html'35- assert context['whiskey'] == 4234+ self.assert_equal(template.name, 'simple_template.html')35+ self.assert_equal(context['whiskey'], 42)36 finally:37 flask.template_rendered.disconnect(record, app)38 39 def test_request_signals(self):3 unmodified lines43 def before_request_signal(sender):44 calls.append('before-signal')45 46 def after_request_signal(sender, response):47- assert response.data == 'stuff'47+ self.assert_equal(response.data, 'stuff')48 calls.append('after-signal')49 50 @app.before_request51 def before_request_handler():14 unmodified lines66 flask.request_finished.connect(after_request_signal, app)67 68 try:69 rv = app.test_client().get('/')70- assert rv.data == 'stuff'70+ self.assert_equal(rv.data, 'stuff')71 72- assert calls == ['before-signal', 'before-handler',72+ self.assert_equal(calls, ['before-signal', 'before-handler',73 'handler', 'after-handler',74- 'after-signal']74+ 'after-signal'])75 finally:76 flask.request_started.disconnect(before_request_signal, app)77 flask.request_finished.disconnect(after_request_signal, app)78 9 unmodified lines88 recorded.append(exception)89 90 flask.got_request_exception.connect(record, app)91 try:92- assert app.test_client().get('/').status_code == 50093- assert len(recorded) == 192+ self.assert_equal(app.test_client().get('/').status_code, 500)93+ self.assert_equal(len(recorded), 1)94 assert isinstance(recorded[0], ZeroDivisionError)95 finally:96 flask.got_request_exception.disconnect(record, app)97 6 unmodified linesmodified:flask/testsuite/templating.py+13 added-13 removed
22 unmodified lines23 @app.route('/')24 def index():25 return flask.render_template('context_template.html', value=23)26 rv = app.test_client().get('/')27- assert rv.data == '<p>23|42'27+ self.assert_equal(rv.data, '<p>23|42')28 29 def test_original_win(self):30 app = flask.Flask(__name__)31 @app.route('/')32 def index():33 return flask.render_template_string('{{ config }}', config=42)34 rv = app.test_client().get('/')35- assert rv.data == '42'35+ self.assert_equal(rv.data, '42')36 37 def test_standard_context(self):38 app = flask.Flask(__name__)39 app.secret_key = 'development key'7 unmodified lines47 {{ config.DEBUG }}48 {{ session.test }}49 ''')50 rv = app.test_client().get('/?foo=42')51- assert rv.data.split() == ['42', '23', 'False', 'aha']51+ self.assert_equal(rv.data.split(), ['42', '23', 'False', 'aha'])52 53 def test_escaping(self):54 text = '<p>Hello World!'55 app = flask.Flask(__name__)1 unmodified line57 def index():58 return flask.render_template('escaping_template.html', text=text,59 html=flask.Markup(text))60 lines = app.test_client().get('/').data.splitlines()61- assert lines == [61+ self.assert_equal(lines, [62 '<p>Hello World!',63 '<p>Hello World!',64 '<p>Hello World!',65 '<p>Hello World!',66 '<p>Hello World!',67 '<p>Hello World!'68- ]68+ ])69 70 def test_no_escaping(self):71 app = flask.Flask(__name__)72 with app.test_request_context():5 unmodified lines78 def test_macros(self):79 app = flask.Flask(__name__)80 with app.test_request_context():81 macro = flask.get_template_attribute('_macro.html', 'hello')82- assert macro('World') == 'Hello World!'82+ self.assert_equal(macro('World'), 'Hello World!')83 84 def test_template_filter(self):85 app = flask.Flask(__name__)86 @app.template_filter()87 def my_reverse(s):88 return s[::-1]89 assert 'my_reverse' in app.jinja_env.filters.keys()90- assert app.jinja_env.filters['my_reverse'] == my_reverse91- assert app.jinja_env.filters['my_reverse']('abcd') == 'dcba'90+ self.assert_equal(app.jinja_env.filters['my_reverse'], my_reverse)91+ self.assert_equal(app.jinja_env.filters['my_reverse']('abcd'), 'dcba')92 93 def test_template_filter_with_name(self):94 app = flask.Flask(__name__)95 @app.template_filter('strrev')96 def my_reverse(s):97 return s[::-1]98 assert 'strrev' in app.jinja_env.filters.keys()99- assert app.jinja_env.filters['strrev'] == my_reverse100- assert app.jinja_env.filters['strrev']('abcd') == 'dcba'99+ self.assert_equal(app.jinja_env.filters['strrev'], my_reverse)100+ self.assert_equal(app.jinja_env.filters['strrev']('abcd'), 'dcba')101 102 def test_template_filter_with_template(self):103 app = flask.Flask(__name__)104 @app.template_filter()2 unmodified lines107 @app.route('/')108 def index():109 return flask.render_template('template_filter.html', value='abcd')110 rv = app.test_client().get('/')111- assert rv.data == 'dcba'111+ self.assert_equal(rv.data, 'dcba')112 113 def test_template_filter_with_name_and_template(self):114 app = flask.Flask(__name__)115 @app.template_filter('super_reverse')2 unmodified lines118 @app.route('/')119 def index():120 return flask.render_template('template_filter.html', value='abcd')121 rv = app.test_client().get('/')122- assert rv.data == 'dcba'122+ self.assert_equal(rv.data, 'dcba')123 124 def test_custom_template_loader(self):125 class MyFlask(flask.Flask):126 def create_global_jinja_loader(self):4 unmodified lines131 def index():132 return flask.render_template('index.html')133 c = app.test_client()134 rv = c.get('/')135- assert rv.data == 'Hello Custom World!'135+ self.assert_equal(rv.data, 'Hello Custom World!')136 137 138 def suite():139 suite = unittest.TestSuite()2 unmodified linesmodified:flask/testsuite/testing.py+4 added-4 removed
95 unmodified lines96 1/097 98 with app.test_client() as c:99 resp = c.get('/')100- assert flask.g.value == 42101- assert resp.data == 'Hello World!'102- assert resp.status_code == 200100+ self.assert_equal(flask.g.value, 42)101+ self.assert_equal(resp.data, 'Hello World!')102+ self.assert_equal(resp.status_code, 200)103 104 resp = c.get('/other')105 assert not hasattr(flask.g, 'value')106 assert 'Internal Server Error' in resp.data107- assert resp.status_code == 500107+ self.assert_equal(resp.status_code, 500)108 flask.g.value = 23109 110 try:111 flask.g.value10 unmodified lines