Skip to content

Commit e4bb3e8

Browse files
committed
added test for Table._table_str
1 parent 7e7f5ea commit e4bb3e8

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

piccolo/table.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,10 +594,11 @@ def _get_index_name(cls, column_names: t.List[str]) -> str:
594594
def _table_str(cls, abbreviated=False):
595595
"""
596596
Returns a basic string representation of the table and its columns.
597+
Used by the playground.
597598
598-
Used by the playground, and migrations.
599+
:param abbreviated:
600+
If True, a very high level representation is printed out.
599601
600-
If abbreviated, we just return a very high level representation.
601602
"""
602603
spacer = "\n "
603604
columns = []

tests/table/test_str.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from unittest import TestCase
2+
3+
from ..example_project.tables import Manager
4+
5+
6+
class TestTableStr(TestCase):
7+
def test_table_exists(self):
8+
self.assertEqual(
9+
Manager._table_str(),
10+
(
11+
"class Manager(Table, tablename='manager'):\n"
12+
" id = PrimaryKey(null=False, primary=True, key=True, unique=False, index=False)\n" # noqa
13+
" name = Varchar(length=50, default='', null=False, primary=False, key=False, unique=False, index=False)\n" # noqa
14+
),
15+
)
16+
17+
self.assertEqual(
18+
Manager._table_str(abbreviated=True),
19+
(
20+
"class Manager(Table):\n"
21+
" id = PrimaryKey()\n"
22+
" name = Varchar()\n"
23+
),
24+
)
25+
26+
# We should also be able to print it directly.
27+
print(Manager)

0 commit comments

Comments
 (0)