forked from pallets-eco/flask-sqlalchemy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix repr and add tests (pallets-eco#1296)
- Loading branch information
Showing
3 changed files
with
73 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from __future__ import annotations | ||
|
||
from flask import Flask | ||
|
||
from flask_sqlalchemy import SQLAlchemy | ||
|
||
|
||
def test_repr_no_context() -> None: | ||
db = SQLAlchemy() | ||
app = Flask(__name__) | ||
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite://" | ||
|
||
db.init_app(app) | ||
assert repr(db) == "<SQLAlchemy>" | ||
|
||
|
||
def test_repr_default() -> None: | ||
db = SQLAlchemy() | ||
app = Flask(__name__) | ||
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite://" | ||
|
||
db.init_app(app) | ||
with app.app_context(): | ||
assert repr(db) == "<SQLAlchemy sqlite://>" | ||
|
||
|
||
def test_repr_default_plustwo() -> None: | ||
db = SQLAlchemy() | ||
app = Flask(__name__) | ||
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite://" | ||
app.config["SQLALCHEMY_BINDS"] = { | ||
"a": "sqlite:///:memory:", | ||
"b": "sqlite:///test.db", | ||
} | ||
|
||
db.init_app(app) | ||
with app.app_context(): | ||
assert repr(db) == "<SQLAlchemy sqlite:// +2 engines>" | ||
|
||
|
||
def test_repr_nodefault() -> None: | ||
db = SQLAlchemy() | ||
app = Flask(__name__) | ||
app.config["SQLALCHEMY_BINDS"] = {"x": "sqlite:///:memory:"} | ||
|
||
db.init_app(app) | ||
with app.app_context(): | ||
assert repr(db) == "<SQLAlchemy (No default engine) +1 engines>" | ||
|
||
|
||
def test_repr_nodefault_plustwo() -> None: | ||
db = SQLAlchemy() | ||
app = Flask(__name__) | ||
app.config["SQLALCHEMY_BINDS"] = { | ||
"a": "sqlite:///:memory:", | ||
"b": "sqlite:///test.db", | ||
} | ||
|
||
db.init_app(app) | ||
with app.app_context(): | ||
assert repr(db) == "<SQLAlchemy (No default engine) +2 engines>" |