#NEWLINE# def test_put_tender_contract_document( self ) : #NEWLINE# #INDENT# response = self . app . post ( '/tenders/{}/contracts/{}/documents' . format ( self . tender_id , self . contract_id ) , upload_files = [ ( 'file' , 'name.doc' , 'content' ) ] ) #NEWLINE# self . assertEqual ( response . status , '201 Created' ) #NEWLINE# self . assertEqual ( response . content_type , 'application/json' ) #NEWLINE# doc_id = response . json [ 'data' ] [ 'id' ] #NEWLINE# self . assertIn ( doc_id , response . headers [ 'Location' ] ) #NEWLINE# response = self . app . put ( '/tenders/{}/contracts/{}/documents/{}' . format ( self . tender_id , self . contract_id , doc_id ) , status = 404 , upload_files = [ ( 'invalid_name' , 'name.doc' , 'content' ) ] ) #NEWLINE# self . assertEqual ( response . status , '404 Not Found' ) #NEWLINE# self . assertEqual ( response . content_type , 'application/json' ) #NEWLINE# self . assertEqual ( response . json [ 'status' ] , 'error' ) #NEWLINE# self . assertEqual ( response . json [ 'errors' ] , [ { #NEWLINE# #INDENT# 'description' : 'Not Found' , #NEWLINE# 'location' : 'body' , #NEWLINE# 'name' : 'file' , #NEWLINE# #UNINDENT# } ] ) #NEWLINE# response = self . app . put ( '/tenders/{}/contracts/{}/documents/{}' . format ( self . tender_id , self . contract_id , doc_id ) , upload_files = [ ( 'file' , 'name.doc' , 'content2' ) ] ) #NEWLINE# self . assertEqual ( response . status , '200 OK' ) #NEWLINE# self . assertEqual ( response . content_type , 'application/json' ) #NEWLINE# self . assertEqual ( doc_id , response . json [ 'data' ] [ 'id' ] ) #NEWLINE# key = response . json [ 'data' ] [ 'url' ] . split ( '?' ) [ ( - 1 ) ] #NEWLINE# response = self . app . get ( '/tenders/{}/contracts/{}/documents/{}?{}' . format ( self . tender_id , self . contract_id , doc_id , self ) ) #NEWLINE# self . assertEqual ( response . status , '200 OK' ) #NEWLINE# self . assertEqual ( response . content_type , 'application/msword' ) #NEWLINE# self . assertEqual ( response . content_length , 8 ) #NEWLINE# self . assertEqual ( response . body , 'content2' ) #NEWLINE# response = self . app . get ( '/tenders/{}/contracts/{}/documents/{}' . format ( self . tender_id , self . contract_id , doc_id ) ) #NEWLINE# self . assertEqual ( response . status , '200 OK' ) #NEWLINE# self . assertEqual ( response . content_type , 'application/json' ) #NEWLINE# self . assertEqual ( doc_id , response . json [ 'data' ] [ 'id' ] ) #NEWLINE# self . assertEqual ( 'name.doc' , response . json [ 'data' ] [ 'title' ] ) #NEWLINE# response = self . app . put ( '/tenders/{}/contracts/{}/documents/{}' . format ( self . tender_id , self . contract_id , doc_id ) , 'content3' , content_type = 'application/msword' ) #NEWLINE# self . assertEqual ( response . status , '200 OK' ) #NEWLINE# self . assertEqual ( response . content_type , 'application/json' ) #NEWLINE# self . assertEqual ( doc_id , response . json [ 'data' ] [ 'id' ] ) #NEWLINE# key = response . json [ 'data' ] [ 'url' ] . split ( '?' ) [ ( - 1 ) ] #NEWLINE# response = self . app . get ( '/tenders/{}/contracts/{}/documents/{}?{}' . format ( self . tender_id , self . contract_id , doc_id , key ) ) #NEWLINE# self . assertEqual ( response . status , '200 OK' ) #NEWLINE# self . assertEqual ( response . content_type , 'application/msword' ) #NEWLINE# self . assertEqual ( response . content_length , 8 ) #NEWLINE# self . assertEqual ( response . body , 'content3' ) #NEWLINE# tender = self . db . get ( self . tender_id ) #NEWLINE# tender [ 'contracts' ] [ ( - 1 ) ] [ 'status' ] = 'cancelled' #NEWLINE# self . db . save ( tender ) #NEWLINE# response = self . app . put ( '/tenders/{}/contracts/{}/documents/{}' . format ( self . tender_id , self . contract_id , doc_id ) , upload_files = [ ( 'file' , 'name.doc' , 'content3' ) ] , status = 403 ) #NEWLINE# self . assertEqual ( response . status , '403 Forbidden' ) #NEWLINE# self . assertEqual ( response . content_type , 'application/json' ) #NEWLINE# self . assertEqual ( response . json [ 'errors' ] [ 0 ] [ 'description' ] , "Can't update document in current contract status" ) #NEWLINE# self . set_status ( 'unsuccessful' ) #NEWLINE# response = self . app . put ( '/tenders/{}/contracts/{}/documents/{}' . format ( self . tender_id , self . contract_id , doc_id ) , upload_files = [ ( 'file' , 'name.doc' , 'content3' ) ] , status = 403 ) #NEWLINE# self . assertEqual ( response . status , '403 Forbidden' ) #NEWLINE# self . assertEqual ( response . content_type , 'application/json' ) #NEWLINE# self . assertEqual ( response . json [ 'errors' ] [ 0 ] [ 'description' ] , "Can't update document in current (unsuccessful) tender status" )