Questions tagged [flask-testing]

80 questions
1
vote
1 answer

How do I mock a flask decorator @login_required for my unit tests?

I am working on an application which requires a few unit tests to be written. I wanted to ask how can I mock a decorator '@login_required' in my unit tests? here is a function which has the @login_required function in app.py @app.route('/settings',…
1
vote
1 answer

Trouble unittesting Flask with SQLAlchemy

I have been messing around with trying to test my Flask application for a good while now but I cannot seem to get it to work. I followed the docs for a bit and researched a while myself and ended up piecing something together (code below), however…
ThaRising
  • 23
  • 1
  • 5
1
vote
1 answer

Flask_testing Returns 404 unexpectedly for seemingly working endpoint

Writing some unit tests for my flask application. The endpoint '/' works and returns 200 when I try in postman, however flask_testing gives AssertionError: 404 != 200 I have set up a base config. class BaseTestCase(TestCase): def…
SarahJessica
  • 473
  • 1
  • 7
  • 18
1
vote
1 answer

Unable to mock api call inner Function in Flask Unitest

I am unable to mock API Calls function call in Flask Rest API Tests. I am using unittest and pytest module. Code follows as: rest_api.py @app.route('/api/v1/recommender', methods=['POST']) def recommender(): """Handle POST requests that are…
Deepak Sharma
  • 1,401
  • 19
  • 21
1
vote
1 answer

How to properly run consecutive tests querying a Flask-SQLAlchemy database?

I'm setting up unit-testing for a Flask project using SQLAlchemy as ORM. For my tests I need to setup a new test database every time I run a single unit-test. Somehow, I cannot seem to run consecutive tests that query the database, even though if I…
1
vote
1 answer

Importing files from sibling directory

I need to run unit tests for my Flask app. In my test config file, I need to import the flask create_app function from a sibling directory to initialize the test app. I cannot figure it out without getting import errors. I have tried putting…
Darius Mandres
  • 778
  • 1
  • 13
  • 31
1
vote
0 answers

Flask Test Post is not sending correct data

I'm in the process of writing a test for the login portion of an app I'm creating in Flask. However, when I pass data using the test_client.post() method my test data isn't being passed correctly. What's more, the manual login test POSTs and…
Joel Carter
  • 151
  • 12
1
vote
1 answer

Session key is not modified from Flask tests

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…
user8554766
1
vote
1 answer

Pytest hangs when a flask server runs another thread

I am using Python3, Flask 0.12 and Pytest 3.0.7. I have a flask app similar to this: class AppInitializer: def __init__(self): pass @staticmethod def __function_to_be_refreshed(): while True: try: …
tusharmakkar08
  • 706
  • 1
  • 12
  • 32
1
vote
0 answers

Cannot test login function on flask app with flask-testing

I have a Flask app that I am writing tests for using Flask Testing. I have no trouble running the app and logging in/out, but writing a test for the login function has backfired. I get the following error: "Exception: No user_loader has been…
Isaac
  • 11
  • 1
  • 4
1
vote
0 answers

flask_testing AssertionError:existing endpoint function

when i write some test case use flask_test, it will run with the exception like this:AssertionError: View function mapping is overwriting an existing endpoint function: project When I'm debugging found that create_app will called many time, when it…
kyrione
  • 21
  • 2
1
vote
1 answer

Testing API endpoints with Flask-Testing

I've been using Flask-Testing to test my API, but I've recently run into some issues. What I'll normally want to do is verify an endpoint updates my database as expected. To do that, I'll verify a database value before hitting the end point, then…
Eli
  • 36,793
  • 40
  • 144
  • 207
1
vote
1 answer

How to create test database with Flask-Testing

I want to set up test database for Flask-Testing class, so tests do not affect my main database. I need test database being created each time I run my unittests testcase How can I do this? I use Flask-Testing, Flask-SQLAlchemy, psycopg2 Privilegies…
micgeronimo
  • 2,069
  • 5
  • 23
  • 44
1
vote
1 answer

How to test redirect to created instance in Flask

Having following function in views.py: def ask_question(): form = QuestionForm() if form.validate_on_submit(): question = Question(title=form.title.data, text=form.text.data) db.session.add(question) …
micgeronimo
  • 2,069
  • 5
  • 23
  • 44
1
vote
1 answer

Newb to Writing Integration Tests

Here is my test file: from flask import Flask from flask.ext.testing import TestCase class TestInitViews(TestCase): render_templates = False def create_app(self): app = Flask(__name__) app.config['TESTING'] = True …
dennismonsewicz
  • 25,132
  • 33
  • 116
  • 189