|
1 | 1 | import unittest |
2 | 2 |
|
3 | 3 | from piccolo import columns |
| 4 | +from piccolo.table import Table |
4 | 5 |
|
5 | 6 |
|
6 | | -name_column = columns.Varchar() |
7 | | -# Usually this is handled by the Table MetaClass: |
8 | | -name_column._name = 'name' |
| 7 | +class TestTable(Table): |
| 8 | + name = columns.Varchar() |
9 | 9 |
|
10 | 10 |
|
11 | 11 | class TestColumns(unittest.TestCase): |
12 | 12 |
|
13 | 13 | def test_equals(self): |
14 | | - _where = (name_column == 'Pythonistas') |
| 14 | + _where = (TestTable.name == 'Pythonistas') |
15 | 15 | sql = _where.__str__() |
16 | 16 | print(sql) |
17 | | - self.assertEqual(sql, "name = 'Pythonistas'") |
| 17 | + self.assertEqual(sql, "test_table.name = 'Pythonistas'") |
18 | 18 |
|
19 | 19 | def test_not_equal(self): |
20 | | - _where = (name_column != 'CSharps') |
| 20 | + _where = (TestTable.name != 'CSharps') |
21 | 21 | sql = _where.__str__() |
22 | 22 | print(sql) |
23 | | - self.assertEqual(sql, "name != 'CSharps'") |
| 23 | + self.assertEqual(sql, "test_table.name != 'CSharps'") |
24 | 24 |
|
25 | 25 | def test_like(self): |
26 | | - _where = name_column.like('Python%') |
| 26 | + _where = TestTable.name.like('Python%') |
27 | 27 | sql = _where.__str__() |
28 | 28 | print(sql) |
29 | | - self.assertEqual(sql, "name LIKE 'Python%'") |
| 29 | + self.assertEqual(sql, "test_table.name LIKE 'Python%'") |
30 | 30 |
|
31 | 31 | def test_is_in(self): |
32 | | - _where = name_column.is_in(['Pythonistas', 'Rustaceans']) |
| 32 | + _where = TestTable.name.is_in(['Pythonistas', 'Rustaceans']) |
33 | 33 | sql = _where.__str__() |
34 | 34 | print(sql) |
35 | | - self.assertEqual(sql, "name IN ('Pythonistas', 'Rustaceans')") |
| 35 | + self.assertEqual(sql, "test_table.name IN ('Pythonistas', 'Rustaceans')") |
36 | 36 |
|
37 | 37 | def test_not_in(self): |
38 | | - _where = name_column.not_in(['CSharps']) |
| 38 | + _where = TestTable.name.not_in(['CSharps']) |
39 | 39 | sql = _where.__str__() |
40 | 40 | print(sql) |
41 | | - self.assertEqual(sql, "name NOT IN ('CSharps')") |
| 41 | + self.assertEqual(sql, "test_table.name NOT IN ('CSharps')") |
42 | 42 |
|
43 | 43 |
|
44 | 44 | class TestWhere(): |
|
0 commit comments