#NEWLINE# @ pytest . mark . parametrize ( ( 'status' , 'body' , 'content_type' ) , [ ( 200 , 'hi there' , 'text/plain' ) , ( 200 , '{"hi": "there"}' , 'application/json' ) , ( 200 , json . dumps ( { #NEWLINE# #INDENT# '_links' : { #NEWLINE# #INDENT# 'alternate' : { #NEWLINE# #INDENT# 'href' : '/hogo' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , #NEWLINE# 'hi' : 'there' , #NEWLINE# #UNINDENT# } ) , 'application/hal+json' ) ] ) #NEWLINE# def test_OrphanResource__basic( status , body , content_type ) : #NEWLINE# #INDENT# with httprettify ( ) as HTTPretty : #NEWLINE# #INDENT# index_uri = 'http://www.example.com/api/' #NEWLINE# hosts_uri = ( index_uri + 'hosts' ) #NEWLINE# index_links = { #NEWLINE# #INDENT# 'hosts' : { #NEWLINE# #INDENT# 'href' : hosts_uri , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# register_hal ( index_uri , index_links ) #NEWLINE# HTTPretty . register_uri ( 'POST' , uri = hosts_uri , status = status , body = body , content_type = content_type ) #NEWLINE# N = HN . Navigator . hal ( index_uri ) #NEWLINE# N2 = OR [ 'hosts' ] #NEWLINE# OR = N2 . create ( { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# assert isinstance ( OR , HN . OrphanHALNavigator ) #NEWLINE# assert ( OR . status [ 0 ] == status ) #NEWLINE# assert ( OR . parent is N2 ) #NEWLINE# with pytest . raises ( AttributeError ) : #NEWLINE# #INDENT# OR . fetch ( ) #NEWLINE# #UNINDENT# with pytest . raises ( AttributeError ) : #NEWLINE# #INDENT# OR . create ( { #NEWLINE# #INDENT# 'values' : True , #NEWLINE# 'hi' : 'there' , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# if ( ( status == 200 ) and ( content_type == 'text/plain' ) ) : #NEWLINE# #INDENT# assert ( OR . state == { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# assert ( OR . response . text == 'hi there' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( content_type == 'application/json' ) : #NEWLINE# #INDENT# assert ( OR . state == { #NEWLINE# #INDENT# 'hi' : 'there' , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( content_type == 'application/hal+json' ) : #NEWLINE# #INDENT# assert ( 'alternate' in OR . links ( ) ) #NEWLINE# assert ( OR . links ( ) [ 'alternate' ] . uri == 'http://www.example.com/hogo' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( status == 204 ) : #NEWLINE# #INDENT# assert ( OR . state == { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# assert ( OR . links ( ) == { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# assert ( OR ( ) == OR . state )