File: test_arrow.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 (52 lines) | stat: -rw-r--r-- 1,510 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
40
41
42
43
44
45
46
47
48
49
50
51
52
from datetime import datetime

import sqlalchemy as sa
from pytest import mark

from sqlalchemy_utils.types import arrow
from tests import TestCase


@mark.skipif('arrow.arrow is None')
class TestArrowDateTimeType(TestCase):
    def create_models(self):
        class Article(self.Base):
            __tablename__ = 'article'
            id = sa.Column(sa.Integer, primary_key=True)
            created_at = sa.Column(arrow.ArrowType)

        self.Article = Article

    def test_parameter_processing(self):
        article = self.Article(
            created_at=arrow.arrow.get(datetime(2000, 11, 1))
        )

        self.session.add(article)
        self.session.commit()

        article = self.session.query(self.Article).first()
        assert article.created_at.datetime

    def test_string_coercion(self):
        article = self.Article(
            created_at='1367900664'
        )
        assert article.created_at.year == 2013

    def test_utc(self):
        time = arrow.arrow.utcnow()
        article = self.Article(created_at=time)
        self.session.add(article)
        assert article.created_at == time
        self.session.commit()
        assert article.created_at == time

    def test_other_tz(self):
        time = arrow.arrow.utcnow()
        local = time.to('US/Pacific')
        article = self.Article(created_at=local)
        self.session.add(article)
        assert article.created_at == time == local
        self.session.commit()
        assert article.created_at == time