forked from piccolo-orm/piccolo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_time.py
More file actions
61 lines (45 loc) · 1.61 KB
/
test_time.py
File metadata and controls
61 lines (45 loc) · 1.61 KB
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
53
54
55
56
57
58
59
60
61
import datetime
from functools import partial
from unittest import TestCase
from piccolo.table import Table
from piccolo.columns.column_types import Time
from piccolo.columns.defaults.time import TimeNow
class MyTable(Table):
created_on = Time()
class MyTableDefault(Table):
created_on = Time(default=TimeNow())
class TestTime(TestCase):
def setUp(self):
MyTable.create_table().run_sync()
def tearDown(self):
MyTable.alter().drop_table().run_sync()
def test_timestamp(self):
created_on = datetime.datetime.now().time()
row = MyTable(created_on=created_on)
row.save().run_sync()
result = MyTable.objects().first().run_sync()
self.assertEqual(result.created_on, created_on)
class TestTimeDefault(TestCase):
def setUp(self):
MyTableDefault.create_table().run_sync()
def tearDown(self):
MyTableDefault.alter().drop_table().run_sync()
def test_timestamp(self):
created_on = datetime.datetime.now().time()
row = MyTableDefault()
row.save().run_sync()
_datetime = partial(datetime.datetime, year=2020, month=1, day=1)
result = MyTableDefault.objects().first().run_sync()
self.assertTrue(
_datetime(
hour=result.created_on.hour,
minute=result.created_on.minute,
second=result.created_on.second,
)
- _datetime(
hour=created_on.hour,
minute=created_on.minute,
second=created_on.second,
)
< datetime.timedelta(seconds=1)
)