forked from pallets-eco/flask-sqlalchemy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
40 lines (30 loc) · 885 Bytes
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from datetime import datetime
import flask
import pytest
from flask_sqlalchemy import SQLAlchemy
@pytest.fixture
def app(request):
app = flask.Flask(request.module.__name__)
app.testing = True
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///:memory:"
return app
@pytest.fixture
def db(app):
return SQLAlchemy(app)
@pytest.fixture
def Todo(db):
class Todo(db.Model):
__tablename__ = "todos"
id = db.Column("todo_id", db.Integer, primary_key=True)
title = db.Column(db.String(60))
text = db.Column(db.String)
done = db.Column(db.Boolean)
pub_date = db.Column(db.DateTime)
def __init__(self, title, text):
self.title = title
self.text = text
self.done = False
self.pub_date = datetime.utcnow()
db.create_all()
yield Todo
db.drop_all()