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
|