forked from piccolo-orm/piccolo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_objects.py
More file actions
61 lines (44 loc) · 1.57 KB
/
test_objects.py
File metadata and controls
61 lines (44 loc) · 1.57 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
from ..base import DBTestCase, postgres_only, sqlite_only
from ..example_app.tables import Band
class TestObjects(DBTestCase):
def test_get_all(self):
self.insert_row()
response = Band.objects().run_sync()
self.assertTrue(len(response) == 1)
instance = response[0]
self.assertTrue(isinstance(instance, Band))
self.assertTrue(instance.name == "Pythonistas")
# Now try changing the value and saving it.
instance.name = "Rustaceans"
save_query = instance.save()
save_query.run_sync()
self.assertTrue(
Band.select(Band.name).output(as_list=True).run_sync()[0]
== "Rustaceans"
)
@postgres_only
def test_offset_postgres(self):
"""
Postgres can do an offset without a limit clause.
"""
self.insert_rows()
response = Band.objects().order_by(Band.name).offset(1).run_sync()
print(f"response = {response}")
self.assertEqual(
[i.name for i in response], ["Pythonistas", "Rustaceans"]
)
@sqlite_only
def test_offset_sqlite(self):
"""
SQLite requires a limit clause for offset to work.
"""
self.insert_rows()
query = Band.objects().order_by(Band.name).offset(1)
with self.assertRaises(ValueError):
query.run_sync()
query = query.limit(5)
response = query.run_sync()
print(f"response = {response}")
self.assertEqual(
[i.name for i in response], ["Pythonistas", "Rustaceans"]
)