-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
72 lines (54 loc) · 2.66 KB
/
Copy pathtest.py
File metadata and controls
72 lines (54 loc) · 2.66 KB
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
import unittest
from runpy import run_path
from HTTPRequest import HTTPRequest
from Connection import Connection
class TestSimpleRequests(unittest.TestCase):
def test_importRequest(self):
req=HTTPRequest("tests/testReq1",isTLS=True,verify=False)
self.assertEqual(req.command,"GET")
self.assertEqual(len(req.headers),11)
req=HTTPRequest("tests/testReqPost1",isTLS=True,verify=True)
self.assertEqual(req.command,"POST")
self.assertEqual(len(req.headers),12)
self.assertTrue("antoine.scemama" in str(req.postBody))
con=Connection(isTLS=True,verify=False,proxies={ 'http': 'http://127.0.0.1:8080','https': 'http://127.0.0.1:8080',})
req=HTTPRequest("tests/testReqPost1",connection=con)
self.assertEqual(req.command,"POST")
self.assertEqual(len(req.headers),12)
self.assertTrue("antoine.scemama" in str(req.postBody))
def test_sendRequest(self):
req=HTTPRequest("tests/testReq1",isTLS=True,verify=False)
req.send()
self.assertTrue("buildVersion" in req.response.text)
req=HTTPRequest("tests/testReqPost1",isTLS=True,verify=True)
req.send()
self.assertTrue("Brainloop Web" in req.response.text )
con=Connection(isTLS=True,verify=False)
req=HTTPRequest("tests/testReqPost1",connection=con)
req.send()
self.assertTrue("Brainloop Web" in req.response.text )
req=HTTPRequest("tests/reqHEAD1",connection=con)
req.send()
self.assertTrue(req.response.status_code== 405 )
def test_sendWithProxy(self):
con=Connection(isTLS=True,verify=False,proxies={ 'http': 'http://127.0.0.1:8080','https': 'http://127.0.0.1:8080',})
req=HTTPRequest("tests/testReqPost1",connection=con)
req.send()
self.assertEqual(req.command,"POST")
self.assertEqual(len(req.headers),12)
self.assertTrue("antoine.scemama" in str(req.postBody))
def test_replaceStringInRequest(self):
req=HTTPRequest("tests/reqPost2",isTLS=True,verify=False)
self.assertTrue("antoine.scemama"in str(req.postBody))
req.replaceString("antoine","yo")
self.assertTrue("yo.scemama"in str(req.postBody))
def test_replaceStringInHeader(self):
req=HTTPRequest("tests/reqPost2",isTLS=True,verify=False)
req.replaceString("en-US","yo")
self.assertTrue("yo" in req.headers["Accept-Language"])
def test_replaceStringInURL(self):
req=HTTPRequest("tests/reqPost2",isTLS=True,verify=False)
req.replaceString("scope","yo")
self.assertTrue("yo" in req.URL)
if __name__ == '__main__':
unittest.main()