annotate Database/Lua/HttpClient.lua @ 161:27b3b0df5f90

2 upload tests
author am@osimis.io
date Fri, 17 Aug 2018 17:24:11 +0200
parents 7530eb50c3c4
children a2719263fd04
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
104
7530eb50c3c4 renamed HttpPost.lua into HttpClient.lua + fix tests
amazy
parents: 102
diff changeset
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)
7530eb50c3c4 renamed HttpPost.lua into HttpClient.lua + fix tests
amazy
parents: 102
diff changeset
2
102
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
3 testSucceeded = true
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
4
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
5 local payload = {}
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
6 payload['stringMember'] = 'toto'
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
7 payload['intMember'] = 2
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
8
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
9 local httpHeaders = {}
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
10 httpHeaders['Content-Type'] = 'application/json'
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
11 httpHeaders['Toto'] = 'Tutu'
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
12
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
13 -- Issue HttpPost with body
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
14 response = ParseJson(HttpPost('http://httpbin.org/post', DumpJson(payload), httpHeaders))
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
15 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
16 testSucceeded = testSucceeded and (response['json']['intMember'] == 2 and response['json']['stringMember'] == 'toto')
104
7530eb50c3c4 renamed HttpPost.lua into HttpClient.lua + fix tests
amazy
parents: 102
diff changeset
17 if not testSucceeded then print('Failed in HttpPost with body') PrintRecursive(response) end
102
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
18
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
19 -- Issue HttpPost without body
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
20 response = ParseJson(HttpPost('http://httpbin.org/post', nil, httpHeaders))
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
21 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu')
104
7530eb50c3c4 renamed HttpPost.lua into HttpClient.lua + fix tests
amazy
parents: 102
diff changeset
22 testSucceeded = testSucceeded and (response['data'] == '')
7530eb50c3c4 renamed HttpPost.lua into HttpClient.lua + fix tests
amazy
parents: 102
diff changeset
23 if not testSucceeded then print('Failed in HttpPost without body') PrintRecursive(response) end
102
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
24
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
25 -- Issue HttpPut with body
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
26 response = ParseJson(HttpPut('http://httpbin.org/put', DumpJson(payload), httpHeaders))
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
27 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu')
104
7530eb50c3c4 renamed HttpPost.lua into HttpClient.lua + fix tests
amazy
parents: 102
diff changeset
28 testSucceeded = testSucceeded and (response['json']['intMember'] == 2 and response['json']['stringMember'] == 'toto')
7530eb50c3c4 renamed HttpPost.lua into HttpClient.lua + fix tests
amazy
parents: 102
diff changeset
29 if not testSucceeded then print('Failed in HttpPut with body') PrintRecursive(response) end
102
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
30
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
31 -- Issue HttpPut without body
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
32 response = ParseJson(HttpPut('http://httpbin.org/put', nil, httpHeaders))
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
33 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu')
104
7530eb50c3c4 renamed HttpPost.lua into HttpClient.lua + fix tests
amazy
parents: 102
diff changeset
34 testSucceeded = testSucceeded and (response['data'] == '')
7530eb50c3c4 renamed HttpPost.lua into HttpClient.lua + fix tests
amazy
parents: 102
diff changeset
35 if not testSucceeded then print('Failed in HttpPut without body') PrintRecursive(response) end
102
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 -- 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
38 HttpDelete('http://httpbin.org/delete', httpHeaders)
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
39
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
40 -- Issue HttpGet
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
41 response = ParseJson(HttpGet('http://httpbin.org/get', httpHeaders))
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
42 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu')
104
7530eb50c3c4 renamed HttpPost.lua into HttpClient.lua + fix tests
amazy
parents: 102
diff changeset
43 if not testSucceeded then print('Failed in HttpGet') PrintRecursive(response) end
102
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
44
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
45 if testSucceeded then
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
46 print('OK')
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
47 else
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
48 print('FAILED')
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
49 end