annotate Database/Lua/HttpClient.lua @ 102:9671578fd4d3

added tests for Lua HttpPost/Put/Get/Delete methods
author amazy
date Thu, 02 Feb 2017 21:10:49 +0100
parents
children 7530eb50c3c4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
102
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
1 testSucceeded = true
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
2
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
3 local payload = {}
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
4 payload['stringMember'] = 'toto'
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
5 payload['intMember'] = 2
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
6
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
7 local httpHeaders = {}
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
8 httpHeaders['Content-Type'] = 'application/json'
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
9 httpHeaders['Toto'] = 'Tutu'
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
10
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
11 -- Issue HttpPost with body
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
12 response = ParseJson(HttpPost('http://httpbin.org/post', DumpJson(payload), httpHeaders))
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
13 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu')
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
14 testSucceeded = testSucceeded and (response['json']['intMember'] == 2 and response['json']['stringMember'] == 'toto')
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
15
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
16 -- Issue HttpPost without body
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
17 response = ParseJson(HttpPost('http://httpbin.org/post', nil, httpHeaders))
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
18 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu')
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
19 testSucceeded = testSucceeded and (response['json']['intMember'] == 2 and response['json']['stringMember'] == 'toto')
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
20 PrintRecursive(response)
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
21
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
22 -- Issue HttpPut with body
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
23 response = ParseJson(HttpPut('http://httpbin.org/put', DumpJson(payload), httpHeaders))
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
24 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu')
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
25
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
26 -- Issue HttpPut without body
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
27 response = ParseJson(HttpPut('http://httpbin.org/put', nil, httpHeaders))
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
28 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu')
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
29
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
30 -- Issue HttpDelete (juste make sure it is issued, we can't check the response)
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
31 HttpDelete('http://httpbin.org/delete', httpHeaders)
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
32
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
33 -- Issue HttpGet
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
34 response = ParseJson(HttpGet('http://httpbin.org/get', httpHeaders))
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
35 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu')
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
36
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
37 if testSucceeded then
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
38 print('OK')
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
39 else
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
40 print('FAILED')
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
41 end