forked from piccolo-orm/piccolo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_defaults.py
More file actions
108 lines (96 loc) · 3.23 KB
/
test_defaults.py
File metadata and controls
108 lines (96 loc) · 3.23 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import datetime
import decimal
from unittest import TestCase
import uuid
from piccolo.columns.column_types import (
BigInt,
Date,
DateNow,
ForeignKey,
Integer,
Numeric,
Real,
SmallInt,
Text,
Time,
TimeNow,
Timestamp,
TimestampNow,
UUID,
UUID4,
Varchar,
)
from piccolo.table import Table
class TestDefaults(TestCase):
"""
Columns check the type of the default argument.
"""
def test_int(self):
for _type in (Integer, BigInt, SmallInt):
_type(default=0)
_type(default=None, null=True)
with self.assertRaises(ValueError):
_type(default="hello world")
with self.assertRaises(ValueError):
_type(default=None, null=False)
def test_text(self):
for _type in (Text, Varchar):
_type(default="")
_type(default=None, null=True)
with self.assertRaises(ValueError):
_type(default=123)
with self.assertRaises(ValueError):
_type(default=None, null=False)
def test_real(self):
Real(default=0.0)
Real(default=None, null=True)
with self.assertRaises(ValueError):
Real(default="hello world")
with self.assertRaises(ValueError):
Real(default=None, null=False)
def test_numeric(self):
Numeric(default=decimal.Decimal(1.0))
Numeric(default=None, null=True)
with self.assertRaises(ValueError):
Numeric(default="hello world")
with self.assertRaises(ValueError):
Numeric(default=None, null=False)
def test_uuid(self):
UUID(default=None, null=True)
UUID(default=UUID4())
UUID(default=uuid.uuid4())
with self.assertRaises(ValueError):
UUID(default="hello world")
with self.assertRaises(ValueError):
UUID(default=None, null=False)
def test_time(self):
Time(default=None, null=True)
Time(default=TimeNow())
Time(default=datetime.datetime.now().time())
with self.assertRaises(ValueError):
Time(default="hello world")
with self.assertRaises(ValueError):
Time(default=None, null=False)
def test_date(self):
Date(default=None, null=True)
Date(default=DateNow())
Date(default=datetime.datetime.now().date())
with self.assertRaises(ValueError):
Date(default="hello world")
with self.assertRaises(ValueError):
Date(default=None, null=False)
def test_timestamp(self):
Timestamp(default=None, null=True)
Timestamp(default=TimestampNow())
Timestamp(default=datetime.datetime.now())
with self.assertRaises(ValueError):
Timestamp(default="hello world")
with self.assertRaises(ValueError):
Timestamp(default=None, null=False)
def test_foreignkey(self):
ForeignKey(references=Table(), default=None, null=True)
ForeignKey(references=Table(), default=1)
with self.assertRaises(ValueError):
ForeignKey(references=Table, default="hello world")
with self.assertRaises(ValueError):
ForeignKey(references=Table, default=None, null=False)