Mercurial > hg > orthanc-tests
annotate Database/Lua/HttpClient.lua @ 608:ba06331ac8dd
new test for issue #219
author | Alain Mazy <am@osimis.io> |
---|---|
date | Wed, 24 Jan 2024 13:23:29 +0100 |
parents | f78f7ee6b660 |
children |
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) |
494 | 2 -- since these tests to httpbin.org fails a lot, we have added 10 retries |
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 | |
494 | 14 retry = 10 |
15 response = nil | |
16 while retry > 0 and response == nil do | |
495 | 17 print("HttpClient test: POST with body to httpbin.org") |
494 | 18 response = ParseJson(HttpPost('http://httpbin.org/post', DumpJson(payload), httpHeaders)) |
19 end | |
102 | 20 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') |
21 testSucceeded = testSucceeded and (response['json']['intMember'] == 2 and response['json']['stringMember'] == 'toto') | |
104 | 22 if not testSucceeded then print('Failed in HttpPost with body') PrintRecursive(response) end |
102 | 23 |
24 -- Issue HttpPost without body | |
494 | 25 retry = 10 |
26 response = nil | |
27 while retry > 0 and response == nil do | |
495 | 28 print("HttpClient test: POST without body to httpbin.org") |
494 | 29 response = ParseJson(HttpPost('http://httpbin.org/post', nil, httpHeaders)) |
30 end | |
102 | 31 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') |
104 | 32 testSucceeded = testSucceeded and (response['data'] == '') |
33 if not testSucceeded then print('Failed in HttpPost without body') PrintRecursive(response) end | |
102 | 34 |
35 -- Issue HttpPut with body | |
494 | 36 retry = 10 |
37 response = nil | |
38 while retry > 0 and response == nil do | |
495 | 39 print("HttpClient test: PUT with body to httpbin.org") |
494 | 40 response = ParseJson(HttpPut('http://httpbin.org/put', DumpJson(payload), httpHeaders)) |
41 end | |
102 | 42 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') |
104 | 43 testSucceeded = testSucceeded and (response['json']['intMember'] == 2 and response['json']['stringMember'] == 'toto') |
44 if not testSucceeded then print('Failed in HttpPut with body') PrintRecursive(response) end | |
102 | 45 |
46 -- Issue HttpPut without body | |
494 | 47 retry = 10 |
48 response = nil | |
49 while retry > 0 and response == nil do | |
495 | 50 print("HttpClient test: PUT without body to httpbin.org") |
494 | 51 response = ParseJson(HttpPut('http://httpbin.org/put', nil, httpHeaders)) |
52 end | |
102 | 53 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') |
104 | 54 testSucceeded = testSucceeded and (response['data'] == '') |
55 if not testSucceeded then print('Failed in HttpPut without body') PrintRecursive(response) end | |
102 | 56 |
57 -- Issue HttpDelete (juste make sure it is issued, we can't check the response) | |
58 HttpDelete('http://httpbin.org/delete', httpHeaders) | |
59 | |
263
a2719263fd04
test_study_series_find_inconsistency
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
104
diff
changeset
|
60 -- 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
|
61 -- in curl at this point |
a2719263fd04
test_study_series_find_inconsistency
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
104
diff
changeset
|
62 |
102 | 63 -- Issue HttpGet |
494 | 64 retry = 10 |
65 response = nil | |
66 while retry > 0 and response == nil do | |
495 | 67 print("HttpClient test: GET to httpbin.org") |
494 | 68 response = ParseJson(HttpGet('http://httpbin.org/get', httpHeaders)) |
69 end | |
102 | 70 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') |
104 | 71 if not testSucceeded then print('Failed in HttpGet') PrintRecursive(response) end |
102 | 72 |
480
5ac463ebf463
added a test for lua SetHttpTimeout
Alain Mazy <am@osimis.io>
parents:
263
diff
changeset
|
73 |
481 | 74 system = ParseJson(RestApiGet('/system')) |
480
5ac463ebf463
added a test for lua SetHttpTimeout
Alain Mazy <am@osimis.io>
parents:
263
diff
changeset
|
75 |
481 | 76 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 :-) ) |
77 -- Test SetHttpTimeout | |
78 SetHttpTimeout(10) | |
495 | 79 print("HttpClient test: GET with timeout (10) to httpstat.us") |
481 | 80 response = HttpGet('https://httpstat.us/200?sleep=1000') |
81 testSucceeded = testSucceeded and (response == '200 OK') | |
82 if not testSucceeded then print('Failed in SetHttpTimeout1') PrintRecursive(response) end | |
83 | |
84 SetHttpTimeout(1) | |
495 | 85 print("HttpClient test: GET with timeout (1) to httpstat.us") |
481 | 86 response = HttpGet('https://httpstat.us/200?sleep=2000') |
87 testSucceeded = testSucceeded and (response == nil) | |
88 if not testSucceeded then print('Failed in SetHttpTimeout2') PrintRecursive(response) end | |
89 end | |
480
5ac463ebf463
added a test for lua SetHttpTimeout
Alain Mazy <am@osimis.io>
parents:
263
diff
changeset
|
90 |
102 | 91 if testSucceeded then |
92 print('OK') | |
93 else | |
94 print('FAILED') | |
95 end |