File: test_models.py

package info (click to toggle)
python-sqlalchemy-utils 0.30.12-2~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 1,056 kB
  • sloc: python: 10,350; makefile: 160
file content (39 lines) | stat: -rw-r--r-- 978 bytes parent folder | download | duplicates (2)
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()