<s> from pyswagger import SwaggerApp , primitives , errs , io <EOL> from . . utils import get_test_data_folder <EOL> from pyswagger . spec . v2_0 import objects , parser <EOL> from pyswagger . spec import base <EOL> from pyswagger . utils import jp_compose <EOL> from pyswagger . primitives import SwaggerPrimitive <EOL> import os <EOL> import unittest <EOL> import datetime <EOL> import six <EOL> class SchemaTestCase ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def setUpClass ( kls ) : <EOL> kls . app = SwaggerApp . _create_ ( get_test_data_folder ( version = '<STR_LIT>' , which = os . path . join ( '<STR_LIT>' , '<STR_LIT>' ) ) ) <EOL> def test_model_tag ( self ) : <EOL> """<STR_LIT>""" <EOL> t = self . app . resolve ( '<STR_LIT>' ) <EOL> self . assertTrue ( isinstance ( t , objects . Schema ) ) <EOL> v = t . _prim_ ( dict ( id = <NUM_LIT:1> , name = '<STR_LIT>' ) , self . app . prim_factory ) <EOL> self . assertTrue ( isinstance ( v , primitives . Model ) ) <EOL> self . assertEqual ( v . id , <NUM_LIT:1> ) <EOL> self . assertEqual ( v . name , '<STR_LIT>' ) <EOL> def test_model_pet ( self ) : <EOL> """<STR_LIT>""" <EOL> p = self . app . resolve ( '<STR_LIT>' ) <EOL> self . assertTrue ( isinstance ( p , objects . Schema ) ) <EOL> v = p . _prim_ ( dict ( <EOL> name = '<STR_LIT>' , <EOL> photoUrls = [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> id = <NUM_LIT:10> , <EOL> category = dict ( <EOL> id = <NUM_LIT:1> , <EOL> name = '<STR_LIT>' <EOL> ) , <EOL> tags = [ <EOL> dict ( id = <NUM_LIT:1> , name = '<STR_LIT>' ) , <EOL> dict ( id = <NUM_LIT:2> , name = '<STR_LIT>' ) , <EOL> ] <EOL> ) , self . app . prim_factory ) <EOL> self . assertTrue ( isinstance ( v , primitives . Model ) ) <EOL> self . assertEqual ( v . name , '<STR_LIT>' ) <EOL> self . assertEqual ( v . photoUrls [ <NUM_LIT:0> ] , '<STR_LIT>' ) <EOL> self . assertEqual ( v . photoUrls [ <NUM_LIT:1> ] , '<STR_LIT>' ) <EOL> self . assertEqual ( v . id , <NUM_LIT:10> ) <EOL> self . assertTrue ( isinstance ( v . tags [ <NUM_LIT:0> ] , primitives . Model ) ) <EOL> self . assertTrue ( v . tags [ <NUM_LIT:0> ] . id , <NUM_LIT:1> ) <EOL> self . assertTrue ( v . tags [ <NUM_LIT:0> ] . name , '<STR_LIT>' ) <EOL> self . assertTrue ( isinstance ( v . category , primitives . Model ) ) <EOL> self . assertTrue ( v . category . id , <NUM_LIT:1> ) <EOL> self . assertTrue ( v . category . name , '<STR_LIT>' ) <EOL> def test_model_employee ( self ) : <EOL> """<STR_LIT>""" <EOL> e = self . app . resolve ( "<STR_LIT>" ) <EOL> self . assertTrue ( isinstance ( e , objects . Schema ) ) <EOL> v = e . _prim_ ( dict ( <EOL> id = <NUM_LIT:1> , <EOL> skill_id = <NUM_LIT:2> , <EOL> location = "<STR_LIT>" , <EOL> skill_name = "<STR_LIT>" , <EOL> email = "<STR_LIT>" <EOL> ) , self . app . prim_factory ) <EOL> self . assertTrue ( isinstance ( v , primitives . Model ) ) <EOL> self . assertEqual ( v . id , <NUM_LIT:1> ) <EOL> self . assertEqual ( v . skill_id , <NUM_LIT:2> ) <EOL> self . assertEqual ( v . location , "<STR_LIT>" ) <EOL> self . assertEqual ( v . skill_name , "<STR_LIT>" ) <EOL> self . assertRaises ( <EOL> errs . ValidationError , <EOL> e . _prim_ , dict ( <EOL> id = <NUM_LIT:1> , <EOL> skill_id = <NUM_LIT:2> , <EOL> location = "<STR_LIT>" , <EOL> skill_name = "<STR_LIT>" , <EOL> email = "<STR_LIT>" <EOL> ) , self . app . prim_factory <EOL> ) <EOL> def test_model_boss ( self ) : <EOL> """<STR_LIT>""" <EOL> b = self . app . resolve ( "<STR_LIT>" ) <EOL> self . assertTrue ( isinstance ( b , objects . Schema ) ) <EOL> v = b . _prim_ ( dict ( <EOL> id = <NUM_LIT:1> , <EOL> location = "<STR_LIT>" , <EOL> boss_name = "<STR_LIT>" <EOL> ) , self . app . prim_factory ) <EOL> self . assertTrue ( isinstance ( v , primitives . Model ) ) <EOL> self . assertEqual ( v . id , <NUM_LIT:1> ) <EOL> self . assertEqual ( v . location , "<STR_LIT>" ) <EOL> self . assertEqual ( v . boss_name , "<STR_LIT>" ) <EOL> def test_int ( self ) : <EOL> """<STR_LIT>""" <EOL> i = self . app . resolve ( "<STR_LIT>" ) <EOL> self . assertRaises ( errs . ValidationError , i . _prim_ , <NUM_LIT:200> , self . app . prim_factory ) <EOL> self . assertRaises ( errs . ValidationError , i . _prim_ , <NUM_LIT> , self . app . prim_factory ) <EOL> def test_array_of_int ( self ) : <EOL> """<STR_LIT>""" <EOL> i = self . app . resolve ( '<STR_LIT>' ) <EOL> i . _prim_ ( [ <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ] , self . app . prim_factory ) <EOL> i . _prim_ ( [ <NUM_LIT:1> , <NUM_LIT:1> ] , self . app . prim_factory ) <EOL> self . assertRaises ( errs . ValidationError , i . _prim_ , [ <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ] , self . app . prim_factory ) <EOL> self . assertRaises ( errs . ValidationError , i . _prim_ , [ <NUM_LIT:1> ] , self . app . prim_factory ) <EOL> def test_num_multiple_of ( self ) : <EOL> """<STR_LIT>""" <EOL> i = self . app . resolve ( "<STR_LIT>" ) <EOL> self . assertRaises ( errs . ValidationError , i . _prim_ , <NUM_LIT:4> , self . app . prim_factory ) <EOL> i . _prim_ ( <NUM_LIT:5> , self . app . prim_factory ) <EOL> def test_str_enum ( self ) : <EOL> """<STR_LIT>""" <EOL> e = self . app . resolve ( "<STR_LIT>" ) <EOL> self . assertRaises ( errs . ValidationError , e . _prim_ , "<STR_LIT>" , self . app . prim_factory ) <EOL> e . _prim_ ( "<STR_LIT>" , self . app . prim_factory ) <EOL> def test_byte ( self ) : <EOL> """<STR_LIT>""" <EOL> b = self . app . resolve ( "<STR_LIT>" ) <EOL> bv = b . _prim_ ( "<STR_LIT>" , self . app . prim_factory ) <EOL> self . assertEqual ( str ( bv ) , "<STR_LIT>" , self . app . prim_factory ) <EOL> self . assertEqual ( bv . to_json ( ) , six . b ( "<STR_LIT>" ) ) <EOL> def test_date ( self ) : <EOL> """<STR_LIT>""" <EOL> d = self . app . resolve ( "<STR_LIT>" ) <EOL> self . assertEqual ( str ( d . _prim_ ( float ( <NUM_LIT:0> ) , self . app . prim_factory ) ) , "<STR_LIT>" ) <EOL> self . assertEqual ( str ( d . _prim_ ( datetime . date . fromtimestamp ( <NUM_LIT:0> ) , self . app . prim_factory ) ) , "<STR_LIT>" ) <EOL> self . assertEqual ( str ( d . _prim_ ( datetime . date . fromtimestamp ( <NUM_LIT:0> ) . isoformat ( ) , self . app . prim_factory ) ) , "<STR_LIT>" ) <EOL> dv = d . _prim_ ( float ( <NUM_LIT:0> ) , self . app . prim_factory ) <EOL> self . assertEqual ( dv . to_json ( ) , "<STR_LIT>" ) <EOL> def test_date_time ( self ) : <EOL> """<STR_LIT>""" <EOL> d = self . app . resolve ( "<STR_LIT>" ) <EOL> self . assertEqual ( str ( d . _prim_ ( float ( <NUM_LIT:0> ) , self . app . prim_factory ) ) , "<STR_LIT>" ) <EOL> self . assertEqual ( str ( d . _prim_ ( datetime . datetime . utcfromtimestamp ( <NUM_LIT:0> ) , self . app . prim_factory ) ) , "<STR_LIT>" ) <EOL> self . assertEqual ( str ( d . _prim_ ( datetime . datetime . utcfromtimestamp ( <NUM_LIT:0> ) . isoformat ( ) , self . app . prim_factory ) ) , "<STR_LIT>" ) <EOL> dv = d . _prim_ ( float ( <NUM_LIT:0> ) , self . app . prim_factory ) <EOL> self . assertEqual ( dv . to_json ( ) , "<STR_LIT>" ) <EOL> def test_model_bool ( self ) : <EOL> """<STR_LIT>""" <EOL> d = self . app . resolve ( "<STR_LIT>" ) <EOL> dv = d . _prim_ ( dict ( bool_val = True ) , self . app . prim_factory ) <EOL> self . assertEqual ( dv . bool_val , True ) <EOL> def test_email ( self ) : <EOL> """<STR_LIT>""" <EOL> d = self . app . resolve ( '<STR_LIT>' ) <EOL> dv = d . _prim_ ( '<STR_LIT>' , self . app . prim_factory ) <EOL> self . assertEqual ( dv , '<STR_LIT>' ) <EOL> self . assertRaises ( errs . ValidationError , d . _prim_ , '<STR_LIT>' , self . app . prim_factory ) <EOL> def test_uuid ( self ) : <EOL> """<STR_LIT>""" <EOL> d = self . app . resolve ( '<STR_LIT>' ) <EOL> dv = d . _prim_ ( '<STR_LIT>' , self . app . prim_factory ) <EOL> self . assertTrue ( isinstance ( dv , primitives . UUID ) , '<STR_LIT>' . format ( str ( type ( dv ) ) ) ) <EOL> self . assertEqual ( str ( dv ) , '<STR_LIT>' ) <EOL> dv = d . _prim_ ( six . b ( '<STR_LIT>' ) , self . app . prim_factory ) <EOL> self . assertTrue ( isinstance ( dv , primitives . UUID ) , '<STR_LIT>' . format ( dv ) ) <EOL> self . assertEqual ( dv . v . bytes , six . b ( '<STR_LIT>' ) ) <EOL> class HeaderTestCase ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def setUpClass ( kls ) : <EOL> kls . app = SwaggerApp . _create_ ( get_test_data_folder ( version = '<STR_LIT>' , which = os . path . join ( '<STR_LIT>' , '<STR_LIT>' ) ) ) <EOL> def test_simple_array ( self ) : <EOL> """<STR_LIT>""" <EOL> p1 = self . app . resolve ( jp_compose ( [ '<STR_LIT:#>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:0>' ] ) ) <EOL> self . assertTrue ( isinstance ( p1 , objects . Parameter ) ) <EOL> v = p1 . _prim_ ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] , self . app . prim_factory ) <EOL> self . assertTrue ( isinstance ( v , primitives . Array ) ) <EOL> self . assertEqual ( str ( v ) , '<STR_LIT>' ) <EOL> def test_integer_limit ( self ) : <EOL> """<STR_LIT>""" <EOL> p2 = self . app . resolve ( jp_compose ( [ '<STR_LIT:#>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:1>' ] ) ) <EOL> self . assertTrue ( isinstance ( p2 , objects . Parameter ) ) <EOL> self . assertRaises ( errs . ValidationError , p2 . _prim_ , <NUM_LIT> , self . app . prim_factory ) <EOL> self . assertRaises ( errs . ValidationError , p2 . _prim_ , - <NUM_LIT:1> , self . app . prim_factory ) <EOL> def test_multi_level_array ( self ) : <EOL> """<STR_LIT>""" <EOL> p3 = self . app . resolve ( jp_compose ( [ '<STR_LIT:#>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:2>' ] ) ) <EOL> self . assertTrue ( isinstance ( p3 , objects . Parameter ) ) <EOL> self . assertEqual ( str ( p3 . _prim_ ( <EOL> [ <EOL> [ <EOL> [ <NUM_LIT:1> , <NUM_LIT:2> ] , <EOL> [ <NUM_LIT:3> , <NUM_LIT:4> ] , <EOL> [ <NUM_LIT:5> , <NUM_LIT:6> ] <EOL> ] , <EOL> [ <EOL> [ <NUM_LIT:7> , <NUM_LIT:8> ] , <EOL> [ <NUM_LIT:9> , <NUM_LIT:10> ] <EOL> ] , <EOL> [ <EOL> [ <NUM_LIT:11> , <NUM_LIT:12> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> ] <EOL> ] <EOL> ] , self . app . prim_factory ) ) , '<STR_LIT>' ) <EOL> def test_header_in_response ( self ) : <EOL> """<STR_LIT>""" <EOL> resp = io . SwaggerResponse ( self . app . s ( '<STR_LIT>' ) . get ) <EOL> resp . apply_with ( status = <NUM_LIT:200> , raw = None , header = dict ( <EOL> test = '<STR_LIT>' <EOL> ) ) <EOL> self . assertEqual ( resp . header [ '<STR_LIT:test>' ] , [ [ <EOL> [ <EOL> [ <NUM_LIT:1> , <NUM_LIT:2> ] , <EOL> [ <NUM_LIT:3> , <NUM_LIT:4> ] , <EOL> [ <NUM_LIT:5> , <NUM_LIT:6> ] <EOL> ] , <EOL> [ <EOL> [ <NUM_LIT:7> , <NUM_LIT:8> ] , <EOL> [ <NUM_LIT:9> , <NUM_LIT:10> ] <EOL> ] , <EOL> [ <EOL> [ <NUM_LIT:11> , <NUM_LIT:12> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> ] <EOL> ] <EOL> ] ] ) <EOL> class AdditionalPropertiesTestCase ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def setUpClass ( kls ) : <EOL> kls . app = SwaggerApp . _create_ ( get_test_data_folder ( version = '<STR_LIT>' , which = os . path . join ( '<STR_LIT>' , '<STR_LIT>' ) ) ) <EOL> def test_merge ( self ) : <EOL> """<STR_LIT>""" <EOL> addp = self . app . resolve ( '<STR_LIT>' ) <EOL> final = objects . Schema ( base . NullContext ( ) ) <EOL> final . merge ( addp , parser . SchemaContext ) <EOL> addp = self . app . resolve ( '<STR_LIT>' ) <EOL> final = objects . Schema ( base . NullContext ( ) ) <EOL> final . merge ( addp , parser . SchemaContext ) <EOL> addp = self . app . resolve ( '<STR_LIT>' ) <EOL> final = objects . Schema ( base . NullContext ( ) ) <EOL> final . merge ( addp , parser . SchemaContext ) <EOL> addp = self . app . resolve ( '<STR_LIT>' ) <EOL> final = objects . Schema ( base . NullContext ( ) ) <EOL> final . merge ( addp , parser . SchemaContext ) <EOL> def test_with_schema ( self ) : <EOL> m = self . app . prim_factory . produce ( <EOL> self . app . resolve ( '<STR_LIT>' ) , <EOL> dict ( <EOL> name_of_map = '<STR_LIT:test>' , <EOL> category1 = dict ( <EOL> id = <NUM_LIT:1> , <EOL> name = '<STR_LIT>' <EOL> ) , <EOL> category2 = dict ( <EOL> id = <NUM_LIT:2> , <EOL> name = '<STR_LIT>' <EOL> ) , <EOL> category3 = dict ( <EOL> id = <NUM_LIT:3> , <EOL> name = '<STR_LIT>' <EOL> ) <EOL> ) ) <EOL> self . assertTrue ( isinstance ( m , primitives . Model ) ) <EOL> self . assertEqual ( m . name_of_map , '<STR_LIT:test>' ) <EOL> self . assertEqual ( m . category1 . id , <NUM_LIT:1> ) <EOL> self . assertEqual ( m . category1 . name , '<STR_LIT>' ) <EOL> self . assertEqual ( m . category2 . id , <NUM_LIT:2> ) <EOL> self . assertEqual ( m . category2 . name , '<STR_LIT>' ) <EOL> self . assertEqual ( m . category3 . id , <NUM_LIT:3> ) <EOL> self . assertEqual ( m . category3 . name , '<STR_LIT>' ) <EOL> def test_with_bool ( self ) : <EOL> d = self . app . resolve ( '<STR_LIT>' ) <EOL> m = self . app . prim_factory . produce ( <EOL> d , <EOL> dict ( <EOL> name = '<STR_LIT>' , <EOL> category1 = <NUM_LIT:1> , <EOL> category2 = '<STR_LIT>' <EOL> ) <EOL> ) <EOL> self . assertTrue ( isinstance ( m , primitives . Model ) ) <EOL> self . assertEqual ( m . name , '<STR_LIT>' ) <EOL> self . assertEqual ( m . category1 , <NUM_LIT:1> ) <EOL> self . assertEqual ( m . category2 , '<STR_LIT>' ) <EOL> def test_with_bool_false ( self ) : <EOL> d = self . app . resolve ( '<STR_LIT>' ) <EOL> m = self . app . prim_factory . produce ( <EOL> d , <EOL> dict ( <EOL> name = '<STR_LIT>' , <EOL> category1 = <NUM_LIT:1> , <EOL> category2 = '<STR_LIT>' <EOL> ) <EOL> ) <EOL> self . assertTrue ( isinstance ( m , primitives . Model ) ) <EOL> self . assertEqual ( m . name , '<STR_LIT>' ) <EOL> self . assertTrue ( '<STR_LIT>' not in m ) <EOL> self . assertTrue ( '<STR_LIT>' not in m ) <EOL> def test_with_allof_limitation ( self ) : <EOL> """<STR_LIT>""" <EOL> d = self . app . resolve ( '<STR_LIT>' ) <EOL> self . assertRaises ( errs . ValidationError , self . app . prim_factory . produce , <EOL> d , <EOL> dict ( <EOL> my_int = <NUM_LIT> <EOL> ) <EOL> ) <EOL> def test_array_addp_without_prop ( self ) : <EOL> """<STR_LIT>""" <EOL> d = self . app . resolve ( '<STR_LIT>' ) <EOL> m = self . app . prim_factory . produce ( <EOL> d , [ <EOL> dict ( a = <NUM_LIT:1> , b = <NUM_LIT:2> , c = <NUM_LIT:3> ) , <EOL> dict ( name = '<STR_LIT>' , email = '<STR_LIT>' ) , <EOL> ] <EOL> ) <EOL> self . assertEqual ( len ( m ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( m [ <NUM_LIT:0> ] , dict ( a = <NUM_LIT:1> , b = <NUM_LIT:2> , c = <NUM_LIT:3> ) ) <EOL> self . assertEqual ( m [ <NUM_LIT:1> ] , dict ( name = '<STR_LIT>' , email = '<STR_LIT>' ) ) <EOL> class ParameterTestCase ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def setUpClass ( kls ) : <EOL> kls . app = SwaggerApp . _create_ ( get_test_data_folder ( version = '<STR_LIT>' , which = os . path . join ( '<STR_LIT>' , '<STR_LIT>' ) ) ) <EOL> def test_unknown ( self ) : <EOL> p = self . app . resolve ( '<STR_LIT>' ) <EOL> self . assertRaises ( ValueError , p , p1 = '<STR_LIT>' , p2 = '<STR_LIT>' , p3 = '<STR_LIT>' , p4 = '<STR_LIT>' ) <EOL> class PrimitiveExtensionTestCase ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def setUpClass ( kls ) : <EOL> factory = SwaggerPrimitive ( ) <EOL> def decode_int ( obj , val , ctx ) : <EOL> return int ( val ) - <NUM_LIT:1> <EOL> def decode_str ( obj , val , ctx ) : <EOL> return str ( val ) [ : - <NUM_LIT:1> ] <EOL> def str_no_validate ( obj , val , ctx ) : <EOL> return str ( val ) <EOL> factory . register ( '<STR_LIT>' , None , decode_int ) <EOL> factory . register ( '<STR_LIT:string>' , '<STR_LIT>' , decode_str ) <EOL> factory . register ( '<STR_LIT:string>' , None , str_no_validate , _2nd_pass = None ) <EOL> kls . app = SwaggerApp . load ( get_test_data_folder ( <EOL> version = '<STR_LIT>' , <EOL> which = os . path . join ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ) , prim = factory ) <EOL> kls . app . prepare ( ) <EOL> def test_extend ( self ) : <EOL> """<STR_LIT>""" <EOL> m1 = self . app . resolve ( '<STR_LIT>' ) <EOL> v = m1 . _prim_ ( { <EOL> "<STR_LIT>" : <NUM_LIT:100> , <EOL> "<STR_LIT:name>" : '<STR_LIT>' , <EOL> } , self . app . prim_factory ) <EOL> self . assertEqual ( v . _id , <NUM_LIT> ) <EOL> self . assertEqual ( v . name , '<STR_LIT:M>' ) <EOL> def test_overwrite ( self ) : <EOL> """<STR_LIT>""" <EOL> m1 = self . app . resolve ( '<STR_LIT>' ) <EOL> v = m1 . _prim_ ( { <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } , self . app . prim_factory ) <EOL> self . assertEqual ( v . job , "<STR_LIT>" ) <EOL> app = SwaggerApp . create ( get_test_data_folder ( <EOL> version = '<STR_LIT>' , <EOL> which = os . path . join ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> ) ) <EOL> m1 = app . resolve ( '<STR_LIT>' ) <EOL> self . assertRaises ( errs . ValidationError , m1 . _prim_ , { '<STR_LIT>' : '<STR_LIT>' } , app . prim_factory ) </s>
