-
Notifications
You must be signed in to change notification settings - Fork 11
/
sqltest.py
40 lines (30 loc) · 1.5 KB
/
sqltest.py
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
#!/usr/bin/python
# -*-coding: utf-8 -*-
import unittest
from dictmysql import DictMySQL
class TestSQLConversion(unittest.TestCase):
def setUp(self):
self.connection = DictMySQL(host='localhost', user='root', passwd='')
self.connection.debug = True
def testSelect(self):
self.connection.select(table='jobs', columns=['id', 'value'], where={'id': 5, 'value': 'Teacher'})
self.assertEqual(self.connection.last_query,
"SELECT `id`, `value` FROM `jobs` WHERE (`id` = 5) AND (`value` = Teacher);")
def testInsert(self):
self.connection.insert(table='jobs', value={'value': 'Teacher'})
self.assertEqual(self.connection.last_query,
"INSERT INTO `jobs` (`value`) VALUES (Teacher);")
def testUpdate(self):
self.connection.update(table='jobs', value={'value': 'Teacher'}, where={'value': 'Teacher'})
self.assertEqual(self.connection.last_query,
"UPDATE `jobs` SET `value` = Teacher WHERE (`value` = Teacher);")
def testDelete(self):
self.connection.delete(table='jobs', where={'value': 'Taecher'})
self.assertEqual(self.connection.last_query,
"DELETE FROM `jobs` WHERE (`value` = Teacher);")
def testWhere(self):
where = self.connection._where_parser(where={'id': {'$<': 20}})
self.assertEqual(self.connection.last_query,
" WHERE (`id` < 20)")
if __name__ == '__main__':
unittest.main()