Fixed flask tests
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 e059bf3 · Browse files · 5 files·+23 added−10 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+23 added−10 removed
- other:+23 added−10 removed
Provenance
- Commit
d2d8e66- Tree
0fd0b35- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
e059bf3
5 files changed+23 added−10 removed
modified:examples/flaskr/flaskr_tests.py+2 added-1 removed
19 unmodified lines20 """Before each test, set up a blank database"""21 self.db_fd, flaskr.app.config['DATABASE'] = tempfile.mkstemp()22 flaskr.app.config['TESTING'] = True23 self.app = flaskr.app.test_client()24+ with flaskr.app.app_context():24- flaskr.init_db()25+ flaskr.init_db()26 27 def tearDown(self):28 """Get rid of the database again after each test."""29 os.close(self.db_fd)47 unmodified linesmodified:examples/flaskr/flaskr.py+8 added-3 removed
35 unmodified lines36 rv.row_factory = sqlite3.Row37 return rv38 39 40-@app.cli.command()41-def initdb():42- """Creates the database tables."""40+def init_db():41+ """Initializes the database."""42 db = get_db()43 with app.open_resource('schema.sql', mode='r') as f:44 db.cursor().executescript(f.read())45 db.commit()46+47+48+@app.cli.command('initdb')49+def initdb_command():50+ """Creates the database tables."""51+ init_db()52 print('Initialized the database.')53 54 55 def get_db():55 unmodified linesmodified:examples/minitwit/minitwit_tests.py+2 added-1 removed
18 unmodified lines19 def setUp(self):20 """Before each test, set up a blank database"""21 self.db_fd, minitwit.app.config['DATABASE'] = tempfile.mkstemp()22 self.app = minitwit.app.test_client()23+ with minitwit.app.app_context():23- minitwit.init_db()24+ minitwit.init_db()25 26 def tearDown(self):27 """Get rid of the database again after each test."""28 os.close(self.db_fd)122 unmodified linesmodified:examples/minitwit/minitwit.py+9 added-3 removed
47 unmodified lines48 if hasattr(top, 'sqlite_db'):49 top.sqlite_db.close()50 51 52-@app.cli.command()53-def initdb():54- """Creates the database tables."""52+def init_db():53+ """Initializes the database."""54 db = get_db()55 with app.open_resource('schema.sql', mode='r') as f:56 db.cursor().executescript(f.read())57 db.commit()58 59 60+@app.cli.command('initdb')61+def initdb_command():62+ """Creates the database tables."""63+ init_db()64+ print('Initialized the database.')65+66+67 def query_db(query, args=(), one=False):68 """Queries the database and returns a list of dictionaries."""69 cur = get_db().execute(query, args)70 rv = cur.fetchall()186 unmodified linesmodified:flask/cli.py+2 added-2 removed
197 unmodified lines198 if os.path.isfile(value):199 value = prepare_exec_for_file(value)200 elif '.' not in sys.path:201 sys.path.insert(0, '.')202- ctx.obj.app_import_path = value202+ ctx.ensure_object(ScriptInfo).app_import_path = value203 def set_debug(ctx, value):204- ctx.obj.debug = value204+ ctx.ensure_object(ScriptInfo).debug = value205 206 click.Group.__init__(self, help=help, params=[207 click.Option(['-a', '--app'],208 help='The application to run',148 unmodified lines