| 794 | self.db.drop(table) |
| 795 | |
| 796 | def test_view(self): |
| 797 | |
| 798 | class Products(db.View): |
| 799 | def __init__(self, database): |
| 800 | db.View.__init__(self, database, "products", schema=[ |
| 801 | db.pk(), |
| 802 | db.field("name", db.STRING), |
| 803 | db.field("price", db.FLOAT) |
| 804 | ]) |
| 805 | self.setup() |
| 806 | self.table.insert(name="pizza", price=15.0) |
| 807 | def render(self, query, **kwargs): |
| 808 | q = self.table.search(fields=["name", "price"], filters=[("name", "*%s*" % query)]) |
| 809 | s = [] |
| 810 | for row in q.rows(): |
| 811 | s.append("<tr>%s</tr>" % "".join( |
| 812 | ["<td class=\"%s\">%s</td>" % f for f in zip(q.fields, row)])) |
| 813 | return "<table>" + "".join(s) + "</table>" |
| 814 | |
| 815 | # Assert View with automatic Table creation. |
| 816 | v = Products(self.db) |
| 817 | self.assertEqual(v.render("iz"), |
| 818 | "<table>" |
| 819 | "<tr>" |
| 820 | "<td class=\"name\">pizza</td>" |
| 821 | "<td class=\"price\">15.0</td>" |
| 822 | "</tr>" |
| 823 | "</table>" |
| 824 | ) |
| 825 | print "pattern.db.View" |
| 826 | |
| 827 | class TestMySQLView(TestView): |
| 828 | def setUp(self): |