Questions tagged [flask-testing]
80 questions
1
vote
1 answer
flask test client post does not create object in database
The following test code does not pass even though manually submitting the form on my web interface actually does work.
import os
from flask.ext.testing import TestCase
from flask import url_for
from config import _basedir
from app import app,…

Calvin Cheng
- 35,640
- 39
- 116
- 167
1
vote
1 answer
Nose main() with no arguments produces odd behavior
I have a Flask app and I am using Flask-Script and Flask-Testing. Basically I have a manage.py file that looks like this:
from flask.ext.script import Manager
from app import app, db
manager = Manager(app)
@manager.command
def test():
import…

linkyndy
- 17,038
- 20
- 114
- 194
0
votes
0 answers
Flask Testing with SQLite DB, deleting not working
In order to test my flask application, I setup a local SQLite DB with create_engine. To delete, I have my route call TablesEtl().delete_record_by_id().
class TablesEtl:
def __init__(self) -> None:
self.engine =…

Rafael
- 1
- 1
0
votes
1 answer
Import reflected Flask-SQLAlchemy Module before creating the app
This is a continuation of this question.
As my flask app should not write anything in my database, I set up Flask-SQLAlchemy to reflect my database. This way I do not have to change my models, when I change my schema:
# app/__init__.py
from flask…

Tibor Völcker
- 175
- 12
0
votes
1 answer
How to test SQLAlchemy with reflected database
As my flask app should not write anything in my database, I set up Flask-SQLAlchemy to reflect my database. This way I do not have to change my models, when I change my schema:
# app/__init__.py
from flask import Flask
from flask_sqlalchemy import…

Tibor Völcker
- 175
- 12
0
votes
0 answers
How do run assertion against exception with unittest?
I'm unittesting token creation (think PyJWT) and I need to test if
expired token raises exception:
from jwt.exceptions import ExpiredSignatureError
def test_invalid_logout_expired_token(self):
add_user('testuser', 'testemail@mail.com',…

Mark
- 1,385
- 3
- 16
- 29
0
votes
1 answer
Why test file can't run tests against app file?
I'm practising tdd with Flask and funny enough my first test file
can't seem to detect the main flask_app file:
test_basics.py :
from flask_testing import TestCase
from flask_app import app
import unittest
class TestBasics(TestCase):
def…

appdeveloper
- 61
- 7
0
votes
1 answer
Is it possible to emulate that some MySQL procedure exists when mocking callproc method from MySQLdb python library
I have the following unittest which needs to test the flask route.
@unittest.mock.patch('flask_login.utils._get_user')
@unittest.mock.patch('flask_sqlalchemy.SQLAlchemy')
def test_attendances_management(self, SQLAlchemy, current_user):
user =…

Matija Lukic
- 599
- 8
- 28
0
votes
2 answers
Getting a "Can't pickle local object 'LiveServerTestCase'" error when trying to use LiveServerTestCase to test Flask app
I am getting the error mentioned in the title once trying to run a unittest on my Flask app using LiveServerTestCase from flask_testing.
This is my test file:
from app import create_app
from flask_testing import LiveServerTestCase
class…

AcroTom
- 71
- 6
0
votes
1 answer
Automated testing in Flask
I am having a problem with making automated tests for flask in python 3. I have tried unittest, pytests, nosetests but I still can't figure out how to form automated tests for flask application.
Following is the code I have wrote using unittest and…

Icy
- 13
- 7
0
votes
1 answer
How to send QuerySelectField form data to a Flask view in a unittest?
I am trying to test edit and add views in a flask application I am working on. A version of the website is deployed and the views are working correctly, but the tests I am making are do not seem to be passing the QuerySelectField data correctly.…

Kody Rogers
- 63
- 1
- 7
0
votes
1 answer
flask testing - assertRedirects doesn't show redirect
I'm writing a unit test module for my python3 flask project. One of the tests is intended to check if after passing user credentials to log-in form, the user gets successfuly redirected to home page. The application itself works fine through the web…

Grzegorz Ky
- 31
- 1
- 6
0
votes
1 answer
Flask Testing - Dynamically test all protected routes from a blueprint
I would like to test that all routes from a blueprint are protected with a login required decorator.
The point is :
If a developer add a new route and forget to add this decorator, I would like my test to automatically spot that lack.
In order to do…

Charles R
- 1,621
- 1
- 8
- 25
0
votes
1 answer
I don't know why create_app is called in every test function
I write testing code using flask_testing
following is my testing code
from app import create_app, db
class SampleTest(TestCase):
def create_app(self):
self.db_fd, self.db_path = tempflie.mkstemp()
return create_app({'DATABASE':…

fuzes
- 1,777
- 4
- 20
- 40
0
votes
1 answer
Flask-testing : self.client.delete() return 200 but fail as he doesnt delete anything
I have a CRUD football player flask app using SQL Alchemy and postgresql.
I'm trying to test it with unittest and flask-testing but when I test delete and patch request on a player (based on his number), the statut returned is 200 but the player…

DevAb
- 530
- 6
- 12