-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
62 lines (56 loc) · 1.68 KB
/
test.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
from api import app
import unittest, json
class FlaskTest(unittest.TestCase):
# Check for response 404
def test_index(self):
tester = app.test_client(self)
response = tester.get('/')
statuscode = response.status_code
self.assertEquals(statuscode, 404)
# Test Encrypt With GET Method
def test_encrypt_with_get_method(self):
tester = app.test_client(self)
response =tester.get('/encrypt')
statuscode = response.status_code
self.assertEquals(statuscode, 405)
# Test Encrypt
def test_encrypt(self):
tester = app.test_client(self)
payload = {
"data" : [
{
"text": "Message1"
},
{
"text": "Message2"
}
]
}
response = tester.post('/encrypt', data = json.dumps(dict(payload)), content_type='application/json')
statuscode = response.status_code
self.assertEquals(statuscode, 200)
# Test Decrypt With GET Method
def test_decrypt_with_get_method(self):
tester = app.test_client(self)
response =tester.get('/decrypt')
statuscode = response.status_code
self.assertEquals(statuscode, 405)
# Test Decrypt
def test_decrypt(self):
tester = app.test_client(self)
payload = {
"data" : [
{
"text": "Message1"
},
{
"text": "Message2"
}
]
}
encrypt_data = tester.post('/encrypt', data = json.dumps(dict(payload)), content_type='application/json')
response = tester.post('/decrypt', data = json.dumps(dict(json.loads(encrypt_data.data))), content_type='application/json')
statuscode = response.status_code
self.assertEquals(statuscode, 200)
if __name__ == "__main__":
unittest.main()