changeset 104:7530eb50c3c4

renamed HttpPost.lua into HttpClient.lua + fix tests
author amazy
date Thu, 02 Mar 2017 20:10:03 +0100
parents c0aa1ed6f4eb
children a2ba5b4eddc9
files Database/Lua/HttpClient.lua Tests/Tests.py
diffstat 2 files changed, 12 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/Database/Lua/HttpClient.lua	Thu Feb 02 21:11:19 2017 +0100
+++ b/Database/Lua/HttpClient.lua	Thu Mar 02 20:10:03 2017 +0100
@@ -1,3 +1,5 @@
+-- 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)
+
 testSucceeded = true
 
 local payload = {}
@@ -12,20 +14,25 @@
 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')
+if not testSucceeded then print('Failed in HttpPost with body') PrintRecursive(response) end
 
 -- 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)
+testSucceeded = testSucceeded and (response['data'] == '')
+if not testSucceeded then print('Failed in HttpPost without body') PrintRecursive(response) end
 
 -- 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')
+testSucceeded = testSucceeded and (response['json']['intMember'] == 2 and response['json']['stringMember'] == 'toto')
+if not testSucceeded then print('Failed in HttpPut with body') PrintRecursive(response) end
 
 -- 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')
+testSucceeded = testSucceeded and (response['data'] == '')
+if not testSucceeded then print('Failed in HttpPut without body') PrintRecursive(response) end
 
 -- Issue HttpDelete (juste make sure it is issued, we can't check the response)
 HttpDelete('http://httpbin.org/delete', httpHeaders)
@@ -33,6 +40,7 @@
 -- 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 not testSucceeded then print('Failed in HttpGet') PrintRecursive(response) end
 
 if testSucceeded then
 	print('OK')
--- a/Tests/Tests.py	Thu Feb 02 21:11:19 2017 +0100
+++ b/Tests/Tests.py	Thu Mar 02 20:10:03 2017 +0100
@@ -3137,8 +3137,8 @@
         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:
+    def test_httpClient_lua(self):
+        with open(GetDatabasePath('Lua/HttpClient.lua'), 'r') as f:
             result = DoPost(_REMOTE, '/tools/execute-script', f.read(), 'application/lua')
 
         self.assertIn('OK', result)