Questions tagged [flask-testing]

80 questions
35
votes
1 answer

How to set request args with Flask test_client?

I have to test out a certain view that gets certain information from request.args. I can't mock this since a lot of stuff in the view uses the request object. The only alternative I can think of is to manually set request.args. I can do that with…
Saša Kalaba
  • 4,241
  • 6
  • 29
  • 52
13
votes
3 answers

How to Generate Fixtures from Database with SqlAlchemy

I'm starting to write tests with Flask-SQLAlchemy, and I'd like to add some fixtures for those. I have plenty of good data for that in my development database and a lot of tables so writing data manually would get annoying. I'd really like to just…
Eli
  • 36,793
  • 40
  • 144
  • 207
7
votes
2 answers

Flask Testing: Test App Request?

While doing the Miguel Grinberg's Flask Web Development, I got stuck while testing the gravatar code, def test_gravatar(self): u = User(email='john@example.com', password='cat') with self.app.test_request_context('/'): gravatar =…
Anuj
  • 6,987
  • 3
  • 22
  • 25
7
votes
1 answer

ImportError: No module named app

I working with Flask-Testing and make file test_app.py to test But I got this error File "test_app.py", line 4, in from app import create_app, db ImportError: No module named app. so please help how can I fix it and what is the problem Thanx :)…
LiLi
  • 301
  • 2
  • 7
  • 21
6
votes
1 answer

WrapperTestResponse' object has no attribute 'text'

Currently I'm writing a unite testing for my flask project. I wrote a function to test the login feature. When I run the unit test, it showed some error message. FAILED unit_test.py::TestClass::test_login - AttributeError: 'WrapperTestResponse'…
Jay Park
  • 308
  • 1
  • 6
  • 14
6
votes
1 answer

Flask-Testing signals not supported error

When running my tests I am getting the following traceback. in get_context_variable raise RuntimeError("Signals not supported") RuntimeError: Signals not supported __init__.py from flask_testing import TestCase from app import create_app,…
Adam
  • 3,992
  • 2
  • 19
  • 39
5
votes
0 answers

How to create test Postgres db in flask-tesing

I am using flask-testing to do some unit tests on a Postgres application. According to doc , I have following code. from flask_testing import TestCase from src.game.models import db from src import create_app class BaseTest(TestCase): …
4
votes
1 answer

Flask test client using GET request instead of POST

I have a route for only POST request and it returns json response if conditions are met. It's something like this: @app.route('/panel', methods=['POST']) def post_panel(): # Check for conditions and database operations return…
tanjibpa
  • 129
  • 10
4
votes
1 answer

Flask-Testing and Flask-SQLAlchemy: first_or_404()

I'm trying to test with Flask-Testing a Flask-SQLAlchemy model. More precisely a static method of this model that uses first_or_404() and I cannot find a way to make my test work. Here a self contained example that highlight the issue: from flask…
Johan
  • 3,728
  • 16
  • 25
4
votes
1 answer

Flask view testing: How do I prevent data from being saved to the database?

I have an app with SQLAlchemy, initialized: config_name = os.getenv('FLASK_CONFIG') or 'default' app = Flask(__name__) db = SQLAlchemy(app) db.init_app(app) and a view I'm working on that just returns all users in json format: @app.route('/users',…
limasxgoesto0
  • 4,555
  • 8
  • 31
  • 38
3
votes
0 answers

AssertionError: View function mapping is overwriting an existing endpoint function: api.users

I am trying to write a simple unittest case for my app but it crashes after the first test with error: AssertionError: View function mapping is overwriting an existing endpoint function: api.users Below is my test case (I use Flask-Testing): …
Denis Sologub
  • 7,277
  • 11
  • 56
  • 123
3
votes
3 answers

Problem when getting 'Authorization' header on test Flask application with FlaskClient

I'm testing my Flask application using FlaskClient, in order to avoid to run a Flask server always when I'm testing my application. I've created a 'sign_in' view that returns an 'Authorization' header with a encrypted token when the user logs…
rmmariano
  • 896
  • 1
  • 18
  • 32
3
votes
2 answers

Flask Testing a put request with custom headers

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…
3
votes
1 answer

Flask-testing - why the test does fail

I'm trying to write tests for a simple Flask application. Structure of the project is following: app/ static/ templates/ forms.py models.py views.py migrations/ config.py manage.py tests.py tests.py import unittest from app…
Stright
  • 47
  • 1
  • 6
3
votes
3 answers

Use in-memory database separately for testing - how?

I have this code: my_app.py: from flask import Flask from flask.ext.sqlalchemy import SQLAlchemy import os app = Flask(__name__) app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False app.config["BASE_DIR"] =…
John Reese
  • 583
  • 2
  • 6
  • 17
1
2 3 4 5 6