forked from piccolo-orm/piccolo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_create.py
More file actions
51 lines (37 loc) · 1.46 KB
/
test_create.py
File metadata and controls
51 lines (37 loc) · 1.46 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
from unittest import TestCase
from piccolo.table import Table
from piccolo.columns import Varchar
from ..example_app.tables import Manager
class TestCreate(TestCase):
def test_create_table(self):
Manager.create_table().run_sync()
self.assertTrue(Manager.table_exists().run_sync())
Manager.alter().drop_table().run_sync()
class BandMember(Table):
name = Varchar(length=50, index=True)
class TestCreateWithIndexes(TestCase):
def setUp(self):
BandMember.create_table().run_sync()
def tearDown(self):
BandMember.alter().drop_table().run_sync()
def test_create_table_with_indexes(self):
index_names = BandMember.indexes().run_sync()
index_name = BandMember._get_index_name(["name"])
self.assertTrue(index_name in index_names)
def test_create_if_not_exists_with_indexes(self):
"""
Make sure that if the same table is created again, with the
`if_not_exists` flag, then no errors are raised for duplicate indexes
(i.e. the indexes should also be created with IF NOT EXISTS).
"""
query = BandMember.create_table(if_not_exists=True)
# Shouldn't raise any errors:
query.run_sync()
self.assertTrue(
query.querystrings[0]
.__str__()
.startswith("CREATE TABLE IF NOT EXISTS"),
query.querystrings[1]
.__str__()
.startswith("CREATE INDEX IF NOT EXISTS"),
)