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
|
from datetime import datetime
import sqlalchemy as sa
from sqlalchemy_utils import Timestamp
from tests import TestCase
class TestTimestamp(TestCase):
def create_models(self):
class Article(self.Base, Timestamp):
__tablename__ = 'article'
id = sa.Column(sa.Integer, primary_key=True)
name = sa.Column(sa.Unicode(255), default=u'Some article')
self.Article = Article
def test_created(self):
then = datetime.utcnow()
article = self.Article()
self.session.add(article)
self.session.commit()
assert article.created >= then and article.created <= datetime.utcnow()
def test_updated(self):
article = self.Article()
self.session.add(article)
self.session.commit()
then = datetime.utcnow()
article.name = u"Something"
self.session.commit()
assert article.updated >= then and article.updated <= datetime.utcnow()
|