Mercurial > hg > orthanc-tests
changeset 102:9671578fd4d3
added tests for Lua HttpPost/Put/Get/Delete methods
author | amazy |
---|---|
date | Thu, 02 Feb 2017 21:10:49 +0100 |
parents | 71bca28a4645 |
children | c0aa1ed6f4eb |
files | Database/Lua/HttpClient.lua Tests/Tests.py |
diffstat | 2 files changed, 47 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Database/Lua/HttpClient.lua Thu Feb 02 21:10:49 2017 +0100 @@ -0,0 +1,41 @@ +testSucceeded = true + +local payload = {} +payload['stringMember'] = 'toto' +payload['intMember'] = 2 + +local httpHeaders = {} +httpHeaders['Content-Type'] = 'application/json' +httpHeaders['Toto'] = 'Tutu' + +-- Issue HttpPost with body +response = ParseJson(HttpPost('http://httpbin.org/post', DumpJson(payload), httpHeaders)) +testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') +testSucceeded = testSucceeded and (response['json']['intMember'] == 2 and response['json']['stringMember'] == 'toto') + +-- Issue HttpPost without body +response = ParseJson(HttpPost('http://httpbin.org/post', nil, httpHeaders)) +testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') +testSucceeded = testSucceeded and (response['json']['intMember'] == 2 and response['json']['stringMember'] == 'toto') +PrintRecursive(response) + +-- Issue HttpPut with body +response = ParseJson(HttpPut('http://httpbin.org/put', DumpJson(payload), httpHeaders)) +testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') + +-- Issue HttpPut without body +response = ParseJson(HttpPut('http://httpbin.org/put', nil, httpHeaders)) +testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') + +-- Issue HttpDelete (juste make sure it is issued, we can't check the response) +HttpDelete('http://httpbin.org/delete', httpHeaders) + +-- Issue HttpGet +response = ParseJson(HttpGet('http://httpbin.org/get', httpHeaders)) +testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') + +if testSucceeded then + print('OK') +else + print('FAILED') +end
--- a/Tests/Tests.py Thu Feb 02 15:56:34 2017 +0100 +++ b/Tests/Tests.py Thu Feb 02 21:10:49 2017 +0100 @@ -3136,3 +3136,9 @@ CompareMainDicomTag('hello', a, 'study', 'StudyDescription') CompareMainDicomTag('world', a, 'series', 'SeriesDescription') CompareMainDicomTag('1.2.840.113619.2.176.2025.1499492.7040.1171286242.109', a, '', 'SOPInstanceUID') + + def test_httpPost_lua(self): + with open(GetDatabasePath('Lua/HttpPost.lua'), 'r') as f: + result = DoPost(_REMOTE, '/tools/execute-script', f.read(), 'application/lua') + + self.assertIn('OK', result)