annotate Database/Lua/HttpClient.lua @ 311:07e2adc4aead

fix
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 20 May 2020 18:29:23 +0200
parents a2719263fd04
children 5ac463ebf463
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
263
a2719263fd04 test_study_series_find_inconsistency
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 104
diff changeset
40 -- TODO Very strange: Since Orthanc 1.6.0, a timeout frequently occurs
a2719263fd04 test_study_series_find_inconsistency
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 104
diff changeset
41 -- in curl at this point
a2719263fd04 test_study_series_find_inconsistency
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 104
diff changeset
42
102
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
43 -- Issue HttpGet
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
44 response = ParseJson(HttpGet('http://httpbin.org/get', httpHeaders))
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
45 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
46 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
47
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
48 if testSucceeded then
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
49 print('OK')
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
50 else
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
51 print('FAILED')
9671578fd4d3 added tests for Lua HttpPost/Put/Get/Delete methods
amazy
parents:
diff changeset
52 end