flask-testing

How do I mock dependencies of the views module of my Flask application in flask-testing?

喜欢而已 提交于 2019-12-11 20:09:28
问题 As a minimal example, my Flask application has a views module like from flask import render_template from something import some_service def home(): foo = some_service.do_thing('bar') return render_template('index.html', foo=foo) I've got a test setup like from application import app from flask.ext.testing import TestCase class MyTest(TestCase): def create_app(self): app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False return app def setUp(self): self.app = app.test_client() def

Flask Testing a put request with custom headers

孤街浪徒 提交于 2019-12-11 03:14:50
问题 Im trying to test a PUT request in my Flask app, using flasks test client. Everything looks good to me but i keep getting 400 BAD request. I tried the same request using POSTMAN and I get the response back. Here is the code from flask import Flask app = Flask(__name__) data = {"filename": "/Users/resources/rovi_source_mock.csv"} headers = {'content-type': 'application/json'} api = "http://localhost:5000/ingest" with app.test_client() as client: api_response = client.put(api, data=data,

Test Coverage for Flask application doesnt work

£可爱£侵袭症+ 提交于 2019-12-10 20:40:01
问题 Hi want to test the "delete route" in my flask application in terminal I can see that the test is past and it said "test_user_delete (test_app.LayoutTestCase) ... ok" But when I open the cover page it still with red color which means doesn't cover it wold you please someone explain to me why and where I am doing wrong? app.layout.view.py test.py e1 = Users(name='admine2', email='admine2@gmail.com', age=25) e2 = Users(name='teste2', email='teste2@gmail.com', age=27) db.session.add_all([e1, e2]

Session key is not modified from Flask tests

拥有回忆 提交于 2019-12-09 04:33:25
I am building a tests for my Flask application, in one of the test there is a need to modify a session key (which itself is a list of values), and then check that app behaviour is altered by the modified key content. I'm using an approach from Flask documentation for modifying session from tests. Here is an excerpt example code, to demonstrate the problem (I have added print statements, along with what they are printing during test run): my_app.py from flask import ( Flask, session, ) app = Flask(__name__) app.secret_key = 'bad secret key' @app.route('/create_list/', methods=['POST']) def

Session key is not modified from Flask tests

僤鯓⒐⒋嵵緔 提交于 2019-12-08 05:00:49
问题 I am building a tests for my Flask application, in one of the test there is a need to modify a session key (which itself is a list of values), and then check that app behaviour is altered by the modified key content. I'm using an approach from Flask documentation for modifying session from tests. Here is an excerpt example code, to demonstrate the problem (I have added print statements, along with what they are printing during test run): my_app.py from flask import ( Flask, session, ) app =