Mercurial > hg > orthanc-tests
comparison Database/Lua/HttpClient.lua @ 495:75d8a5261f82
more verbose httpclient test
author | Alain Mazy <am@osimis.io> |
---|---|
date | Wed, 17 Aug 2022 09:37:47 +0200 |
parents | cffef67c9a94 |
children | f78f7ee6b660 |
comparison
equal
deleted
inserted
replaced
494:cffef67c9a94 | 495:75d8a5261f82 |
---|---|
12 | 12 |
13 -- Issue HttpPost with body | 13 -- Issue HttpPost with body |
14 retry = 10 | 14 retry = 10 |
15 response = nil | 15 response = nil |
16 while retry > 0 and response == nil do | 16 while retry > 0 and response == nil do |
17 print("HttpClient test: POST with body to httpbin.org") | |
17 response = ParseJson(HttpPost('http://httpbin.org/post', DumpJson(payload), httpHeaders)) | 18 response = ParseJson(HttpPost('http://httpbin.org/post', DumpJson(payload), httpHeaders)) |
18 end | 19 end |
19 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') | 20 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') |
20 testSucceeded = testSucceeded and (response['json']['intMember'] == 2 and response['json']['stringMember'] == 'toto') | 21 testSucceeded = testSucceeded and (response['json']['intMember'] == 2 and response['json']['stringMember'] == 'toto') |
21 if not testSucceeded then print('Failed in HttpPost with body') PrintRecursive(response) end | 22 if not testSucceeded then print('Failed in HttpPost with body') PrintRecursive(response) end |
22 | 23 |
23 -- Issue HttpPost without body | 24 -- Issue HttpPost without body |
24 retry = 10 | 25 retry = 10 |
25 response = nil | 26 response = nil |
26 while retry > 0 and response == nil do | 27 while retry > 0 and response == nil do |
28 print("HttpClient test: POST without body to httpbin.org") | |
27 response = ParseJson(HttpPost('http://httpbin.org/post', nil, httpHeaders)) | 29 response = ParseJson(HttpPost('http://httpbin.org/post', nil, httpHeaders)) |
28 end | 30 end |
29 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') | 31 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') |
30 testSucceeded = testSucceeded and (response['data'] == '') | 32 testSucceeded = testSucceeded and (response['data'] == '') |
31 if not testSucceeded then print('Failed in HttpPost without body') PrintRecursive(response) end | 33 if not testSucceeded then print('Failed in HttpPost without body') PrintRecursive(response) end |
32 | 34 |
33 -- Issue HttpPut with body | 35 -- Issue HttpPut with body |
34 retry = 10 | 36 retry = 10 |
35 response = nil | 37 response = nil |
36 while retry > 0 and response == nil do | 38 while retry > 0 and response == nil do |
39 print("HttpClient test: PUT with body to httpbin.org") | |
37 response = ParseJson(HttpPut('http://httpbin.org/put', DumpJson(payload), httpHeaders)) | 40 response = ParseJson(HttpPut('http://httpbin.org/put', DumpJson(payload), httpHeaders)) |
38 end | 41 end |
39 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') | 42 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') |
40 testSucceeded = testSucceeded and (response['json']['intMember'] == 2 and response['json']['stringMember'] == 'toto') | 43 testSucceeded = testSucceeded and (response['json']['intMember'] == 2 and response['json']['stringMember'] == 'toto') |
41 if not testSucceeded then print('Failed in HttpPut with body') PrintRecursive(response) end | 44 if not testSucceeded then print('Failed in HttpPut with body') PrintRecursive(response) end |
42 | 45 |
43 -- Issue HttpPut without body | 46 -- Issue HttpPut without body |
44 retry = 10 | 47 retry = 10 |
45 response = nil | 48 response = nil |
46 while retry > 0 and response == nil do | 49 while retry > 0 and response == nil do |
50 print("HttpClient test: PUT without body to httpbin.org") | |
47 response = ParseJson(HttpPut('http://httpbin.org/put', nil, httpHeaders)) | 51 response = ParseJson(HttpPut('http://httpbin.org/put', nil, httpHeaders)) |
48 end | 52 end |
49 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') | 53 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') |
50 testSucceeded = testSucceeded and (response['data'] == '') | 54 testSucceeded = testSucceeded and (response['data'] == '') |
51 if not testSucceeded then print('Failed in HttpPut without body') PrintRecursive(response) end | 55 if not testSucceeded then print('Failed in HttpPut without body') PrintRecursive(response) end |
58 | 62 |
59 -- Issue HttpGet | 63 -- Issue HttpGet |
60 retry = 10 | 64 retry = 10 |
61 response = nil | 65 response = nil |
62 while retry > 0 and response == nil do | 66 while retry > 0 and response == nil do |
67 print("HttpClient test: GET to httpbin.org") | |
63 response = ParseJson(HttpGet('http://httpbin.org/get', httpHeaders)) | 68 response = ParseJson(HttpGet('http://httpbin.org/get', httpHeaders)) |
69 sleep(1) | |
64 end | 70 end |
65 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') | 71 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') |
66 if not testSucceeded then print('Failed in HttpGet') PrintRecursive(response) end | 72 if not testSucceeded then print('Failed in HttpGet') PrintRecursive(response) end |
67 | 73 |
68 | 74 |
69 system = ParseJson(RestApiGet('/system')) | 75 system = ParseJson(RestApiGet('/system')) |
70 | 76 |
71 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 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 :-) ) |
72 -- Test SetHttpTimeout | 78 -- Test SetHttpTimeout |
73 SetHttpTimeout(10) | 79 SetHttpTimeout(10) |
80 print("HttpClient test: GET with timeout (10) to httpstat.us") | |
74 response = HttpGet('https://httpstat.us/200?sleep=1000') | 81 response = HttpGet('https://httpstat.us/200?sleep=1000') |
75 testSucceeded = testSucceeded and (response == '200 OK') | 82 testSucceeded = testSucceeded and (response == '200 OK') |
76 if not testSucceeded then print('Failed in SetHttpTimeout1') PrintRecursive(response) end | 83 if not testSucceeded then print('Failed in SetHttpTimeout1') PrintRecursive(response) end |
77 | 84 |
78 SetHttpTimeout(1) | 85 SetHttpTimeout(1) |
86 print("HttpClient test: GET with timeout (1) to httpstat.us") | |
79 response = HttpGet('https://httpstat.us/200?sleep=2000') | 87 response = HttpGet('https://httpstat.us/200?sleep=2000') |
80 testSucceeded = testSucceeded and (response == nil) | 88 testSucceeded = testSucceeded and (response == nil) |
81 if not testSucceeded then print('Failed in SetHttpTimeout2') PrintRecursive(response) end | 89 if not testSucceeded then print('Failed in SetHttpTimeout2') PrintRecursive(response) end |
82 end | 90 end |
83 | 91 |