Mercurial > hg > orthanc-tests
comparison Database/Lua/HttpClient.lua @ 102:9671578fd4d3
added tests for Lua HttpPost/Put/Get/Delete methods
author | amazy |
---|---|
date | Thu, 02 Feb 2017 21:10:49 +0100 |
parents | |
children | 7530eb50c3c4 |
comparison
equal
deleted
inserted
replaced
101:71bca28a4645 | 102:9671578fd4d3 |
---|---|
1 testSucceeded = true | |
2 | |
3 local payload = {} | |
4 payload['stringMember'] = 'toto' | |
5 payload['intMember'] = 2 | |
6 | |
7 local httpHeaders = {} | |
8 httpHeaders['Content-Type'] = 'application/json' | |
9 httpHeaders['Toto'] = 'Tutu' | |
10 | |
11 -- Issue HttpPost with body | |
12 response = ParseJson(HttpPost('http://httpbin.org/post', DumpJson(payload), httpHeaders)) | |
13 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') | |
14 testSucceeded = testSucceeded and (response['json']['intMember'] == 2 and response['json']['stringMember'] == 'toto') | |
15 | |
16 -- Issue HttpPost without body | |
17 response = ParseJson(HttpPost('http://httpbin.org/post', nil, httpHeaders)) | |
18 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') | |
19 testSucceeded = testSucceeded and (response['json']['intMember'] == 2 and response['json']['stringMember'] == 'toto') | |
20 PrintRecursive(response) | |
21 | |
22 -- Issue HttpPut with body | |
23 response = ParseJson(HttpPut('http://httpbin.org/put', DumpJson(payload), httpHeaders)) | |
24 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') | |
25 | |
26 -- Issue HttpPut without body | |
27 response = ParseJson(HttpPut('http://httpbin.org/put', nil, httpHeaders)) | |
28 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') | |
29 | |
30 -- Issue HttpDelete (juste make sure it is issued, we can't check the response) | |
31 HttpDelete('http://httpbin.org/delete', httpHeaders) | |
32 | |
33 -- Issue HttpGet | |
34 response = ParseJson(HttpGet('http://httpbin.org/get', httpHeaders)) | |
35 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') | |
36 | |
37 if testSucceeded then | |
38 print('OK') | |
39 else | |
40 print('FAILED') | |
41 end |