#NEWLINE# def test_patch_tender_contract( self ) : #NEWLINE# #INDENT# response = self . app . get ( '/tenders/{}/contracts' . format ( self . tender_id ) ) #NEWLINE# contract = response . json [ 'data' ] [ 0 ] #NEWLINE# response = self . app . patch_json ( '/tenders/{}/contracts/{}' . format ( self . tender_id , contract [ 'id' ] ) , { #NEWLINE# #INDENT# 'data' : { #NEWLINE# #INDENT# 'status' : 'active' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , status = 403 ) #NEWLINE# self . assertEqual ( response . status , '403 Forbidden' ) #NEWLINE# self . assertEqual ( response . content_type , 'application/json' ) #NEWLINE# self . assertIn ( "Can't sign contract before stand-still period end (" , response . json [ 'errors' ] [ 0 ] [ 'description' ] ) #NEWLINE# self . set_status ( 'complete' , { #NEWLINE# #INDENT# 'status' : 'active.awarded' , #NEWLINE# #UNINDENT# } ) #NEWLINE# response = self . app . post_json ( '/tenders/{}/awards/{}/complaints' . format ( self . tender_id , self . award_id ) , { #NEWLINE# #INDENT# 'data' : { #NEWLINE# #INDENT# 'title' : 'complaint title' , #NEWLINE# 'description' : 'complaint description' , #NEWLINE# 'author' : test_organization , #NEWLINE# 'status' : 'claim' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertEqual ( response . status , '201 Created' ) #NEWLINE# complaint = response . json [ 'data' ] #NEWLINE# owner_token = response . json [ 'access' ] [ 'token' ] #NEWLINE# tender = self . db . get ( self . tender_id ) #NEWLINE# for i in tender . get ( 'awards' , [ ] ) : #NEWLINE# #INDENT# i [ 'complaintPeriod' ] [ 'endDate' ] = i [ 'complaintPeriod' ] [ 'startDate' ] #NEWLINE# #UNINDENT# self . db . save ( tender ) #NEWLINE# response = self . app . patch_json ( '/tenders/{}/contracts/{}' . format ( self . tender_id , contract [ 'id' ] ) , { #NEWLINE# #INDENT# 'data' : { #NEWLINE# #INDENT# 'contractID' : 'myselfID' , #NEWLINE# 'items' : [ { #NEWLINE# #INDENT# 'description' : 'New Description' , #NEWLINE# #UNINDENT# } ] , #NEWLINE# 'suppliers' : [ { #NEWLINE# #INDENT# 'name' : 'New Name' , #NEWLINE# #UNINDENT# } ] , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# response = self . app . get ( '/tenders/{}/contracts/{}' . format ( self . tender_id , contract [ 'id' ] ) ) #NEWLINE# self . assertEqual ( response . json [ 'data' ] [ 'contractID' ] , contract [ 'contractID' ] ) #NEWLINE# self . assertEqual ( response . json [ 'data' ] [ 'items' ] , contract [ 'items' ] ) #NEWLINE# self . assertEqual ( response . json [ 'data' ] [ 'suppliers' ] , contract [ 'suppliers' ] ) #NEWLINE# response = self . app . patch_json ( '/tenders/{}/contracts/{}' . format ( self . tender_id , contract [ 'id' ] ) , { #NEWLINE# #INDENT# 'data' : { #NEWLINE# #INDENT# 'value' : { #NEWLINE# #INDENT# 'currency' : 'USD' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , status = 403 ) #NEWLINE# self . assertEqual ( response . status , '403 Forbidden' ) #NEWLINE# self . assertEqual ( response . json [ 'errors' ] [ 0 ] [ 'description' ] , "Can't update currency for contract value" ) #NEWLINE# response = self . app . patch_json ( '/tenders/{}/contracts/{}' . format ( self . tender_id , contract [ 'id' ] ) , { #NEWLINE# #INDENT# 'data' : { #NEWLINE# #INDENT# 'value' : { #NEWLINE# #INDENT# 'valueAddedTaxIncluded' : False , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , status = 403 ) #NEWLINE# self . assertEqual ( response . status , '403 Forbidden' ) #NEWLINE# self . assertEqual ( response . json [ 'errors' ] [ 0 ] [ 'description' ] , "Can't update valueAddedTaxIncluded for contract value" ) #NEWLINE# response = self . app . patch_json ( '/tenders/{}/contracts/{}' . format ( self . tender_id , contract [ 'id' ] ) , { #NEWLINE# #INDENT# 'data' : { #NEWLINE# #INDENT# 'value' : { #NEWLINE# #INDENT# 'amount' : 501 , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , status = 403 ) #NEWLINE# self . assertEqual ( response . status , '403 Forbidden' ) #NEWLINE# self . assertEqual ( response . json [ 'errors' ] [ 0 ] [ 'description' ] , 'Value amount should be less or equal to awarded amount (500.0)' ) #NEWLINE# response = self . app . patch_json ( '/tenders/{}/contracts/{}' . format ( self . tender_id , contract [ 'id' ] ) , { #NEWLINE# #INDENT# 'data' : { #NEWLINE# #INDENT# 'value' : { #NEWLINE# #INDENT# 'amount' : 238 , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertEqual ( response . status , '200 OK' ) #NEWLINE# self . assertEqual ( response . json [ 'data' ] [ 'value' ] [ 'amount' ] , 238 ) #NEWLINE# response = self . app . patch_json ( '/tenders/{}/contracts/{}' . format ( self . tender_id , contract [ 'id' ] ) , { #NEWLINE# #INDENT# 'data' : { #NEWLINE# #INDENT# 'dateSigned' : i [ 'complaintPeriod' ] [ 'endDate' ] , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , status = 422 ) #NEWLINE# self . assertEqual ( response . status , '422 Unprocessable Entity' ) #NEWLINE# self . assertEqual ( response . json [ 'errors' ] , [ { #NEWLINE# #INDENT# 'description' : [ 'Contract signature date should be after award complaint period end date ({})' . format ( i [ 'complaintPeriod' ] [ 'endDate' ] ) ] , #NEWLINE# 'location' : 'body' , #NEWLINE# 'name' : 'dateSigned' , #NEWLINE# #UNINDENT# } ] ) #NEWLINE# one_hour_in_furure = ( get_now ( ) + timedelta ( hours = 1 ) ) . isoformat ( ) #NEWLINE# response = self . app . patch_json ( '/tenders/{}/contracts/{}' . format ( self . tender_id , contract [ 'id' ] ) , { #NEWLINE# #INDENT# 'data' : { #NEWLINE# #INDENT# 'dateSigned' : one_hour_in_furure , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , status = 422 ) #NEWLINE# self . assertEqual ( response . status , '422 Unprocessable Entity' ) #NEWLINE# self . assertEqual ( response . json [ 'errors' ] , [ { #NEWLINE# #INDENT# 'description' : [ "Contract signature date can't be in the future" ] , #NEWLINE# 'location' : 'body' , #NEWLINE# 'name' : 'dateSigned' , #NEWLINE# #UNINDENT# } ] ) #NEWLINE# custom_signature_date = get_now ( ) . isoformat ( ) #NEWLINE# response = self . app . patch_json ( '/tenders/{}/contracts/{}' . format ( self . tender_id , contract [ 'id' ] ) , { #NEWLINE# #INDENT# 'data' : { #NEWLINE# #INDENT# 'dateSigned' : custom_signature_date , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertEqual ( response . status , '200 OK' ) #NEWLINE# response = self . app . patch_json ( '/tenders/{}/contracts/{}' . format ( self . tender_id , contract [ 'id' ] ) , { #NEWLINE# #INDENT# 'data' : { #NEWLINE# #INDENT# 'status' : 'active' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , 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 sign contract before reviewing all complaints" ) #NEWLINE# response = self . app . patch_json ( '/tenders/{}/awards/{}/complaints/{}?acc_token={}' . format ( self . tender_id , self . award_id , complaint [ 'id' ] , self . tender_token ) , { #NEWLINE# #INDENT# 'data' : { #NEWLINE# #INDENT# 'status' : 'answered' , #NEWLINE# 'resolutionType' : 'resolved' , #NEWLINE# 'resolution' : ( 'resolution text ' * 2 ) , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertEqual ( response . status , '200 OK' ) #NEWLINE# self . assertEqual ( response . content_type , 'application/json' ) #NEWLINE# self . assertEqual ( response . json [ 'data' ] [ 'status' ] , 'answered' ) #NEWLINE# self . assertEqual ( response . json [ 'data' ] [ 'resolutionType' ] , 'resolved' ) #NEWLINE# self . assertEqual ( response . json [ 'data' ] [ 'resolution' ] , ( 'resolution text ' * 2 ) ) #NEWLINE# response = self . app . patch_json ( '/tenders/{}/awards/{}/complaints/{}?acc_token={}' . format ( self . tender_id , self . award_id , complaint [ 'id' ] , owner_token ) , { #NEWLINE# #INDENT# 'data' : { #NEWLINE# #INDENT# 'satisfied' : True , #NEWLINE# 'status' : 'resolved' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertEqual ( response . status , '200 OK' ) #NEWLINE# self . assertEqual ( response . content_type , 'application/json' ) #NEWLINE# self . assertEqual ( response . json [ 'data' ] [ 'status' ] , 'resolved' ) #NEWLINE# response = self . app . patch_json ( '/tenders/{}/contracts/{}' . format ( self . tender_id , contract [ 'id' ] ) , { #NEWLINE# #INDENT# 'data' : { #NEWLINE# #INDENT# 'status' : 'active' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertEqual ( response . status , '200 OK' ) #NEWLINE# self . assertEqual ( response . content_type , 'application/json' ) #NEWLINE# self . assertEqual ( response . json [ 'data' ] [ 'status' ] , 'active' ) #NEWLINE# response = self . app . patch_json ( '/tenders/{}/contracts/{}' . format ( self . tender_id , contract [ 'id' ] ) , { #NEWLINE# #INDENT# 'data' : { #NEWLINE# #INDENT# 'value' : { #NEWLINE# #INDENT# 'amount' : 232 , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , status = 403 ) #NEWLINE# self . assertEqual ( response . status , '403 Forbidden' ) #NEWLINE# self . assertEqual ( response . json [ 'errors' ] [ 0 ] [ 'description' ] , "Can't update contract in current (complete) tender status" ) #NEWLINE# response = self . app . patch_json ( '/tenders/{}/contracts/{}' . format ( self . tender_id , contract [ 'id' ] ) , { #NEWLINE# #INDENT# 'data' : { #NEWLINE# #INDENT# 'contractID' : 'myselfID' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , status = 403 ) #NEWLINE# self . assertEqual ( response . status , '403 Forbidden' ) #NEWLINE# self . assertEqual ( response . json [ 'errors' ] [ 0 ] [ 'description' ] , "Can't update contract in current (complete) tender status" ) #NEWLINE# response = self . app . patch_json ( '/tenders/{}/contracts/{}' . format ( self . tender_id , contract [ 'id' ] ) , { #NEWLINE# #INDENT# 'data' : { #NEWLINE# #INDENT# 'items' : [ { #NEWLINE# #INDENT# 'description' : 'New Description' , #NEWLINE# #UNINDENT# } ] , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , status = 403 ) #NEWLINE# self . assertEqual ( response . status , '403 Forbidden' ) #NEWLINE# self . assertEqual ( response . json [ 'errors' ] [ 0 ] [ 'description' ] , "Can't update contract in current (complete) tender status" ) #NEWLINE# response = self . app . patch_json ( '/tenders/{}/contracts/{}' . format ( self . tender_id , contract [ 'id' ] ) , { #NEWLINE# #INDENT# 'data' : { #NEWLINE# #INDENT# 'suppliers' : [ { #NEWLINE# #INDENT# 'name' : 'New Name' , #NEWLINE# #UNINDENT# } ] , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , status = 403 ) #NEWLINE# self . assertEqual ( response . status , '403 Forbidden' ) #NEWLINE# self . assertEqual ( response . json [ 'errors' ] [ 0 ] [ 'description' ] , "Can't update contract in current (complete) tender status" ) #NEWLINE# response = self . app . patch_json ( '/tenders/{}/contracts/{}' . format ( self . tender_id , contract [ 'id' ] ) , { #NEWLINE# #INDENT# 'data' : { #NEWLINE# #INDENT# 'status' : 'active' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , 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 contract in current (complete) tender status" ) #NEWLINE# response = self . app . patch_json ( '/tenders/{}/contracts/some_id' . format ( self . tender_id ) , { #NEWLINE# #INDENT# 'data' : { #NEWLINE# #INDENT# 'status' : 'active' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , status = 404 ) #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' : 'url' , #NEWLINE# 'name' : 'contract_id' , #NEWLINE# #UNINDENT# } ] ) #NEWLINE# response = self . app . patch_json ( '/tenders/some_id/contracts/some_id' , { #NEWLINE# #INDENT# 'data' : { #NEWLINE# #INDENT# 'status' : 'active' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , status = 404 ) #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' : 'url' , #NEWLINE# 'name' : 'tender_id' , #NEWLINE# #UNINDENT# } ] ) #NEWLINE# response = self . app . get ( '/tenders/{}/contracts/{}' . format ( self . tender_id , contract [ 'id' ] ) ) #NEWLINE# self . assertEqual ( response . status , '200 OK' ) #NEWLINE# self . assertEqual ( response . content_type , 'application/json' ) #NEWLINE# self . assertEqual ( response . json [ 'data' ] [ 'status' ] , 'active' ) #NEWLINE# self . assertEqual ( response . json [ 'data' ] [ 'value' ] [ 'amount' ] , 238 ) #NEWLINE# self . assertEqual ( response . json [ 'data' ] [ 'contractID' ] , contract [ 'contractID' ] ) #NEWLINE# self . assertEqual ( response . json [ 'data' ] [ 'items' ] , contract [ 'items' ] ) #NEWLINE# self . assertEqual ( response . json [ 'data' ] [ 'suppliers' ] , contract [ 'suppliers' ] ) #NEWLINE# self . assertEqual ( response . json [ 'data' ] [ 'dateSigned' ] , custom_signature_date )