<s> '''<STR_LIT>''' <EOL> import json <EOL> import unittest <EOL> import os <EOL> import flask <EOL> from lxml . html import fragment_fromstring <EOL> import werkzeug . wrappers <EOL> from framework . exceptions import HTTPError , http <EOL> from framework . routing import ( <EOL> Renderer , JSONRenderer , WebRenderer , <EOL> render_mako_string , <EOL> ) <EOL> from tests . base import AppTestCase , OsfTestCase <EOL> from website . routes import OsfWebRenderer <EOL> HERE = os . path . dirname ( os . path . abspath ( __file__ ) ) <EOL> TEMPLATES_PATH = os . path . join ( HERE , '<STR_LIT>' ) <EOL> class RendererTestCase ( AppTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( RendererTestCase , self ) . setUp ( ) <EOL> self . r = Renderer ( ) <EOL> def test_redirect ( self ) : <EOL> """<STR_LIT>""" <EOL> resp = flask . make_response ( '<STR_LIT>' ) <EOL> self . assertIsInstance ( <EOL> self . r ( resp ) , <EOL> werkzeug . wrappers . Response , <EOL> ) <EOL> def test_http_error_raised ( self ) : <EOL> """<STR_LIT>""" <EOL> with self . assertRaises ( NotImplementedError ) : <EOL> self . r ( HTTPError ( http . NOT_FOUND ) ) <EOL> def test_tuple ( self ) : <EOL> """<STR_LIT>""" <EOL> with self . assertRaises ( NotImplementedError ) : <EOL> self . r ( ( '<STR_LIT>' , ) ) <EOL> class JSONRendererTestCase ( RendererTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( JSONRendererTestCase , self ) . setUp ( ) <EOL> self . r = JSONRenderer ( ) <EOL> def test_redirect ( self ) : <EOL> """<STR_LIT>""" <EOL> resp = flask . make_response ( '<STR_LIT>' ) <EOL> self . assertIsInstance ( <EOL> self . r ( resp ) , <EOL> werkzeug . wrappers . Response , <EOL> ) <EOL> def test_http_error_raised ( self ) : <EOL> """<STR_LIT>""" <EOL> resp = self . r ( HTTPError ( http . NOT_FOUND ) ) <EOL> msg = HTTPError . error_msgs [ http . NOT_FOUND ] <EOL> self . assertEqual ( <EOL> ( <EOL> { <EOL> '<STR_LIT:code>' : http . NOT_FOUND , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : msg [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : msg [ '<STR_LIT>' ] , <EOL> } , <EOL> http . NOT_FOUND , <EOL> ) , <EOL> ( json . loads ( resp [ <NUM_LIT:0> ] ) , http . NOT_FOUND , ) , <EOL> ) <EOL> def test_tuple ( self ) : <EOL> pass <EOL> class WebRendererTestCase ( OsfTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( WebRendererTestCase , self ) . setUp ( ) <EOL> self . r = OsfWebRenderer ( <EOL> os . path . join ( TEMPLATES_PATH , '<STR_LIT>' ) , <EOL> render_mako_string <EOL> ) <EOL> def test_redirect ( self ) : <EOL> """<STR_LIT>""" <EOL> self . app . app . preprocess_request ( ) <EOL> resp = self . r ( <EOL> ( { } , <EOL> <NUM_LIT> , <EOL> None , <EOL> '<STR_LIT>' , <EOL> ) <EOL> ) <EOL> self . assertIsInstance ( <EOL> resp , <EOL> werkzeug . wrappers . Response , <EOL> ) <EOL> self . assertEqual ( <NUM_LIT> , resp . status_code ) <EOL> self . assertEqual ( '<STR_LIT>' , resp . location ) <EOL> def test_input_dict ( self ) : <EOL> """<STR_LIT>""" <EOL> self . app . app . preprocess_request ( ) <EOL> input_dict = { '<STR_LIT:foo>' : '<STR_LIT:bar>' } <EOL> resp = self . r ( input_dict ) <EOL> self . assertIsInstance ( <EOL> resp , werkzeug . wrappers . Response <EOL> ) <EOL> self . assertIn ( <EOL> '<STR_LIT>' , <EOL> resp . data <EOL> ) <EOL> def test_http_error_raised ( self ) : <EOL> """<STR_LIT>""" <EOL> self . app . app . preprocess_request ( ) <EOL> err = HTTPError ( http . NOT_FOUND ) <EOL> resp = self . r ( err ) <EOL> self . assertIn ( <EOL> err . to_data ( ) [ '<STR_LIT>' ] , <EOL> resp [ <NUM_LIT:0> ] , <EOL> ) <EOL> self . assertEqual ( <EOL> http . NOT_FOUND , <EOL> resp [ <NUM_LIT:1> ] , <EOL> ) <EOL> def test_http_error_raise_with_redirect ( self ) : <EOL> """<STR_LIT>""" <EOL> resp = self . r ( <EOL> HTTPError ( http . CREATED , redirect_url = '<STR_LIT>' ) <EOL> ) <EOL> self . assertIsInstance ( <EOL> resp , werkzeug . wrappers . Response <EOL> ) <EOL> self . assertEqual ( <NUM_LIT> , resp . status_code ) <EOL> self . assertEqual ( '<STR_LIT>' , resp . location ) <EOL> class WebRendererTemplateTestCase ( OsfTestCase ) : <EOL> def test_nested_templates ( self ) : <EOL> """<STR_LIT>""" <EOL> self . app . app . preprocess_request ( ) <EOL> r = WebRenderer ( <EOL> '<STR_LIT>' , <EOL> render_mako_string , <EOL> template_dir = TEMPLATES_PATH , <EOL> ) <EOL> resp = r ( { } ) <EOL> self . assertIsInstance ( resp , werkzeug . wrappers . Response ) <EOL> self . assertIn ( '<STR_LIT>' , resp . data ) <EOL> def test_render_included_template ( self ) : <EOL> """<STR_LIT>""" <EOL> self . app . app . preprocess_request ( ) <EOL> r = WebRenderer ( <EOL> '<STR_LIT>' , <EOL> render_mako_string , <EOL> template_dir = TEMPLATES_PATH , <EOL> ) <EOL> html = fragment_fromstring ( <EOL> '<STR_LIT>' . join ( ( <EOL> "<STR_LIT>" , <EOL> '<STR_LIT>' , <EOL> "<STR_LIT>" , <EOL> ) ) , <EOL> create_parent = '<STR_LIT>' , <EOL> ) <EOL> result = r . render_element ( <EOL> html . findall ( '<STR_LIT>' ) [ <NUM_LIT:0> ] , <EOL> data = { } , <EOL> ) <EOL> self . assertEqual ( <EOL> ( '<STR_LIT>' , True ) , <EOL> result , <EOL> ) <EOL> def test_broken_template_uri ( self ) : <EOL> """<STR_LIT>""" <EOL> self . app . app . preprocess_request ( ) <EOL> r = WebRenderer ( <EOL> '<STR_LIT>' , <EOL> render_mako_string , <EOL> template_dir = TEMPLATES_PATH , <EOL> ) <EOL> resp = r ( { } ) <EOL> self . assertIn ( <EOL> '<STR_LIT>' , <EOL> resp . data , <EOL> ) <EOL> def test_render_included_template_not_found ( self ) : <EOL> """<STR_LIT>""" <EOL> self . app . app . preprocess_request ( ) <EOL> r = WebRenderer ( <EOL> '<STR_LIT>' , <EOL> render_mako_string , <EOL> template_dir = '<STR_LIT>' , <EOL> ) <EOL> html = fragment_fromstring ( <EOL> '<STR_LIT>' . join ( ( <EOL> "<STR_LIT>" , <EOL> '<STR_LIT>' , <EOL> "<STR_LIT>" , <EOL> ) ) , <EOL> create_parent = '<STR_LIT>' , <EOL> ) <EOL> result = r . render_element ( <EOL> html . findall ( '<STR_LIT>' ) [ <NUM_LIT:0> ] , <EOL> data = { } , <EOL> ) <EOL> self . assertEqual ( <EOL> ( '<STR_LIT>' , True ) , <EOL> result , <EOL> ) <EOL> class JSONRendererEncoderTestCase ( unittest . TestCase ) : <EOL> def test_encode_custom_class ( self ) : <EOL> class TestClass ( object ) : <EOL> def to_json ( self ) : <EOL> return '<STR_LIT>' <EOL> test_object = TestClass ( ) <EOL> self . assertEqual ( <EOL> '<STR_LIT>' , <EOL> json . dumps ( test_object , cls = JSONRenderer . Encoder ) , <EOL> ) <EOL> def test_string ( self ) : <EOL> self . assertEqual ( <EOL> '<STR_LIT>' , <EOL> json . dumps ( '<STR_LIT>' , cls = JSONRenderer . Encoder ) <EOL> ) </s>
