<s> from __future__ import absolute_import <EOL> import hashlib <EOL> from . test_render import BaseRenderTest <EOL> from . test_execute import BaseLuaRenderTest <EOL> from . test_jsonpost import JsonPostRequestHandler <EOL> class RenderHtmlArgumentCachingTest ( BaseRenderTest ) : <EOL> endpoint = '<STR_LIT>' <EOL> def test_cache_url ( self ) : <EOL> resp = self . request ( { <EOL> "<STR_LIT:url>" : self . mockurl ( '<STR_LIT>' ) , <EOL> "<STR_LIT>" : <NUM_LIT:0.5> , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } ) <EOL> self . assertStatusCode ( resp , <NUM_LIT:200> ) <EOL> self . assertIn ( "<STR_LIT>" , resp . text ) <EOL> header = resp . headers [ '<STR_LIT>' ] <EOL> resp2 = self . request ( { "<STR_LIT>" : header } ) <EOL> self . assertStatusCode ( resp2 , <NUM_LIT:200> ) <EOL> assert resp2 . text == resp . text <EOL> resp3 = self . post ( { } , endpoint = "<STR_LIT>" ) <EOL> self . assertStatusCode ( resp3 , <NUM_LIT:200> ) <EOL> data = resp3 . json ( ) <EOL> assert data [ '<STR_LIT>' ] >= <NUM_LIT:2> <EOL> assert data [ '<STR_LIT>' ] > <NUM_LIT:0> <EOL> assert data [ '<STR_LIT:status>' ] == '<STR_LIT>' <EOL> resp4 = self . request ( { "<STR_LIT>" : header } ) <EOL> data = self . assertJsonError ( resp4 , <NUM_LIT> , '<STR_LIT>' ) <EOL> assert set ( data [ '<STR_LIT:info>' ] [ '<STR_LIT>' ] ) == { '<STR_LIT>' , '<STR_LIT:url>' } <EOL> class ArgumentCachingTest ( BaseLuaRenderTest ) : <EOL> request_handler = JsonPostRequestHandler <EOL> def test_cache_args ( self ) : <EOL> resp = self . request_lua ( """<STR_LIT>""" , { <EOL> "<STR_LIT>" : [ "<STR_LIT>" , "<STR_LIT:foo>" , "<STR_LIT:bar>" ] , <EOL> "<STR_LIT:foo>" : "<STR_LIT:hello>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } ) <EOL> self . assertStatusCode ( resp , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . json ( ) , { "<STR_LIT:foo>" : "<STR_LIT:hello>" , "<STR_LIT>" : "<STR_LIT>" } ) <EOL> hashes = dict ( <EOL> h . split ( "<STR_LIT:=>" , <NUM_LIT:1> ) for h in <EOL> resp . headers [ '<STR_LIT>' ] . split ( "<STR_LIT:;>" ) <EOL> ) <EOL> resp2 = self . request ( { "<STR_LIT>" : hashes , "<STR_LIT>" : "<STR_LIT:!>" } ) <EOL> self . assertStatusCode ( resp2 , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp2 . json ( ) , { "<STR_LIT:foo>" : "<STR_LIT:hello>" , "<STR_LIT>" : "<STR_LIT:!>" } ) <EOL> hashes [ "<STR_LIT:foo>" ] = hashlib . sha1 ( b"<STR_LIT>" ) . hexdigest ( ) <EOL> resp3 = self . request ( { "<STR_LIT>" : hashes , "<STR_LIT>" : "<STR_LIT:!>" } ) <EOL> data = self . assertJsonError ( resp3 , <NUM_LIT> , "<STR_LIT>" ) <EOL> self . assertEqual ( data [ '<STR_LIT:info>' ] , { '<STR_LIT>' : [ '<STR_LIT:foo>' ] } ) <EOL> def test_bad_save_args ( self ) : <EOL> resp = self . request_lua ( "<STR_LIT>" , { <EOL> "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT:yes>" } , <EOL> } ) <EOL> self . assertBadArgument ( resp , "<STR_LIT>" ) <EOL> resp = self . request_lua ( "<STR_LIT>" , { <EOL> "<STR_LIT>" : [ "<STR_LIT:foo>" , <NUM_LIT> ] , <EOL> } ) <EOL> self . assertBadArgument ( resp , "<STR_LIT>" ) <EOL> def test_bad_load_args ( self ) : <EOL> resp = self . request ( { "<STR_LIT>" : "<STR_LIT:foo>" } ) <EOL> self . assertBadArgument ( resp , "<STR_LIT>" ) <EOL> resp = self . request ( { "<STR_LIT>" : [ ( "<STR_LIT:foo>" , "<STR_LIT:bar>" ) ] } ) <EOL> self . assertBadArgument ( resp , "<STR_LIT>" ) </s>
