piccolo 1.5.1__py3-none-any.whl → 1.6.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/playground/commands/run.py +70 -18
- piccolo/columns/base.py +31 -40
- piccolo/columns/column_types.py +11 -8
- piccolo/columns/m2m.py +16 -6
- piccolo/columns/readable.py +9 -7
- piccolo/query/__init__.py +1 -4
- piccolo/query/base.py +1 -5
- piccolo/query/functions/__init__.py +16 -0
- piccolo/query/functions/aggregate.py +179 -0
- piccolo/query/functions/base.py +21 -0
- piccolo/query/functions/string.py +73 -0
- piccolo/query/methods/__init__.py +18 -1
- piccolo/query/methods/count.py +3 -3
- piccolo/query/methods/delete.py +1 -1
- piccolo/query/methods/exists.py +1 -1
- piccolo/query/methods/objects.py +1 -1
- piccolo/query/methods/select.py +17 -232
- piccolo/query/methods/update.py +1 -1
- piccolo/query/mixins.py +9 -2
- piccolo/querystring.py +101 -13
- piccolo/table.py +8 -24
- {piccolo-1.5.1.dist-info → piccolo-1.6.0.dist-info}/METADATA +1 -1
- {piccolo-1.5.1.dist-info → piccolo-1.6.0.dist-info}/RECORD +35 -30
- tests/apps/migrations/commands/test_forwards_backwards.py +3 -0
- tests/apps/shell/commands/test_run.py +1 -0
- tests/conf/test_apps.py +6 -0
- tests/example_apps/music/tables.py +10 -0
- tests/query/test_functions.py +102 -0
- tests/table/test_output.py +88 -36
- tests/table/test_select.py +2 -9
- {piccolo-1.5.1.dist-info → piccolo-1.6.0.dist-info}/LICENSE +0 -0
- {piccolo-1.5.1.dist-info → piccolo-1.6.0.dist-info}/WHEEL +0 -0
- {piccolo-1.5.1.dist-info → piccolo-1.6.0.dist-info}/entry_points.txt +0 -0
- {piccolo-1.5.1.dist-info → piccolo-1.6.0.dist-info}/top_level.txt +0 -0
tests/table/test_output.py
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
import json
|
2
2
|
from unittest import TestCase
|
3
3
|
|
4
|
-
from
|
5
|
-
from tests.
|
4
|
+
from piccolo.table import create_db_tables_sync, drop_db_tables_sync
|
5
|
+
from tests.base import DBTestCase
|
6
|
+
from tests.example_apps.music.tables import Band, Instrument, RecordingStudio
|
6
7
|
|
7
8
|
|
8
9
|
class TestOutputList(DBTestCase):
|
@@ -32,51 +33,102 @@ class TestOutputJSON(DBTestCase):
|
|
32
33
|
|
33
34
|
|
34
35
|
class TestOutputLoadJSON(TestCase):
|
36
|
+
tables = [RecordingStudio, Instrument]
|
37
|
+
json = {"a": 123}
|
38
|
+
|
35
39
|
def setUp(self):
|
36
|
-
|
40
|
+
create_db_tables_sync(*self.tables)
|
41
|
+
|
42
|
+
recording_studio = RecordingStudio(
|
43
|
+
{
|
44
|
+
RecordingStudio.facilities: self.json,
|
45
|
+
RecordingStudio.facilities_b: self.json,
|
46
|
+
}
|
47
|
+
)
|
48
|
+
recording_studio.save().run_sync()
|
49
|
+
|
50
|
+
instrument = Instrument(
|
51
|
+
{
|
52
|
+
Instrument.recording_studio: recording_studio,
|
53
|
+
Instrument.name: "Piccolo",
|
54
|
+
}
|
55
|
+
)
|
56
|
+
instrument.save().run_sync()
|
37
57
|
|
38
58
|
def tearDown(self):
|
39
|
-
|
59
|
+
drop_db_tables_sync(*self.tables)
|
40
60
|
|
41
61
|
def test_select(self):
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
results = RecordingStudio.select().output(load_json=True).run_sync()
|
47
|
-
|
48
|
-
if engine_is("cockroach"):
|
49
|
-
self.assertEqual(
|
50
|
-
results,
|
51
|
-
[
|
52
|
-
{
|
53
|
-
"id": results[0]["id"],
|
54
|
-
"facilities": {"a": 123},
|
55
|
-
"facilities_b": {"a": 123},
|
56
|
-
}
|
57
|
-
],
|
62
|
+
results = (
|
63
|
+
RecordingStudio.select(
|
64
|
+
RecordingStudio.facilities, RecordingStudio.facilities_b
|
58
65
|
)
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
66
|
+
.output(load_json=True)
|
67
|
+
.run_sync()
|
68
|
+
)
|
69
|
+
|
70
|
+
self.assertEqual(
|
71
|
+
results,
|
72
|
+
[
|
73
|
+
{
|
74
|
+
"facilities": self.json,
|
75
|
+
"facilities_b": self.json,
|
76
|
+
}
|
77
|
+
],
|
78
|
+
)
|
79
|
+
|
80
|
+
def test_join(self):
|
81
|
+
"""
|
82
|
+
Make sure it works correctly when the JSON column is on a joined table.
|
83
|
+
|
84
|
+
https://github.com/piccolo-orm/piccolo/issues/1001
|
85
|
+
|
86
|
+
"""
|
87
|
+
results = (
|
88
|
+
Instrument.select(
|
89
|
+
Instrument.name,
|
90
|
+
Instrument.recording_studio._.facilities,
|
69
91
|
)
|
92
|
+
.output(load_json=True)
|
93
|
+
.run_sync()
|
94
|
+
)
|
70
95
|
|
71
|
-
|
72
|
-
|
96
|
+
self.assertEqual(
|
97
|
+
results,
|
98
|
+
[
|
99
|
+
{
|
100
|
+
"name": "Piccolo",
|
101
|
+
"recording_studio.facilities": self.json,
|
102
|
+
}
|
103
|
+
],
|
104
|
+
)
|
73
105
|
|
74
|
-
|
106
|
+
def test_join_with_alias(self):
|
107
|
+
results = (
|
108
|
+
Instrument.select(
|
109
|
+
Instrument.name,
|
110
|
+
Instrument.recording_studio._.facilities.as_alias(
|
111
|
+
"facilities"
|
112
|
+
),
|
113
|
+
)
|
114
|
+
.output(load_json=True)
|
115
|
+
.run_sync()
|
116
|
+
)
|
75
117
|
|
76
|
-
|
118
|
+
self.assertEqual(
|
119
|
+
results,
|
120
|
+
[
|
121
|
+
{
|
122
|
+
"name": "Piccolo",
|
123
|
+
"facilities": self.json,
|
124
|
+
}
|
125
|
+
],
|
126
|
+
)
|
77
127
|
|
78
|
-
|
79
|
-
|
128
|
+
def test_objects(self):
|
129
|
+
results = RecordingStudio.objects().output(load_json=True).run_sync()
|
130
|
+
self.assertEqual(results[0].facilities, self.json)
|
131
|
+
self.assertEqual(results[0].facilities_b, self.json)
|
80
132
|
|
81
133
|
|
82
134
|
class TestOutputNested(DBTestCase):
|
tests/table/test_select.py
CHANGED
@@ -7,7 +7,8 @@ from piccolo.apps.user.tables import BaseUser
|
|
7
7
|
from piccolo.columns import Date, Varchar
|
8
8
|
from piccolo.columns.combination import WhereRaw
|
9
9
|
from piccolo.query import OrderByRaw
|
10
|
-
from piccolo.query.
|
10
|
+
from piccolo.query.functions.aggregate import Avg, Count, Max, Min, Sum
|
11
|
+
from piccolo.query.methods.select import SelectRaw
|
11
12
|
from piccolo.query.mixins import DistinctOnError
|
12
13
|
from piccolo.table import Table, create_db_tables_sync, drop_db_tables_sync
|
13
14
|
from tests.base import (
|
@@ -927,14 +928,6 @@ class TestSelect(DBTestCase):
|
|
927
928
|
self.assertEqual(float(response["popularity_avg"]), 1003.3333333333334)
|
928
929
|
self.assertEqual(response["popularity_sum"], 3010)
|
929
930
|
|
930
|
-
def test_avg_validation(self):
|
931
|
-
with self.assertRaises(ValueError):
|
932
|
-
Band.select(Avg(Band.name)).run_sync()
|
933
|
-
|
934
|
-
def test_sum_validation(self):
|
935
|
-
with self.assertRaises(ValueError):
|
936
|
-
Band.select(Sum(Band.name)).run_sync()
|
937
|
-
|
938
931
|
def test_columns(self):
|
939
932
|
"""
|
940
933
|
Make sure the colums method can be used to specify which columns to
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|