Skip to content
Myr

Changed assert to self.assert_ where it was still in place

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 3069e2d · Browse files · 8 files+86 added−86 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+86 added−86 removed

  • other:+86 added−86 removed

8 files+86 added−86 removed

modified:flask/testsuite/basic.py+40 added-40 removed
71 unmodified lines
72 self.assert_equal(rv.status_code, 405)73 self.assert_equal(sorted(rv.allow), ['GET', 'HEAD', 'OPTIONS'])74 rv = c.head('/')75 self.assert_equal(rv.status_code, 200)76 assert not rv.data # head truncates76 self.assert_(not rv.data) # head truncates77 self.assert_equal(c.post('/more').data, 'POST')78 self.assert_equal(c.get('/more').data, 'GET')79 rv = c.delete('/more')80 self.assert_equal(rv.status_code, 405)
15 unmodified lines
96 self.assert_equal(rv.status_code, 405)97 self.assert_equal(sorted(rv.allow), ['GET', 'HEAD', 'OPTIONS'])98 rv = c.head('/')99 self.assert_equal(rv.status_code, 200)100 assert not rv.data # head truncates100 self.assert_(not rv.data) # head truncates101 self.assert_equal(c.post('/more').data, 'POST')102 self.assert_equal(c.get('/more').data, 'GET')103 rv = c.delete('/more')104 self.assert_equal(rv.status_code, 405)
62 unmodified lines
167 def index():168 flask.session['testing'] = 42169 return 'Hello World'170 rv = app.test_client().get('/', 'http://example.com/')171 assert 'domain=.example.com' in rv.headers['set-cookie'].lower()172 assert 'httponly' in rv.headers['set-cookie'].lower()171 self.assert_('domain=.example.com' in rv.headers['set-cookie'].lower())172 self.assert_('httponly' in rv.headers['set-cookie'].lower())173174 def test_session_using_server_name_and_port(self):175 app = flask.Flask(__name__)176 app.config.update(
4 unmodified lines
181 def index():182 flask.session['testing'] = 42183 return 'Hello World'184 rv = app.test_client().get('/', 'http://example.com:8080/')185 assert 'domain=.example.com' in rv.headers['set-cookie'].lower()186 assert 'httponly' in rv.headers['set-cookie'].lower()185 self.assert_('domain=.example.com' in rv.headers['set-cookie'].lower())186 self.assert_('httponly' in rv.headers['set-cookie'].lower())187188 def test_session_using_application_root(self):189 class PrefixPathMiddleware(object):190 def __init__(self, app, prefix):
13 unmodified lines
204 def index():205 flask.session['testing'] = 42206 return 'Hello World'207 rv = app.test_client().get('/', 'http://example.com:8080/')208 assert 'path=/bar' in rv.headers['set-cookie'].lower()208 self.assert_('path=/bar' in rv.headers['set-cookie'].lower())209210 def test_missing_session(self):211 app = flask.Flask(__name__)212 def expect_exception(f, *args, **kwargs):213 try:214 f(*args, **kwargs)215 except RuntimeError, e:216 assert e.args and 'session is unavailable' in e.args[0]216 self.assert_(e.args and 'session is unavailable' in e.args[0])217 else:218 assert False, 'expected exception'218 self.assert_(False, 'expected exception')219 with app.test_request_context():220 assert flask.session.get('missing_key') is None220 self.assert_(flask.session.get('missing_key') is None)221 expect_exception(flask.session.__setitem__, 'foo', 42)222 expect_exception(flask.session.pop, 'foo')223224 def test_session_expiration(self):
11 unmodified lines
236 return unicode(flask.session.permanent)237238 client = app.test_client()239 rv = client.get('/')240 assert 'set-cookie' in rv.headers240 self.assert_('set-cookie' in rv.headers)241 match = re.search(r'\bexpires=([^;]+)', rv.headers['set-cookie'])242 expires = parse_date(match.group())243 expected = datetime.utcnow() + app.permanent_session_lifetime244 self.assert_equal(expires.year, expected.year)
4 unmodified lines
249 self.assert_equal(rv.data, 'True')250251 permanent = False252 rv = app.test_client().get('/')253 assert 'set-cookie' in rv.headers253 self.assert_('set-cookie' in rv.headers)254 match = re.search(r'\bexpires=([^;]+)', rv.headers['set-cookie'])255 assert match is None255 self.assert_(match is None)256257 def test_flashes(self):258 app = flask.Flask(__name__)259 app.secret_key = 'testkey'260261 with app.test_request_context():262 assert not flask.session.modified262 self.assert_(not flask.session.modified)263 flask.flash('Zap')264 flask.session.modified = False265 flask.flash('Zip')266 assert flask.session.modified266 self.assert_(flask.session.modified)267 self.assert_equal(list(flask.get_flashed_messages()), ['Zap', 'Zip'])268269 def test_extended_flashing(self):270 app = flask.Flask(__name__)
36 unmodified lines
307 evts.append('after')308 return response309 @app.route('/')310 def index():311 assert 'before' in evts312 assert 'after' not in evts311 self.assert_('before' in evts)312 self.assert_('after' not in evts)313 return 'request'314 assert 'after' not in evts314 self.assert_('after' not in evts)315 rv = app.test_client().get('/').data316 assert 'after' in evts316 self.assert_('after' in evts)317 self.assert_equal(rv, 'request|after')318319 def test_teardown_request_handler(self):320 called = []
6 unmodified lines
327 def root():328 return "Response"329 rv = app.test_client().get('/')330 self.assert_equal(rv.status_code, 200)331 assert 'Response' in rv.data331 self.assert_('Response' in rv.data)332 self.assert_equal(len(called), 1)333334 def test_teardown_request_handler_debug_mode(self):335 called = []
7 unmodified lines
343 def root():344 return "Response"345 rv = app.test_client().get('/')346 self.assert_equal(rv.status_code, 200)347 assert 'Response' in rv.data347 self.assert_('Response' in rv.data)348 self.assert_equal(len(called), 1)349350 def test_teardown_request_handler_error(self):351 called = []
24 unmodified lines
376 def fails():377 1/0378 rv = app.test_client().get('/')379 self.assert_equal(rv.status_code, 500)380 assert 'Internal Server Error' in rv.data380 self.assert_('Internal Server Error' in rv.data)381 self.assert_equal(len(called), 2)382383 def test_before_after_request_order(self):384 called = []
65 unmodified lines
450451 app = flask.Flask(__name__)452 @app.errorhandler(MyException)453 def handle_my_exception(e):454 assert isinstance(e, MyException)454 self.assert_(isinstance(e, MyException))455 return '42'456 @app.route('/')457 def index():458 raise MyException()
14 unmodified lines
473 c = app.test_client()474 try:475 c.get('/fail')476 except KeyError, e:477 assert isinstance(e, BadRequest)477 self.assert_(isinstance(e, BadRequest))478 else:479 self.fail('Expected exception')480481 def test_trapping_of_all_http_exceptions(self):
26 unmodified lines
508 with app.test_client() as c:509 try:510 c.post('/fail', data={'foo': 'index.txt'})511 except DebugFilesKeyError, e:512 assert 'no file contents were transmitted' in str(e)513 assert 'This was submitted: "index.txt"' in str(e)512 self.assert_('no file contents were transmitted' in str(e))513 self.assert_('This was submitted: "index.txt"' in str(e))514 else:515 self.fail('Expected exception')516517 def test_teardown_on_pop(self):
53 unmodified lines
571 def hello():572 pass573 with app.test_request_context():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'575 self.assert_equal(flask.url_for('hello', name='test x', _external=True),576 'http://localhost/hello/test%20x')577578 def test_custom_converters(self):579 from werkzeug.routing import BaseConverter580 class ListConverter(BaseConverter):
15 unmodified lines
596 rv = app.test_client().get('/static/index.html')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'600 self.assert_equal(flask.url_for('static', filename='index.html'),601 '/static/index.html')602603 def test_none_response(self):604 app = flask.Flask(__name__)605 @app.route('/')
4 unmodified lines
610 except ValueError, e:611 self.assert_equal(str(e), 'View function did not return a response')612 pass613 else:614 assert "Expected ValueError"614 self.assert_("Expected ValueError")615616 def test_request_locals(self):617 self.assert_equal(repr(flask.g), '<LocalProxy unbound>')618 self.assertFalse(flask.g)
21 unmodified lines
640 try:641 with app.test_request_context('/', environ_overrides={'HTTP_HOST': 'localhost'}):642 pass643 except Exception, e:644 assert isinstance(e, ValueError)644 self.assert_(isinstance(e, ValueError))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')")648
118 unmodified lines
767 app.config['MAX_CONTENT_LENGTH'] = 64768 @app.before_request769 def always_first():770 flask.request.form['myfile']771 assert False771 self.assert_(False)772 @app.route('/accept', methods=['POST'])773 def accept_file():774 flask.request.form['myfile']775 assert False775 self.assert_(False)776 @app.errorhandler(413)777 def catcher(error):778 return '42'779
108 unmodified lines
888 with app.test_request_context('/?name=World'):889 self.assert_equal(index(), 'Hello World!')890 with app.test_request_context('/meh'):891 self.assert_equal(meh(), 'http://localhost/meh')892 assert flask._request_ctx_stack.top is None892 self.assert_(flask._request_ctx_stack.top is None)893894 def test_context_test(self):895 app = flask.Flask(__name__)896 assert not flask.request897 assert not flask.has_request_context()896 self.assert_(not flask.request)897 self.assert_(not flask.has_request_context())898 ctx = app.test_request_context()899 ctx.push()900 try:901 assert flask.request902 assert flask.has_request_context()901 self.assert_(flask.request)902 self.assert_(flask.has_request_context())903 finally:904 ctx.pop()905906 def test_manual_context_binding(self):
10 unmodified lines
917 index()918 except RuntimeError:919 pass920 else:921 assert 0, 'expected runtime error'921 self.assert_(0, 'expected runtime error')922923924class SubdomainTestCase(FlaskTestCase):925
67 unmodified lines
modified:flask/testsuite/blueprints.py+9 added-9 removed
171 unmodified lines
172 rv = c.get('/admin/static/css/test.css')173 self.assert_equal(rv.data.strip(), '/* nested file */')174175 with app.test_request_context():176 assert flask.url_for('admin.static', filename='test.txt') \177 == '/admin/static/test.txt'176 self.assert_equal(flask.url_for('admin.static', filename='test.txt'),177 '/admin/static/test.txt')178179 with app.test_request_context():180 try:181 flask.render_template('missing.html')182 except TemplateNotFound, e:183 self.assert_equal(e.name, 'missing.html')184 else:185 assert 0, 'expected exception'185 self.assert_(0, 'expected exception')186187 with flask.Flask(__name__).test_request_context():188 self.assert_equal(flask.render_template('nested/nested.txt'), 'I\'m nested')189
7 unmodified lines
197 f('/etc/passwd')198 except NotFound:199 pass200 else:201 assert 0, 'expected exception'201 self.assert_(0, 'expected exception')202 try:203 f('../__init__.py')204 except NotFound:205 pass206 else:207 assert 0, 'expected exception'207 self.assert_(0, 'expected exception')208209 # testcase for a security issue that may exist on windows systems210 import os211 import ntpath
4 unmodified lines
216 f('..\\__init__.py')217 except NotFound:218 pass219 else:220 assert 0, 'expected exception'220 self.assert_(0, 'expected exception')221 finally:222 os.path = old_path223224 @emits_module_deprecation_warning
129 unmodified lines
354 rv = c.get('/admin/static/css/test.css')355 self.assert_equal(rv.data.strip(), '/* nested file */')356357 with app.test_request_context():358 assert flask.url_for('admin.static', filename='test.txt') \359 == '/admin/static/test.txt'358 self.assert_equal(flask.url_for('admin.static', filename='test.txt'),359 '/admin/static/test.txt')360361 with app.test_request_context():362 try:363 flask.render_template('missing.html')364 except TemplateNotFound, e:365 self.assert_equal(e.name, 'missing.html')366 else:367 assert 0, 'expected exception'367 self.assert_(0, 'expected exception')368369 with flask.Flask(__name__).test_request_context():370 self.assert_equal(flask.render_template('nested/nested.txt'), 'I\'m nested')371
52 unmodified lines
modified:flask/testsuite/config.py+10 added-10 removed
23 unmodified lines
2425 def common_object_test(self, app):26 self.assert_equal(app.secret_key, 'devkey')27 self.assert_equal(app.config['TEST_KEY'], 'foo')28 assert 'ConfigTestCase' not in app.config28 self.assert_('ConfigTestCase' not in app.config)2930 def test_config_from_file(self):31 app = flask.Flask(__name__)32 app.config.from_pyfile(__file__.rsplit('.')[0] + '.py')
20 unmodified lines
53 app = flask.Flask(__name__)54 try:55 app.config.from_envvar('FOO_SETTINGS')56 except RuntimeError, e:57 assert "'FOO_SETTINGS' is not set" in str(e)57 self.assert_("'FOO_SETTINGS' is not set" in str(e))58 else:59 assert 0, 'expected exception'60 assert not app.config.from_envvar('FOO_SETTINGS', silent=True)59 self.assert_(0, 'expected exception')60 self.assert_(not app.config.from_envvar('FOO_SETTINGS', silent=True))6162 os.environ = {'FOO_SETTINGS': __file__.rsplit('.')[0] + '.py'}63 assert app.config.from_envvar('FOO_SETTINGS')63 self.assert_(app.config.from_envvar('FOO_SETTINGS'))64 self.common_object_test(app)65 finally:66 os.environ = env67
2 unmodified lines
70 try:71 app.config.from_pyfile('missing.cfg')72 except IOError, e:73 msg = str(e)74 assert msg.startswith('[Errno 2] Unable to load configuration '75 'file (No such file or directory):')76 assert msg.endswith("missing.cfg'")74 self.assert_(msg.startswith('[Errno 2] Unable to load configuration '75 'file (No such file or directory):'))76 self.assert_(msg.endswith("missing.cfg'"))77 else:78 assert 0, 'expected config'79 assert not app.config.from_pyfile('missing.cfg', silent=True)78 self.assert_(0, 'expected config')79 self.assert_(not app.config.from_pyfile('missing.cfg', silent=True))808182class InstanceTestCase(FlaskTestCase):83
94 unmodified lines
modified:flask/testsuite/deprecations.py+1 added-1 removed
27 unmodified lines
2829 c = app.test_client()30 self.assert_equal(c.get('/').data, '42')31 self.assert_equal(len(log), 1)32 assert 'init_jinja_globals' in str(log[0]['message'])32 self.assert_('init_jinja_globals' in str(log[0]['message']))333435def suite():36 suite = unittest.TestSuite()
2 unmodified lines
modified:flask/testsuite/helpers.py+17 added-17 removed
106 unmodified lines
107 def test_send_file_regular(self):108 app = flask.Flask(__name__)109 with app.test_request_context():110 rv = flask.send_file('static/index.html')111 assert rv.direct_passthrough111 self.assert_(rv.direct_passthrough)112 self.assert_equal(rv.mimetype, 'text/html')113 with app.open_resource('static/index.html') as f:114 self.assert_equal(rv.data, f.read())115
1 unmodified line
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.headers121 self.assert_(rv.direct_passthrough)122 self.assert_('x-sendfile' in rv.headers)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
14 unmodified lines
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 self.assert_equal(rv.mimetype, 'text/html')145 assert 'x-sendfile' in rv.headers145 self.assert_('x-sendfile' in rv.headers)146 self.assert_equal(rv.headers['x-sendfile'],147 os.path.join(app.root_path, 'static/index.html'))148 # mimetypes + etag149 self.assert_equal(len(captured), 2)
19 unmodified lines
169 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.headers173 self.assert_('x-sendfile' not in rv.headers)174 # etags175 self.assert_equal(len(captured), 1)176177 def test_attachment(self):
28 unmodified lines
206207 def test_logger_cache(self):208 app = flask.Flask(__name__)209 logger1 = app.logger210 assert app.logger is logger1210 self.assert_(app.logger is logger1)211 self.assert_equal(logger1.name, __name__)212 app.logger_name = __name__ + '/test_logger_cache'213 assert app.logger is not logger1213 self.assert_(app.logger is not logger1)214215 def test_debug_log(self):216 app = flask.Flask(__name__)217 app.debug = True
11 unmodified lines
229 with app.test_client() as c:230 with catch_stderr() as err:231 c.get('/')232 out = err.getvalue()233 assert 'WARNING in helpers [' in out234 assert os.path.basename(__file__.rsplit('.')[0] + '.py') in out235 assert 'the standard library is dead' in out236 assert 'this is a debug statement' in out233 self.assert_('WARNING in helpers [' in out)234 self.assert_(os.path.basename(__file__.rsplit('.')[0] + '.py') in out)235 self.assert_('the standard library is dead' in out)236 self.assert_('this is a debug statement' in out)237238 with catch_stderr() as err:239 try:240 c.get('/exc')241 except ZeroDivisionError:242 pass243 else:244 assert False, 'debug log ate the exception'244 self.assert_(False, 'debug log ate the exception')245246 def test_exception_logging(self):247 out = StringIO()248 app = flask.Flask(__name__)
5 unmodified lines
254 1/0255256 rv = app.test_client().get('/')257 self.assert_equal(rv.status_code, 500)258 assert 'Internal Server Error' in rv.data258 self.assert_('Internal Server Error' in rv.data)259260 err = out.getvalue()261 assert 'Exception on / [GET]' in err262 assert 'Traceback (most recent call last):' in err263 assert '1/0' in err264 assert 'ZeroDivisionError:' in err261 self.assert_('Exception on / [GET]' in err)262 self.assert_('Traceback (most recent call last):' in err)263 self.assert_('1/0' in err)264 self.assert_('ZeroDivisionError:' in err)265266 def test_processor_exceptions(self):267 app = flask.Flask(__name__)268 @app.before_request
27 unmodified lines
modified:flask/testsuite/signals.py+1 added-1 removed
89 unmodified lines
90 flask.got_request_exception.connect(record, app)91 try:92 self.assert_equal(app.test_client().get('/').status_code, 500)93 self.assert_equal(len(recorded), 1)94 assert isinstance(recorded[0], ZeroDivisionError)94 self.assert_(isinstance(recorded[0], ZeroDivisionError))95 finally:96 flask.got_request_exception.disconnect(record, app)9798
5 unmodified lines
modified:flask/testsuite/templating.py+6 added-6 removed
68 unmodified lines
6970 def test_no_escaping(self):71 app = flask.Flask(__name__)72 with app.test_request_context():73 assert flask.render_template_string('{{ foo }}',74 foo='<test>') == '<test>'75 assert flask.render_template('mail.txt', foo='<test>') \76 == '<test> Mail'73 self.assert_equal(flask.render_template_string('{{ foo }}',74 foo='<test>'), '<test>')75 self.assert_equal(flask.render_template('mail.txt', foo='<test>'),76 '<test> Mail')7778 def test_macros(self):79 app = flask.Flask(__name__)80 with app.test_request_context():
4 unmodified lines
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()89 self.assert_('my_reverse' in app.jinja_env.filters.keys())90 self.assert_equal(app.jinja_env.filters['my_reverse'], my_reverse)91 self.assert_equal(app.jinja_env.filters['my_reverse']('abcd'), 'dcba')9293 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()98 self.assert_('strrev' in app.jinja_env.filters.keys())99 self.assert_equal(app.jinja_env.filters['strrev'], my_reverse)100 self.assert_equal(app.jinja_env.filters['strrev']('abcd'), 'dcba')101102 def test_template_filter_with_template(self):
39 unmodified lines
modified:flask/testsuite/testing.py+2 added-2 removed
100 unmodified lines
101 self.assert_equal(resp.data, 'Hello World!')102 self.assert_equal(resp.status_code, 200)103104 resp = c.get('/other')105 assert not hasattr(flask.g, 'value')106 assert 'Internal Server Error' in resp.data105 self.assert_(not hasattr(flask.g, 'value'))106 self.assert_('Internal Server Error' in resp.data)107 self.assert_equal(resp.status_code, 500)108 flask.g.value = 23109110 try:
11 unmodified lines