-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathunit.py
114 lines (104 loc) · 3.39 KB
/
unit.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import unittest
import dblayer
class MyTestCase(unittest.TestCase):
def test_a_truncate_db(self):
print("Currently Executing {}".format(self._testMethodName))
print("To clear all the records before test cases start")
try:
response = dblayer.truncate_table()
if response == 1:
assert True
else:
assert False
except Exception as e:
print(e)
assert False
def test_b_insert_record(self):
print("Currently Executing {}".format(self._testMethodName))
print("Inserting first record")
try:
request_url = 'http://test.com/safe'
response = dblayer.insert_record(request_url)
if response == 1:
assert True
else:
assert False
except Exception as e:
print(e)
assert False
def test_c_update_record(self):
print("Currently Executing {}".format(self._testMethodName))
print("Updating the first record")
try:
request_url = 'http://test.com/notsafe'
response = dblayer.update_record(1, request_url, True)
if response == 1:
assert True
else:
assert False
except Exception as e:
print(e)
assert False
def test_d_insert_second_record(self):
print("Currently Executing {}".format(self._testMethodName))
print("Inserting second record")
try:
request_url = 'http://10.10.10.10:9200/isclean'
response = dblayer.insert_record(request_url)
if response == 1:
assert True
else:
assert False
except Exception as e:
print(e)
assert False
def test_e_read_first_record(self):
print("Currently Executing {}".format(self._testMethodName))
print("Reading one record")
try:
response = dblayer.get_record_by_id(1)
if len(response) > 2:
assert True
else:
assert False
except Exception as e:
print(e)
assert False
def test_f_read_all_record(self):
print("Currently Executing {}".format(self._testMethodName))
print("Reading all record")
try:
response = dblayer.get_all_records()
if len(response) > 2:
assert True
else:
assert False
except Exception as e:
print(e)
assert False
def test_g_delete_record(self):
print("Currently Executing ".format(self._testMethodName))
print("Deleting a record")
try:
response = dblayer.update_record(2, '', False)
if response == 1:
assert True
else:
assert False
except Exception as e:
print(e)
assert False
def test_h_truncate_row(self):
print("Currently Executing Cleanup")
print("Cleaning the DB after test cases are finished")
try:
response = dblayer.truncate_table()
if response == 1:
assert True
else:
assert False
except Exception as e:
print(e)
assert False
if __name__ == '__main__':
unittest.main()