示例#1
0
class TestDatabase(unittest.TestCase):
    def setUp(self):
        # Define self.db and self.type in a subclass.
        pass

    def tearDown(self):
        for table in self.db:
            self.db.drop(table)

    def test_escape(self):
        # Assert str, unicode, int, long, float, bool and None field values.
        for v, s in (("a", "'a'"), (u"a", "'a'"), (1, "1"), (1L, "1"),
                     (1.0, "1.0"), (True, "1"), (False, "0"), (None, "null")):
            self.assertEqual(db._escape(v), s)
        # Assert date.
        v = db.date("1707-04-15")
        self.assertEqual(db._escape(v), "'1707-04-15 00:00:00'")
        # Assert current date.
        v = "current_timestamp"
        self.assertEqual(db._escape(v), "current_timestamp")
        # Assert subquery.
        v = self.db.create("dummy", fields=[db.pk()])
        v = v.query()
        self.assertEqual(db._escape(v), "(select dummy.* from `dummy`)")
        # Assert MySQL and SQLite quotes.
        if self.db.type == db.MYSQL:
            self.assertEqual(self.db.escape("'"), "'\\''")
        if self.db.type == db.SQLITE:
            self.assertEqual(self.db.escape("'"), "''''")
        print "pattern.db._escape()"
示例#2
0
文件: test_db.py 项目: pri-k/pattern
 def test_escape(self):
     # Assert str, unicode, int, long, float, bool and None field values.
     for v, s in (
       (   "a", "'a'"),
       (     1, "1"),
       (int(1), "1"),
       (   1.0, "1.0"),
       (  True, "1"),
       ( False, "0"),
       (  None, "null")):
         self.assertEqual(db._escape(v), s)
     # Assert date.
     v = db.date("1707-04-15")
     self.assertEqual(db._escape(v), "'1707-04-15 00:00:00'")
     # Assert current date.
     v = "current_timestamp"
     self.assertEqual(db._escape(v), "current_timestamp")
     # Assert subquery.
     v = self.db.create("dummy", fields=[db.pk()])
     v = v.query()
     self.assertEqual(db._escape(v), "(select dummy.* from `dummy`)")
     # Assert MySQL and SQLite quotes.
     if self.db.type == db.MYSQL:
         self.assertEqual(self.db.escape("'"), "'\\''")
     if self.db.type == db.SQLITE:
         self.assertEqual(self.db.escape("'"), "''''")
     print("pattern.db._escape()")
示例#3
0
文件: test_db.py 项目: clips/pattern
 def test_escape(self):
     # Assert str, unicode, int, long, float, bool and None field values.
     for v, s in (
       (   "a", "'a'"),
       (     1, "1"),
       (int(1), "1"),
       (   1.0, "1.0"),
       (  True, "1"),
       ( False, "0"),
       (  None, "null")):
         self.assertEqual(db._escape(v), s)
     # Assert date.
     v = db.date("1707-04-15")
     self.assertEqual(db._escape(v), "'1707-04-15 00:00:00'")
     # Assert current date.
     v = "current_timestamp"
     self.assertEqual(db._escape(v), "current_timestamp")
     # Assert subquery.
     v = self.db.create("dummy", fields=[db.pk()])
     v = v.query()
     self.assertEqual(db._escape(v), "(select dummy.* from `dummy`)")
     # Assert MySQL and SQLite quotes.
     if self.db.type == db.MYSQL:
         self.assertEqual(self.db.escape("'"), "'\\''")
     if self.db.type == db.SQLITE:
         self.assertEqual(self.db.escape("'"), "''''")
     print("pattern.db._escape()")
示例#4
0
文件: test_db.py 项目: sp00/pattern
 def test_escape(self):
     # Assert str, unicode, int, long, float, bool and None field values.
     for v, s in (
       (  "a", "'a'"),
       ( u"a", "'a'"),
       (    1, "1"),
       (   1L, "1"),
       (  1.0, "1.0"),
       ( True, "1"),
       (False, "0"),
       ( None, "null")):
         self.assertEqual(db._escape(v), s)
示例#5
0
文件: test_db.py 项目: sp00/pattern
 class Database:
     escape, relations = lambda self, v: db._escape(v), []