# HG changeset patch # User amazy # Date 1486066249 -3600 # Node ID 9671578fd4d3bb1796149db4a24b48c03270c359 # Parent 71bca28a4645846c97314898b069726d65213d7d added tests for Lua HttpPost/Put/Get/Delete methods diff -r 71bca28a4645 -r 9671578fd4d3 Database/Lua/HttpClient.lua --- /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 diff -r 71bca28a4645 -r 9671578fd4d3 Tests/Tests.py --- 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)