# tests if the http post and query arguments are similar to what is sent from a client


# prints failed message if the test failes and raises an exception the registorhttpcallback
# or httpretrieve raises an exception and just excutes if the test passes


include registerhttpcallback.repy
include httpretrieve.repy



def test_normal_server(httprequest_dictionary, http_query, http_post):
  # normal server just sends a message

  #copy the received query and post, which is used check 
  mycontext['received_http_query'] = http_query
  mycontext['received_http_post'] = http_post

  return [' ', None]
   
    
if callfunc == 'initialize':
  # used to copy the query and the post that the server received  
  mycontext['received_http_query'] = {}
  mycontext['received_http_post'] = {}

  try:
    # set up a normal server   
    handle = registerhttpcallback('http://127.0.0.1:12345', test_normal_server)
  except Exception, e: 
    raise Exception()

  # data to post as query and post to a server
  http_query = {"First": "1st", "Second": "2nd"}
  http_post = {"Third": "3rd", "Fourth": "4th"}

  try:
    httpretrieve_get_string('http://127.0.0.1:12345', http_query, http_post)
  except Exception, e:
    raise Exception('http retrieve failed on retrieving data from server')  

  if mycontext['received_http_query'] != http_query:
    print 'query failed'
    print 'sent query dict was ' + str(http_query)
    print 'received query dict was ' + str(mycontext['received_http_query'])

  if mycontext['received_http_post'] != http_post:
    print 'post failed'
    print 'sent query dict was ' + str(http_query)
    print 'received query dict was ' + str(mycontext['received_http_post'])    
    


@@ -1278,17 +1278,26 @@
 ver')  %0A
-%0A
+  else:%0A  
   if myc
@@ -1341,24 +1341,26 @@
 _query:%0A    
+  
 print 'query
@@ -1364,32 +1364,34 @@
 ery failed'%0A    
+ 
+ 
 print 'sent quer
@@ -1413,32 +1413,34 @@
 str(http_query)%0A
+  
     print 'recei
@@ -1501,16 +1501,18 @@
 ery'%5D)%0A%0A
+  
   if myc
@@ -1554,24 +1554,26 @@
 p_post:%0A    
+ 
+ 
 print 'post 
@@ -1576,24 +1576,26 @@
 ost failed'%0A
+  
     print 's
@@ -1629,24 +1629,26 @@
 http_query)%0A
+  
     print 'r
@@ -1719,10 +1719,76 @@
    %0A    
-%0A
+  %0A  finally:%0A    #stop sever%0A    stop_registerhttpcallback(handle)
 %0A

Update test