Mercurial > hg > orthanc-tests
annotate Database/Lua/HttpClient.lua @ 485:459eb688d3a1
updated requirements to have right version of orthanc-api-client
author | Alain Mazy <am@osimis.io> |
---|---|
date | Thu, 23 Jun 2022 14:54:48 +0200 |
parents | e0b502b31a8a |
children | cffef67c9a94 |
rev | line source |
---|---|
104 | 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 | |
102 | 3 testSucceeded = true |
4 | |
5 local payload = {} | |
6 payload['stringMember'] = 'toto' | |
7 payload['intMember'] = 2 | |
8 | |
9 local httpHeaders = {} | |
10 httpHeaders['Content-Type'] = 'application/json' | |
11 httpHeaders['Toto'] = 'Tutu' | |
12 | |
13 -- Issue HttpPost with body | |
14 response = ParseJson(HttpPost('http://httpbin.org/post', DumpJson(payload), httpHeaders)) | |
15 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') | |
16 testSucceeded = testSucceeded and (response['json']['intMember'] == 2 and response['json']['stringMember'] == 'toto') | |
104 | 17 if not testSucceeded then print('Failed in HttpPost with body') PrintRecursive(response) end |
102 | 18 |
19 -- Issue HttpPost without body | |
20 response = ParseJson(HttpPost('http://httpbin.org/post', nil, httpHeaders)) | |
21 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') | |
104 | 22 testSucceeded = testSucceeded and (response['data'] == '') |
23 if not testSucceeded then print('Failed in HttpPost without body') PrintRecursive(response) end | |
102 | 24 |
25 -- Issue HttpPut with body | |
26 response = ParseJson(HttpPut('http://httpbin.org/put', DumpJson(payload), httpHeaders)) | |
27 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') | |
104 | 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 | |
102 | 30 |
31 -- Issue HttpPut without body | |
32 response = ParseJson(HttpPut('http://httpbin.org/put', nil, httpHeaders)) | |
33 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') | |
104 | 34 testSucceeded = testSucceeded and (response['data'] == '') |
35 if not testSucceeded then print('Failed in HttpPut without body') PrintRecursive(response) end | |
102 | 36 |
37 -- Issue HttpDelete (juste make sure it is issued, we can't check the response) | |
38 HttpDelete('http://httpbin.org/delete', httpHeaders) | |
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 | 43 -- Issue HttpGet |
44 response = ParseJson(HttpGet('http://httpbin.org/get', httpHeaders)) | |
45 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') | |
104 | 46 if not testSucceeded then print('Failed in HttpGet') PrintRecursive(response) end |
102 | 47 |
480
5ac463ebf463
added a test for lua SetHttpTimeout
Alain Mazy <am@osimis.io>
parents:
263
diff
changeset
|
48 |
481 | 49 system = ParseJson(RestApiGet('/system')) |
480
5ac463ebf463
added a test for lua SetHttpTimeout
Alain Mazy <am@osimis.io>
parents:
263
diff
changeset
|
50 |
481 | 51 if system['Version'] == 'mainline' or system['Version'] == '1.11.1' or system['ApiVersion'] >= 18 then -- introduced in 1.11.1 which is ApiVersion 17 (too lazy to reimplement IsAboveOrthancVersion in lua :-) ) |
52 -- Test SetHttpTimeout | |
53 SetHttpTimeout(10) | |
54 response = HttpGet('https://httpstat.us/200?sleep=1000') | |
55 testSucceeded = testSucceeded and (response == '200 OK') | |
56 if not testSucceeded then print('Failed in SetHttpTimeout1') PrintRecursive(response) end | |
57 | |
58 SetHttpTimeout(1) | |
59 response = HttpGet('https://httpstat.us/200?sleep=2000') | |
60 testSucceeded = testSucceeded and (response == nil) | |
61 if not testSucceeded then print('Failed in SetHttpTimeout2') PrintRecursive(response) end | |
62 end | |
480
5ac463ebf463
added a test for lua SetHttpTimeout
Alain Mazy <am@osimis.io>
parents:
263
diff
changeset
|
63 |
102 | 64 if testSucceeded then |
65 print('OK') | |
66 else | |
67 print('FAILED') | |
68 end |