#NEWLINE# def test_deserialize( self ) : #NEWLINE# #INDENT# '\n        Send various encoded forms of lowstates (and bad ones) to make sure we\n        handle deserialization correctly\n        ' #NEWLINE# valid_lowstate = [ { #NEWLINE# #INDENT# 'client' : 'local' , #NEWLINE# 'tgt' : '*' , #NEWLINE# 'fun' : 'test.fib' , #NEWLINE# 'arg' : [ '10' ] , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# 'client' : 'runner' , #NEWLINE# 'fun' : 'jobs.lookup_jid' , #NEWLINE# 'jid' : '20130603122505459265' , #NEWLINE# #UNINDENT# } ] #NEWLINE# response = self . fetch ( '/' , method = 'POST' , body = json . dumps ( valid_lowstate ) , headers = { #NEWLINE# #INDENT# 'Content-Type' : self . content_type_map [ 'json' ] , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertEqual ( valid_lowstate , json . loads ( response . body ) [ 'lowstate' ] ) #NEWLINE# response = self . fetch ( '/' , method = 'POST' , body = yaml . dump ( valid_lowstate ) , headers = { #NEWLINE# #INDENT# 'Content-Type' : self . content_type_map [ 'json' ] , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertEqual ( response . code , 400 ) #NEWLINE# response = self . fetch ( '/' , method = 'POST' , body = yaml . dump ( valid_lowstate ) , headers = { #NEWLINE# #INDENT# 'Content-Type' : self . content_type_map [ 'yaml' ] , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertEqual ( valid_lowstate , json . loads ( response . body ) [ 'lowstate' ] ) #NEWLINE# response = self . fetch ( '/' , method = 'POST' , body = json . dumps ( valid_lowstate ) , headers = { #NEWLINE# #INDENT# 'Content-Type' : self . content_type_map [ 'yaml' ] , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertEqual ( valid_lowstate , json . loads ( response . body ) [ 'lowstate' ] ) #NEWLINE# response = self . fetch ( '/' , method = 'POST' , body = json . dumps ( valid_lowstate ) , headers = { #NEWLINE# #INDENT# 'Content-Type' : self . content_type_map [ 'text' ] , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertEqual ( valid_lowstate , json . loads ( response . body ) [ 'lowstate' ] ) #NEWLINE# form_lowstate = ( ( 'client' , 'local' ) , ( 'tgt' , '*' ) , ( 'fun' , 'test.fib' ) , ( 'arg' , '10' ) , ( 'arg' , 'foo' ) ) #NEWLINE# response = self . fetch ( '/' , method = 'POST' , body = urlencode ( form_lowstate ) , headers = { #NEWLINE# #INDENT# 'Content-Type' : self . content_type_map [ 'form' ] , #NEWLINE# #UNINDENT# } ) #NEWLINE# returned_lowstate = json . loads ( response . body ) [ 'lowstate' ] #NEWLINE# self . assertEqual ( len ( returned_lowstate ) , 1 ) #NEWLINE# returned_lowstate = returned_lowstate [ 0 ] #NEWLINE# self . assertEqual ( returned_lowstate [ 'client' ] , 'local' ) #NEWLINE# self . assertEqual ( returned_lowstate [ 'tgt' ] , '*' ) #NEWLINE# self . assertEqual ( form_lowstate [ 'fun' ] , 'test.fib' ) #NEWLINE# self . assertEqual ( returned_lowstate [ 'arg' ] , [ '10' , 'foo' ] ) #NEWLINE# response = self . fetch ( '/' , method = 'POST' , body = json . dumps ( valid_lowstate ) , headers = { #NEWLINE# #INDENT# 'Content-Type' : self . content_type_map [ 'json-utf8' ] , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertEqual ( valid_lowstate , json . loads ( response . body ) [ 'lowstate' ] )