-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsql_requests_tests.py
31 lines (21 loc) · 1.31 KB
/
sql_requests_tests.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
import unittest
from SQLite import SQLite
class testSQL(unittest.TestCase):
sql_obj = SQLite("test.db")
def test_select_request(self):
# Test "SELECT ALL"
test_request_1 = "SELECT * FROM test_table"
expected_answ_1 = "[(123, '23'), (123, '123'), (1323, '123'), (1323, '123'), (1323, '123'), (1323, '123'), (1323, '123'), ('dffgdfg', 'sdgfdfg')]"
self.assertEqual(str(self.sql_obj.execute_request(test_request_1)), expected_answ_1)
# Test "SELECT from" by columns
test_request_2 = "SELECT test_int_field FROM test_table"
expected_answ_2 = "[(123,), (123,), (1323,), (1323,), (1323,), (1323,), (1323,), ('dffgdfg',)]"
self.assertEqual(str(self.sql_obj.execute_request(test_request_2)), expected_answ_2)
test_request_3 = test_request_2.replace("test_int_field", "test_text_field")
expected_answ_3 = "[('23',), ('123',), ('123',), ('123',), ('123',), ('123',), ('123',), ('sdgfdfg',)]"
self.assertEqual(str(self.sql_obj.execute_request(test_request_3)), expected_answ_3)
# Test column that doesn't exist
test_request_4 = test_request_2.replace("test_int_field", "column_random")
self.assertEqual(self.sql_obj.execute_request(test_request_4) , RuntimeError)
if __name__ == "__main__":
unittest.main()