All Questions
31
questions
-1
votes
0
answers
28
views
FastAPI dependency is not getting overriden [SOLVED] [closed]
I'm trying to run some tests with pytest against the API but my dependency override is not working. The root app is in my 'main' file and the endpoints are in a 'routers' file. I also have a separate '...
1
vote
2
answers
65
views
How to mock sqlalchemy's async session?
Code snippet
from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine
engine = create_async_engine(url="")
session_maker = async_sessionmaker(engine)
How can I mock the ...
0
votes
0
answers
131
views
Python tests failing due to testcontainers-postgres connection refused
I am trying to run integration tests by using PostgresContainer from the testcontainers module in Python. These tests are part of the CI workflow on Github Actions but they are failing due to the ...
1
vote
1
answer
449
views
How to get excluded attributes of factory after generation?
I use Factory Boy to generate a fake user. I need a field password that should be hashed (in db, this is the only row related to the password) and a clear_password value in order to know what is the ...
0
votes
0
answers
67
views
How to see sql statement in a test that I'm using mock?
I would like to see the raw sql generated by a query in a test where I mocked the db connection.
db.py
from sqlalchemy import create_engine
def get_db():
engine = create_engine('my_db_url_here')
...
0
votes
1
answer
492
views
testing.postgresql can not initdb
I am trying to create a fastAPI app that connects to a PostgreSQL database when running, but to a testing.postgresql one when running tests. This is my code for the connection:
import sqlalchemy
...
2
votes
1
answer
730
views
How should I test db service module with temp database?
I'm looking for the right way to test service module with temporary database.
I Have a working example, but I feel like there is a better solution out there
this is an example for testing a db_service ...
0
votes
1
answer
48
views
How to subclass a table by changing the primary columns?
I would like to use SQLAlchemy to add some test fixtures to the database. It should should get or set the value accordingly. I was trying to create a model method like: ProductsModel.ensure(name="...
1
vote
1
answer
5k
views
How to mock sqlalchemy execution output inside `with` context manager
I'm trying to write unit tests for my python script which uses sqlalchemy to connect to MySQL.
My function looks like this:
def check_if_table_exists(db):
with db.connect() as cursor:
...
0
votes
0
answers
78
views
Getting a textual representation of all the SQL statements executed by SQLAlchemy and psycopg2?
I'm writing an end-to-end regression test for a program that uses SQLAlchemy over psycopg2, as well as psycopg2 directly, to make a set of changes to a database. To test that the program is correct, ...
1
vote
1
answer
1k
views
Mock default attribute of SQLAlchemy
I have some issues to mock a SQLAlchemy object when using the default and onupdate fields in my models :
def get_uuid():
return str(uuid.uuid4())
def get_now():
return db.func.now()
class ...
1
vote
1
answer
941
views
Test where clause in sqlalchemy select object
I am trying to write some functions to build sqlalchemy select statements. For instance:
import sqlalchemy as sa
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
...
1
vote
1
answer
210
views
Flask-SQLAlchemy Unittest Runs Twice
I've set up my project up like this:
- proj/
- proj.py
- views.py
- tests.py
- models.py
- settings.py
- setup.py
In proj.py I defined app and db:
from flask import Flask
from ...
1
vote
0
answers
157
views
How to test python database interacting functions
I have some function in my python file course.py which is in proj/com/api/course
folder. These function interact with database.
I am using flask, sqlalchemy .
course.py
def create(**kwargs):
...
1
vote
0
answers
1k
views
Testing return value of SQLAlchemy parent-child relationship query
Say I have two models set up like so:
class ParentFoo(SqlBase):
__tablename__ = "parents"
id = Column(String, primary_key=True)
children = relationship("ChildFoo", backref="parents")
class ...