forked from piccolo-orm/piccolo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_insert.py
More file actions
45 lines (31 loc) · 1.27 KB
/
test_insert.py
File metadata and controls
45 lines (31 loc) · 1.27 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
from unittest.case import TestCase
from ..base import DBTestCase
from ..example_app.tables import Band, Manager
class TestInsert(DBTestCase):
def test_insert(self):
self.insert_rows()
Band.insert(Band(name="Rustaceans", popularity=100)).run_sync()
response = Band.select(Band.name).run_sync()
names = [i["name"] for i in response]
self.assertTrue("Rustaceans" in names)
def test_add(self):
self.insert_rows()
Band.insert().add(Band(name="Rustaceans", popularity=100)).run_sync()
response = Band.select(Band.name).run_sync()
names = [i["name"] for i in response]
self.assertTrue("Rustaceans" in names)
def test_incompatible_type(self):
"""
You shouldn't be able to add instances of a different table.
"""
with self.assertRaises(TypeError):
Band.insert().add(Manager(name="Guido")).run_sync()
def test_insert_curly_braces(self):
"""
You should be able to insert curly braces without an error.
"""
self.insert_rows()
Band.insert(Band(name="{}", popularity=100)).run_sync()
response = Band.select(Band.name).run_sync()
names = [i["name"] for i in response]
self.assertTrue("{}" in names)