piccolo 1.10.0__py3-none-any.whl → 1.12.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- piccolo/__init__.py +1 -1
- piccolo/apps/asgi/commands/templates/app/_fastapi_app.py.jinja +35 -30
- piccolo/apps/asgi/commands/templates/app/_starlette_app.py.jinja +29 -21
- piccolo/apps/migrations/auto/migration_manager.py +1 -0
- piccolo/apps/migrations/commands/forwards.py +8 -7
- piccolo/apps/playground/commands/run.py +11 -0
- piccolo/columns/column_types.py +83 -35
- piccolo/query/functions/__init__.py +11 -1
- piccolo/query/functions/datetime.py +260 -0
- piccolo/query/functions/string.py +45 -0
- {piccolo-1.10.0.dist-info → piccolo-1.12.0.dist-info}/METADATA +15 -15
- {piccolo-1.10.0.dist-info → piccolo-1.12.0.dist-info}/RECORD +42 -40
- {piccolo-1.10.0.dist-info → piccolo-1.12.0.dist-info}/WHEEL +1 -1
- tests/apps/migrations/commands/test_forwards_backwards.py +32 -1
- tests/columns/test_array.py +3 -7
- tests/columns/test_bigint.py +3 -9
- tests/columns/test_boolean.py +3 -7
- tests/columns/test_bytea.py +5 -14
- tests/columns/test_choices.py +5 -14
- tests/columns/test_date.py +5 -13
- tests/columns/test_double_precision.py +3 -8
- tests/columns/test_interval.py +5 -13
- tests/columns/test_json.py +9 -26
- tests/columns/test_jsonb.py +3 -11
- tests/columns/test_numeric.py +3 -7
- tests/columns/test_primary_key.py +11 -33
- tests/columns/test_readable.py +5 -7
- tests/columns/test_real.py +3 -8
- tests/columns/test_reserved_column_names.py +3 -8
- tests/columns/test_smallint.py +3 -8
- tests/columns/test_time.py +5 -14
- tests/columns/test_timestamp.py +5 -13
- tests/columns/test_timestamptz.py +5 -13
- tests/columns/test_uuid.py +3 -7
- tests/columns/test_varchar.py +3 -9
- tests/query/functions/base.py +2 -15
- tests/query/functions/test_datetime.py +112 -0
- tests/query/functions/test_math.py +2 -3
- tests/query/functions/test_string.py +34 -2
- {piccolo-1.10.0.dist-info → piccolo-1.12.0.dist-info}/LICENSE +0 -0
- {piccolo-1.10.0.dist-info → piccolo-1.12.0.dist-info}/entry_points.txt +0 -0
- {piccolo-1.10.0.dist-info → piccolo-1.12.0.dist-info}/top_level.txt +0 -0
tests/columns/test_boolean.py
CHANGED
@@ -1,20 +1,16 @@
|
|
1
1
|
import typing as t
|
2
|
-
from unittest import TestCase
|
3
2
|
|
4
3
|
from piccolo.columns.column_types import Boolean
|
5
4
|
from piccolo.table import Table
|
5
|
+
from tests.base import TableTest
|
6
6
|
|
7
7
|
|
8
8
|
class MyTable(Table):
|
9
9
|
boolean = Boolean(boolean=False, null=True)
|
10
10
|
|
11
11
|
|
12
|
-
class TestBoolean(
|
13
|
-
|
14
|
-
MyTable.create_table().run_sync()
|
15
|
-
|
16
|
-
def tearDown(self):
|
17
|
-
MyTable.alter().drop_table().run_sync()
|
12
|
+
class TestBoolean(TableTest):
|
13
|
+
tables = [MyTable]
|
18
14
|
|
19
15
|
def test_return_type(self) -> None:
|
20
16
|
for value in (True, False, None, ...):
|
tests/columns/test_bytea.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
from unittest import TestCase
|
2
|
-
|
3
1
|
from piccolo.columns.column_types import Bytea
|
4
2
|
from piccolo.table import Table
|
3
|
+
from tests.base import TableTest
|
5
4
|
|
6
5
|
|
7
6
|
class MyTable(Table):
|
@@ -19,12 +18,8 @@ class MyTableDefault(Table):
|
|
19
18
|
token_none = Bytea(default=None, null=True)
|
20
19
|
|
21
20
|
|
22
|
-
class TestBytea(
|
23
|
-
|
24
|
-
MyTable.create_table().run_sync()
|
25
|
-
|
26
|
-
def tearDown(self):
|
27
|
-
MyTable.alter().drop_table().run_sync()
|
21
|
+
class TestBytea(TableTest):
|
22
|
+
tables = [MyTable]
|
28
23
|
|
29
24
|
def test_bytea(self):
|
30
25
|
"""
|
@@ -40,12 +35,8 @@ class TestBytea(TestCase):
|
|
40
35
|
)
|
41
36
|
|
42
37
|
|
43
|
-
class TestByteaDefault(
|
44
|
-
|
45
|
-
MyTableDefault.create_table().run_sync()
|
46
|
-
|
47
|
-
def tearDown(self):
|
48
|
-
MyTableDefault.alter().drop_table().run_sync()
|
38
|
+
class TestByteaDefault(TableTest):
|
39
|
+
tables = [MyTableDefault]
|
49
40
|
|
50
41
|
def test_json_default(self):
|
51
42
|
row = MyTableDefault()
|
tests/columns/test_choices.py
CHANGED
@@ -1,18 +1,13 @@
|
|
1
1
|
import enum
|
2
|
-
from unittest import TestCase
|
3
2
|
|
4
3
|
from piccolo.columns.column_types import Array, Varchar
|
5
4
|
from piccolo.table import Table
|
6
|
-
from tests.base import engines_only
|
5
|
+
from tests.base import TableTest, engines_only
|
7
6
|
from tests.example_apps.music.tables import Shirt
|
8
7
|
|
9
8
|
|
10
|
-
class TestChoices(
|
11
|
-
|
12
|
-
Shirt.create_table().run_sync()
|
13
|
-
|
14
|
-
def tearDown(self):
|
15
|
-
Shirt.alter().drop_table().run_sync()
|
9
|
+
class TestChoices(TableTest):
|
10
|
+
tables = [Shirt]
|
16
11
|
|
17
12
|
def _insert_shirts(self):
|
18
13
|
Shirt.insert(
|
@@ -87,16 +82,12 @@ class Ticket(Table):
|
|
87
82
|
|
88
83
|
|
89
84
|
@engines_only("postgres", "sqlite")
|
90
|
-
class TestArrayChoices(
|
85
|
+
class TestArrayChoices(TableTest):
|
91
86
|
"""
|
92
87
|
🐛 Cockroach bug: https://github.com/cockroachdb/cockroach/issues/71908 "could not decorrelate subquery" error under asyncpg
|
93
88
|
""" # noqa: E501
|
94
89
|
|
95
|
-
|
96
|
-
Ticket.create_table().run_sync()
|
97
|
-
|
98
|
-
def tearDown(self):
|
99
|
-
Ticket.alter().drop_table().run_sync()
|
90
|
+
tables = [Ticket]
|
100
91
|
|
101
92
|
def test_string(self):
|
102
93
|
"""
|
tests/columns/test_date.py
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
import datetime
|
2
|
-
from unittest import TestCase
|
3
2
|
|
4
3
|
from piccolo.columns.column_types import Date
|
5
4
|
from piccolo.columns.defaults.date import DateNow
|
6
5
|
from piccolo.table import Table
|
6
|
+
from tests.base import TableTest
|
7
7
|
|
8
8
|
|
9
9
|
class MyTable(Table):
|
@@ -14,12 +14,8 @@ class MyTableDefault(Table):
|
|
14
14
|
created_on = Date(default=DateNow())
|
15
15
|
|
16
16
|
|
17
|
-
class TestDate(
|
18
|
-
|
19
|
-
MyTable.create_table().run_sync()
|
20
|
-
|
21
|
-
def tearDown(self):
|
22
|
-
MyTable.alter().drop_table().run_sync()
|
17
|
+
class TestDate(TableTest):
|
18
|
+
tables = [MyTable]
|
23
19
|
|
24
20
|
def test_timestamp(self):
|
25
21
|
created_on = datetime.datetime.now().date()
|
@@ -31,12 +27,8 @@ class TestDate(TestCase):
|
|
31
27
|
self.assertEqual(result.created_on, created_on)
|
32
28
|
|
33
29
|
|
34
|
-
class TestDateDefault(
|
35
|
-
|
36
|
-
MyTableDefault.create_table().run_sync()
|
37
|
-
|
38
|
-
def tearDown(self):
|
39
|
-
MyTableDefault.alter().drop_table().run_sync()
|
30
|
+
class TestDateDefault(TableTest):
|
31
|
+
tables = [MyTableDefault]
|
40
32
|
|
41
33
|
def test_timestamp(self):
|
42
34
|
created_on = datetime.datetime.now().date()
|
@@ -1,19 +1,14 @@
|
|
1
|
-
from unittest import TestCase
|
2
|
-
|
3
1
|
from piccolo.columns.column_types import DoublePrecision
|
4
2
|
from piccolo.table import Table
|
3
|
+
from tests.base import TableTest
|
5
4
|
|
6
5
|
|
7
6
|
class MyTable(Table):
|
8
7
|
column_a = DoublePrecision()
|
9
8
|
|
10
9
|
|
11
|
-
class TestDoublePrecision(
|
12
|
-
|
13
|
-
MyTable.create_table().run_sync()
|
14
|
-
|
15
|
-
def tearDown(self):
|
16
|
-
MyTable.alter().drop_table().run_sync()
|
10
|
+
class TestDoublePrecision(TableTest):
|
11
|
+
tables = [MyTable]
|
17
12
|
|
18
13
|
def test_creation(self):
|
19
14
|
row = MyTable(column_a=1.23)
|
tests/columns/test_interval.py
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
import datetime
|
2
|
-
from unittest import TestCase
|
3
2
|
|
4
3
|
from piccolo.columns.column_types import Interval
|
5
4
|
from piccolo.columns.defaults.interval import IntervalCustom
|
6
5
|
from piccolo.table import Table
|
6
|
+
from tests.base import TableTest
|
7
7
|
|
8
8
|
|
9
9
|
class MyTable(Table):
|
@@ -14,12 +14,8 @@ class MyTableDefault(Table):
|
|
14
14
|
interval = Interval(default=IntervalCustom(days=1))
|
15
15
|
|
16
16
|
|
17
|
-
class TestInterval(
|
18
|
-
|
19
|
-
MyTable.create_table().run_sync()
|
20
|
-
|
21
|
-
def tearDown(self):
|
22
|
-
MyTable.alter().drop_table().run_sync()
|
17
|
+
class TestInterval(TableTest):
|
18
|
+
tables = [MyTable]
|
23
19
|
|
24
20
|
def test_interval(self):
|
25
21
|
# Test a range of different timedeltas
|
@@ -91,12 +87,8 @@ class TestInterval(TestCase):
|
|
91
87
|
self.assertTrue(result)
|
92
88
|
|
93
89
|
|
94
|
-
class TestIntervalDefault(
|
95
|
-
|
96
|
-
MyTableDefault.create_table().run_sync()
|
97
|
-
|
98
|
-
def tearDown(self):
|
99
|
-
MyTableDefault.alter().drop_table().run_sync()
|
90
|
+
class TestIntervalDefault(TableTest):
|
91
|
+
tables = [MyTableDefault]
|
100
92
|
|
101
93
|
def test_interval(self):
|
102
94
|
row = MyTableDefault()
|
tests/columns/test_json.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
from unittest import TestCase
|
2
|
-
|
3
1
|
from piccolo.columns.column_types import JSON
|
4
2
|
from piccolo.table import Table
|
3
|
+
from tests.base import TableTest
|
5
4
|
|
6
5
|
|
7
6
|
class MyTable(Table):
|
@@ -20,12 +19,8 @@ class MyTableDefault(Table):
|
|
20
19
|
json_none = JSON(default=None, null=True)
|
21
20
|
|
22
21
|
|
23
|
-
class TestJSONSave(
|
24
|
-
|
25
|
-
MyTable.create_table().run_sync()
|
26
|
-
|
27
|
-
def tearDown(self):
|
28
|
-
MyTable.alter().drop_table().run_sync()
|
22
|
+
class TestJSONSave(TableTest):
|
23
|
+
tables = [MyTable]
|
29
24
|
|
30
25
|
def test_json_string(self):
|
31
26
|
"""
|
@@ -58,12 +53,8 @@ class TestJSONSave(TestCase):
|
|
58
53
|
)
|
59
54
|
|
60
55
|
|
61
|
-
class TestJSONDefault(
|
62
|
-
|
63
|
-
MyTableDefault.create_table().run_sync()
|
64
|
-
|
65
|
-
def tearDown(self):
|
66
|
-
MyTableDefault.alter().drop_table().run_sync()
|
56
|
+
class TestJSONDefault(TableTest):
|
57
|
+
tables = [MyTableDefault]
|
67
58
|
|
68
59
|
def test_json_default(self):
|
69
60
|
row = MyTableDefault()
|
@@ -81,12 +72,8 @@ class TestJSONDefault(TestCase):
|
|
81
72
|
JSON(default=value) # type: ignore
|
82
73
|
|
83
74
|
|
84
|
-
class TestJSONInsert(
|
85
|
-
|
86
|
-
MyTable.create_table().run_sync()
|
87
|
-
|
88
|
-
def tearDown(self):
|
89
|
-
MyTable.alter().drop_table().run_sync()
|
75
|
+
class TestJSONInsert(TableTest):
|
76
|
+
tables = [MyTable]
|
90
77
|
|
91
78
|
def check_response(self):
|
92
79
|
row = MyTable.select(MyTable.json).first().run_sync()
|
@@ -112,12 +99,8 @@ class TestJSONInsert(TestCase):
|
|
112
99
|
MyTable.insert(row).run_sync()
|
113
100
|
|
114
101
|
|
115
|
-
class TestJSONUpdate(
|
116
|
-
|
117
|
-
MyTable.create_table().run_sync()
|
118
|
-
|
119
|
-
def tearDown(self):
|
120
|
-
MyTable.alter().drop_table().run_sync()
|
102
|
+
class TestJSONUpdate(TableTest):
|
103
|
+
tables = [MyTable]
|
121
104
|
|
122
105
|
def add_row(self):
|
123
106
|
row = MyTable(json={"message": "original"})
|
tests/columns/test_jsonb.py
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
from unittest import TestCase
|
2
|
-
|
3
1
|
from piccolo.columns.column_types import JSONB, ForeignKey, Varchar
|
4
2
|
from piccolo.table import Table
|
5
|
-
from tests.base import engines_only, engines_skip
|
3
|
+
from tests.base import TableTest, engines_only, engines_skip
|
6
4
|
|
7
5
|
|
8
6
|
class RecordingStudio(Table):
|
@@ -16,14 +14,8 @@ class Instrument(Table):
|
|
16
14
|
|
17
15
|
|
18
16
|
@engines_only("postgres", "cockroach")
|
19
|
-
class TestJSONB(
|
20
|
-
|
21
|
-
RecordingStudio.create_table().run_sync()
|
22
|
-
Instrument.create_table().run_sync()
|
23
|
-
|
24
|
-
def tearDown(self):
|
25
|
-
Instrument.alter().drop_table().run_sync()
|
26
|
-
RecordingStudio.alter().drop_table().run_sync()
|
17
|
+
class TestJSONB(TableTest):
|
18
|
+
tables = [RecordingStudio, Instrument]
|
27
19
|
|
28
20
|
def test_json(self):
|
29
21
|
"""
|
tests/columns/test_numeric.py
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
from decimal import Decimal
|
2
|
-
from unittest import TestCase
|
3
2
|
|
4
3
|
from piccolo.columns.column_types import Numeric
|
5
4
|
from piccolo.table import Table
|
5
|
+
from tests.base import TableTest
|
6
6
|
|
7
7
|
|
8
8
|
class MyTable(Table):
|
@@ -10,12 +10,8 @@ class MyTable(Table):
|
|
10
10
|
column_b = Numeric(digits=(3, 2))
|
11
11
|
|
12
12
|
|
13
|
-
class TestNumeric(
|
14
|
-
|
15
|
-
MyTable.create_table().run_sync()
|
16
|
-
|
17
|
-
def tearDown(self):
|
18
|
-
MyTable.alter().drop_table().run_sync()
|
13
|
+
class TestNumeric(TableTest):
|
14
|
+
tables = [MyTable]
|
19
15
|
|
20
16
|
def test_creation(self):
|
21
17
|
row = MyTable(column_a=Decimal(1.23), column_b=Decimal(1.23))
|
@@ -1,5 +1,4 @@
|
|
1
1
|
import uuid
|
2
|
-
from unittest import TestCase
|
3
2
|
|
4
3
|
from piccolo.columns.column_types import (
|
5
4
|
UUID,
|
@@ -9,6 +8,7 @@ from piccolo.columns.column_types import (
|
|
9
8
|
Varchar,
|
10
9
|
)
|
11
10
|
from piccolo.table import Table
|
11
|
+
from tests.base import TableTest
|
12
12
|
|
13
13
|
|
14
14
|
class MyTableDefaultPrimaryKey(Table):
|
@@ -30,12 +30,8 @@ class MyTablePrimaryKeyUUID(Table):
|
|
30
30
|
name = Varchar()
|
31
31
|
|
32
32
|
|
33
|
-
class TestPrimaryKeyDefault(
|
34
|
-
|
35
|
-
MyTableDefaultPrimaryKey.create_table().run_sync()
|
36
|
-
|
37
|
-
def tearDown(self):
|
38
|
-
MyTableDefaultPrimaryKey.alter().drop_table().run_sync()
|
33
|
+
class TestPrimaryKeyDefault(TableTest):
|
34
|
+
tables = [MyTableDefaultPrimaryKey]
|
39
35
|
|
40
36
|
def test_return_type(self):
|
41
37
|
row = MyTableDefaultPrimaryKey()
|
@@ -45,12 +41,8 @@ class TestPrimaryKeyDefault(TestCase):
|
|
45
41
|
self.assertIsInstance(row["id"], int)
|
46
42
|
|
47
43
|
|
48
|
-
class TestPrimaryKeyInteger(
|
49
|
-
|
50
|
-
MyTablePrimaryKeySerial.create_table().run_sync()
|
51
|
-
|
52
|
-
def tearDown(self):
|
53
|
-
MyTablePrimaryKeySerial.alter().drop_table().run_sync()
|
44
|
+
class TestPrimaryKeyInteger(TableTest):
|
45
|
+
tables = [MyTablePrimaryKeySerial]
|
54
46
|
|
55
47
|
def test_return_type(self):
|
56
48
|
row = MyTablePrimaryKeySerial()
|
@@ -60,12 +52,8 @@ class TestPrimaryKeyInteger(TestCase):
|
|
60
52
|
self.assertIsInstance(row["pk"], int)
|
61
53
|
|
62
54
|
|
63
|
-
class TestPrimaryKeyBigSerial(
|
64
|
-
|
65
|
-
MyTablePrimaryKeyBigSerial.create_table().run_sync()
|
66
|
-
|
67
|
-
def tearDown(self):
|
68
|
-
MyTablePrimaryKeyBigSerial.alter().drop_table().run_sync()
|
55
|
+
class TestPrimaryKeyBigSerial(TableTest):
|
56
|
+
tables = [MyTablePrimaryKeyBigSerial]
|
69
57
|
|
70
58
|
def test_return_type(self):
|
71
59
|
row = MyTablePrimaryKeyBigSerial()
|
@@ -75,12 +63,8 @@ class TestPrimaryKeyBigSerial(TestCase):
|
|
75
63
|
self.assertIsInstance(row["pk"], int)
|
76
64
|
|
77
65
|
|
78
|
-
class TestPrimaryKeyUUID(
|
79
|
-
|
80
|
-
MyTablePrimaryKeyUUID.create_table().run_sync()
|
81
|
-
|
82
|
-
def tearDown(self):
|
83
|
-
MyTablePrimaryKeyUUID.alter().drop_table().run_sync()
|
66
|
+
class TestPrimaryKeyUUID(TableTest):
|
67
|
+
tables = [MyTablePrimaryKeyUUID]
|
84
68
|
|
85
69
|
def test_return_type(self):
|
86
70
|
row = MyTablePrimaryKeyUUID()
|
@@ -101,14 +85,8 @@ class Band(Table):
|
|
101
85
|
manager = ForeignKey(Manager)
|
102
86
|
|
103
87
|
|
104
|
-
class TestPrimaryKeyQueries(
|
105
|
-
|
106
|
-
Manager.create_table().run_sync()
|
107
|
-
Band.create_table().run_sync()
|
108
|
-
|
109
|
-
def tearDown(self):
|
110
|
-
Band.alter().drop_table().run_sync()
|
111
|
-
Manager.alter().drop_table().run_sync()
|
88
|
+
class TestPrimaryKeyQueries(TableTest):
|
89
|
+
tables = [Manager, Band]
|
112
90
|
|
113
91
|
def test_primary_key_queries(self):
|
114
92
|
"""
|
tests/columns/test_readable.py
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
import unittest
|
2
|
-
|
3
1
|
from piccolo import columns
|
4
2
|
from piccolo.columns.readable import Readable
|
5
3
|
from piccolo.table import Table
|
4
|
+
from tests.base import TableTest
|
6
5
|
|
7
6
|
|
8
7
|
class MyTable(Table):
|
@@ -16,14 +15,13 @@ class MyTable(Table):
|
|
16
15
|
)
|
17
16
|
|
18
17
|
|
19
|
-
class TestReadable(
|
18
|
+
class TestReadable(TableTest):
|
19
|
+
tables = [MyTable]
|
20
|
+
|
20
21
|
def setUp(self):
|
21
|
-
|
22
|
+
super().setUp()
|
22
23
|
MyTable(first_name="Guido", last_name="van Rossum").save().run_sync()
|
23
24
|
|
24
25
|
def test_readable(self):
|
25
26
|
response = MyTable.select(MyTable.get_readable()).run_sync()
|
26
27
|
self.assertEqual(response[0]["readable"], "Guido van Rossum")
|
27
|
-
|
28
|
-
def tearDown(self):
|
29
|
-
MyTable.alter().drop_table().run_sync()
|
tests/columns/test_real.py
CHANGED
@@ -1,19 +1,14 @@
|
|
1
|
-
from unittest import TestCase
|
2
|
-
|
3
1
|
from piccolo.columns.column_types import Real
|
4
2
|
from piccolo.table import Table
|
3
|
+
from tests.base import TableTest
|
5
4
|
|
6
5
|
|
7
6
|
class MyTable(Table):
|
8
7
|
column_a = Real()
|
9
8
|
|
10
9
|
|
11
|
-
class TestReal(
|
12
|
-
|
13
|
-
MyTable.create_table().run_sync()
|
14
|
-
|
15
|
-
def tearDown(self):
|
16
|
-
MyTable.alter().drop_table().run_sync()
|
10
|
+
class TestReal(TableTest):
|
11
|
+
tables = [MyTable]
|
17
12
|
|
18
13
|
def test_creation(self):
|
19
14
|
row = MyTable(column_a=1.23)
|
@@ -1,7 +1,6 @@
|
|
1
|
-
from unittest import TestCase
|
2
|
-
|
3
1
|
from piccolo.columns.column_types import Integer, Varchar
|
4
2
|
from piccolo.table import Table
|
3
|
+
from tests.base import TableTest
|
5
4
|
|
6
5
|
|
7
6
|
class Concert(Table):
|
@@ -16,17 +15,13 @@ class Concert(Table):
|
|
16
15
|
order = Integer()
|
17
16
|
|
18
17
|
|
19
|
-
class TestReservedColumnNames(
|
18
|
+
class TestReservedColumnNames(TableTest):
|
20
19
|
"""
|
21
20
|
Make sure the table works as expected, even though it has a problematic
|
22
21
|
column name.
|
23
22
|
"""
|
24
23
|
|
25
|
-
|
26
|
-
Concert.create_table().run_sync()
|
27
|
-
|
28
|
-
def tearDown(self):
|
29
|
-
Concert.alter().drop_table().run_sync()
|
24
|
+
tables = [Concert]
|
30
25
|
|
31
26
|
def test_common_operations(self):
|
32
27
|
# Save / Insert
|
tests/columns/test_smallint.py
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
import os
|
2
|
-
from unittest import TestCase
|
3
2
|
|
4
3
|
from piccolo.columns.column_types import SmallInt
|
5
4
|
from piccolo.table import Table
|
6
5
|
|
7
|
-
from ..base import engines_only
|
6
|
+
from ..base import TableTest, engines_only
|
8
7
|
|
9
8
|
|
10
9
|
class MyTable(Table):
|
@@ -12,16 +11,12 @@ class MyTable(Table):
|
|
12
11
|
|
13
12
|
|
14
13
|
@engines_only("postgres", "cockroach")
|
15
|
-
class TestSmallIntPostgres(
|
14
|
+
class TestSmallIntPostgres(TableTest):
|
16
15
|
"""
|
17
16
|
Make sure a SmallInt column in Postgres can only store small numbers.
|
18
17
|
"""
|
19
18
|
|
20
|
-
|
21
|
-
MyTable.create_table().run_sync()
|
22
|
-
|
23
|
-
def tearDown(self):
|
24
|
-
MyTable.alter().drop_table().run_sync()
|
19
|
+
tables = [MyTable]
|
25
20
|
|
26
21
|
def _test_length(self):
|
27
22
|
# Can store 2 bytes, but split between positive and negative values.
|
tests/columns/test_time.py
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
import datetime
|
2
2
|
from functools import partial
|
3
|
-
from unittest import TestCase
|
4
3
|
|
5
4
|
from piccolo.columns.column_types import Time
|
6
5
|
from piccolo.columns.defaults.time import TimeNow
|
7
6
|
from piccolo.table import Table
|
8
|
-
from tests.base import engines_skip
|
7
|
+
from tests.base import TableTest, engines_skip
|
9
8
|
|
10
9
|
|
11
10
|
class MyTable(Table):
|
@@ -16,12 +15,8 @@ class MyTableDefault(Table):
|
|
16
15
|
created_on = Time(default=TimeNow())
|
17
16
|
|
18
17
|
|
19
|
-
class TestTime(
|
20
|
-
|
21
|
-
MyTable.create_table().run_sync()
|
22
|
-
|
23
|
-
def tearDown(self):
|
24
|
-
MyTable.alter().drop_table().run_sync()
|
18
|
+
class TestTime(TableTest):
|
19
|
+
tables = [MyTable]
|
25
20
|
|
26
21
|
@engines_skip("cockroach")
|
27
22
|
def test_timestamp(self):
|
@@ -34,12 +29,8 @@ class TestTime(TestCase):
|
|
34
29
|
self.assertEqual(result.created_on, created_on)
|
35
30
|
|
36
31
|
|
37
|
-
class TestTimeDefault(
|
38
|
-
|
39
|
-
MyTableDefault.create_table().run_sync()
|
40
|
-
|
41
|
-
def tearDown(self):
|
42
|
-
MyTableDefault.alter().drop_table().run_sync()
|
32
|
+
class TestTimeDefault(TableTest):
|
33
|
+
tables = [MyTableDefault]
|
43
34
|
|
44
35
|
@engines_skip("cockroach")
|
45
36
|
def test_timestamp(self):
|
tests/columns/test_timestamp.py
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
import datetime
|
2
|
-
from unittest import TestCase
|
3
2
|
|
4
3
|
from piccolo.columns.column_types import Timestamp
|
5
4
|
from piccolo.columns.defaults.timestamp import TimestampNow
|
6
5
|
from piccolo.table import Table
|
6
|
+
from tests.base import TableTest
|
7
7
|
|
8
8
|
|
9
9
|
class MyTable(Table):
|
@@ -19,12 +19,8 @@ class MyTableDefault(Table):
|
|
19
19
|
created_on = Timestamp(default=TimestampNow())
|
20
20
|
|
21
21
|
|
22
|
-
class TestTimestamp(
|
23
|
-
|
24
|
-
MyTable.create_table().run_sync()
|
25
|
-
|
26
|
-
def tearDown(self):
|
27
|
-
MyTable.alter().drop_table().run_sync()
|
22
|
+
class TestTimestamp(TableTest):
|
23
|
+
tables = [MyTable]
|
28
24
|
|
29
25
|
def test_timestamp(self):
|
30
26
|
"""
|
@@ -46,12 +42,8 @@ class TestTimestamp(TestCase):
|
|
46
42
|
Timestamp(default=datetime.datetime.now(tz=datetime.timezone.utc))
|
47
43
|
|
48
44
|
|
49
|
-
class TestTimestampDefault(
|
50
|
-
|
51
|
-
MyTableDefault.create_table().run_sync()
|
52
|
-
|
53
|
-
def tearDown(self):
|
54
|
-
MyTableDefault.alter().drop_table().run_sync()
|
45
|
+
class TestTimestampDefault(TableTest):
|
46
|
+
tables = [MyTableDefault]
|
55
47
|
|
56
48
|
def test_timestamp(self):
|
57
49
|
"""
|
@@ -1,5 +1,4 @@
|
|
1
1
|
import datetime
|
2
|
-
from unittest import TestCase
|
3
2
|
|
4
3
|
from dateutil import tz
|
5
4
|
|
@@ -10,6 +9,7 @@ from piccolo.columns.defaults.timestamptz import (
|
|
10
9
|
TimestamptzOffset,
|
11
10
|
)
|
12
11
|
from piccolo.table import Table
|
12
|
+
from tests.base import TableTest
|
13
13
|
|
14
14
|
|
15
15
|
class MyTable(Table):
|
@@ -34,12 +34,8 @@ class CustomTimezone(datetime.tzinfo):
|
|
34
34
|
pass
|
35
35
|
|
36
36
|
|
37
|
-
class TestTimestamptz(
|
38
|
-
|
39
|
-
MyTable.create_table().run_sync()
|
40
|
-
|
41
|
-
def tearDown(self):
|
42
|
-
MyTable.alter().drop_table().run_sync()
|
37
|
+
class TestTimestamptz(TableTest):
|
38
|
+
tables = [MyTable]
|
43
39
|
|
44
40
|
def test_timestamptz_timezone_aware(self):
|
45
41
|
"""
|
@@ -78,12 +74,8 @@ class TestTimestamptz(TestCase):
|
|
78
74
|
self.assertEqual(result.created_on.tzinfo, datetime.timezone.utc)
|
79
75
|
|
80
76
|
|
81
|
-
class TestTimestamptzDefault(
|
82
|
-
|
83
|
-
MyTableDefault.create_table().run_sync()
|
84
|
-
|
85
|
-
def tearDown(self):
|
86
|
-
MyTableDefault.alter().drop_table().run_sync()
|
77
|
+
class TestTimestamptzDefault(TableTest):
|
78
|
+
tables = [MyTableDefault]
|
87
79
|
|
88
80
|
def test_timestamptz_default(self):
|
89
81
|
"""
|
tests/columns/test_uuid.py
CHANGED
@@ -1,20 +1,16 @@
|
|
1
1
|
import uuid
|
2
|
-
from unittest import TestCase
|
3
2
|
|
4
3
|
from piccolo.columns.column_types import UUID
|
5
4
|
from piccolo.table import Table
|
5
|
+
from tests.base import TableTest
|
6
6
|
|
7
7
|
|
8
8
|
class MyTable(Table):
|
9
9
|
uuid = UUID()
|
10
10
|
|
11
11
|
|
12
|
-
class TestUUID(
|
13
|
-
|
14
|
-
MyTable.create_table().run_sync()
|
15
|
-
|
16
|
-
def tearDown(self):
|
17
|
-
MyTable.alter().drop_table().run_sync()
|
12
|
+
class TestUUID(TableTest):
|
13
|
+
tables = [MyTable]
|
18
14
|
|
19
15
|
def test_return_type(self):
|
20
16
|
row = MyTable()
|