comparison Database/Lua/HttpClient.lua @ 104:7530eb50c3c4

renamed HttpPost.lua into HttpClient.lua + fix tests
author amazy
date Thu, 02 Mar 2017 20:10:03 +0100
parents 9671578fd4d3
children a2719263fd04
comparison
equal deleted inserted replaced
103:c0aa1ed6f4eb 104:7530eb50c3c4
1 -- for these tests, we issue HTTP requests to httpbin.org that performs smart echo (it returns all data/headers it has received + some extra data)
2
1 testSucceeded = true 3 testSucceeded = true
2 4
3 local payload = {} 5 local payload = {}
4 payload['stringMember'] = 'toto' 6 payload['stringMember'] = 'toto'
5 payload['intMember'] = 2 7 payload['intMember'] = 2
10 12
11 -- Issue HttpPost with body 13 -- Issue HttpPost with body
12 response = ParseJson(HttpPost('http://httpbin.org/post', DumpJson(payload), httpHeaders)) 14 response = ParseJson(HttpPost('http://httpbin.org/post', DumpJson(payload), httpHeaders))
13 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') 15 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu')
14 testSucceeded = testSucceeded and (response['json']['intMember'] == 2 and response['json']['stringMember'] == 'toto') 16 testSucceeded = testSucceeded and (response['json']['intMember'] == 2 and response['json']['stringMember'] == 'toto')
17 if not testSucceeded then print('Failed in HttpPost with body') PrintRecursive(response) end
15 18
16 -- Issue HttpPost without body 19 -- Issue HttpPost without body
17 response = ParseJson(HttpPost('http://httpbin.org/post', nil, httpHeaders)) 20 response = ParseJson(HttpPost('http://httpbin.org/post', nil, httpHeaders))
18 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') 21 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu')
19 testSucceeded = testSucceeded and (response['json']['intMember'] == 2 and response['json']['stringMember'] == 'toto') 22 testSucceeded = testSucceeded and (response['data'] == '')
20 PrintRecursive(response) 23 if not testSucceeded then print('Failed in HttpPost without body') PrintRecursive(response) end
21 24
22 -- Issue HttpPut with body 25 -- Issue HttpPut with body
23 response = ParseJson(HttpPut('http://httpbin.org/put', DumpJson(payload), httpHeaders)) 26 response = ParseJson(HttpPut('http://httpbin.org/put', DumpJson(payload), httpHeaders))
24 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') 27 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu')
28 testSucceeded = testSucceeded and (response['json']['intMember'] == 2 and response['json']['stringMember'] == 'toto')
29 if not testSucceeded then print('Failed in HttpPut with body') PrintRecursive(response) end
25 30
26 -- Issue HttpPut without body 31 -- Issue HttpPut without body
27 response = ParseJson(HttpPut('http://httpbin.org/put', nil, httpHeaders)) 32 response = ParseJson(HttpPut('http://httpbin.org/put', nil, httpHeaders))
28 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') 33 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu')
34 testSucceeded = testSucceeded and (response['data'] == '')
35 if not testSucceeded then print('Failed in HttpPut without body') PrintRecursive(response) end
29 36
30 -- Issue HttpDelete (juste make sure it is issued, we can't check the response) 37 -- Issue HttpDelete (juste make sure it is issued, we can't check the response)
31 HttpDelete('http://httpbin.org/delete', httpHeaders) 38 HttpDelete('http://httpbin.org/delete', httpHeaders)
32 39
33 -- Issue HttpGet 40 -- Issue HttpGet
34 response = ParseJson(HttpGet('http://httpbin.org/get', httpHeaders)) 41 response = ParseJson(HttpGet('http://httpbin.org/get', httpHeaders))
35 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') 42 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu')
43 if not testSucceeded then print('Failed in HttpGet') PrintRecursive(response) end
36 44
37 if testSucceeded then 45 if testSucceeded then
38 print('OK') 46 print('OK')
39 else 47 else
40 print('FAILED') 48 print('FAILED')