Files
deb-python-sqlalchemy-utils/tests/test_models.py
Jacob Magnusson 815f07d6c1 Use pytest fixtures to reduce complexity and repetition
Also:

Allow override of database name and user in tests (important for me as I would have to mess with my PSQL and MySQL database users otherwise)
Use dict.items instead of six.iteritems as it sporadically caused RuntimeError: dictionary changed size during iteration in Python 2.6 tests.
Fix typo DNS to DSN
Adds Python 3.5 to tox.ini
Added an .editorconfig
Import babel.dates in sqlalchemy_utils.i18n as an exception would be raised when using the latest versions of babel.
2016-01-19 10:52:30 +01:00

41 lines
937 B
Python

from datetime import datetime
import pytest
import sqlalchemy as sa
from sqlalchemy_utils import Timestamp
@pytest.fixture
def Article(Base):
class Article(Base, Timestamp):
__tablename__ = 'article'
id = sa.Column(sa.Integer, primary_key=True)
name = sa.Column(sa.Unicode(255), default=u'Some article')
return Article
class TestTimestamp(object):
def test_created(self, session, Article):
then = datetime.utcnow()
article = Article()
session.add(article)
session.commit()
assert article.created >= then and article.created <= datetime.utcnow()
def test_updated(self, session, Article):
article = Article()
session.add(article)
session.commit()
then = datetime.utcnow()
article.name = u"Something"
session.commit()
assert article.updated >= then and article.updated <= datetime.utcnow()