def test_get_contracts(self): # This test relies on delayed indexation after 1st GET request to the DB, # so if it falls - try to increase sleep time. # P.S. I didn't use docstring to not override nosetest's output with it self.app.authorization = ('Basic', ('contracting', '')) contract = create_contract(self) contract_id_1 = contract.data.id contract = create_contract(self) contract_id_2 = contract.data.id self.app.get(ENDPOINTS['contracts_collection']) time.sleep(0.2) # wait for delayed indexation of listing, seconds response = self.app.get(ENDPOINTS['contracts_collection']) keys_returned = [result['id'] for result in response.json['data']] assert contract_id_1 in keys_returned assert contract_id_2 in keys_returned
def test_patch_contract_status_active_payment(self): contract = create_contract(self) response = patch_contract( self, contract, {'data': { 'status': 'active.payment' }}, ) self.assertEqual(response.status, '200 OK') response_data = response.json['data'] self.assertEqual(response_data['status'], 'active.payment') self.assertTrue(isinstance(response_data.get('milestones'), list), "Milestones weren't created") financial_milestone = response_data['milestones'][0] contract = Contract(contract_create_data) target_dueDate = calculate_business_date( contract.dateSigned, MILESTONE_FINANCING_DUEDATE_OFFSET, context=None, working_days=False, specific_hour=18, result_is_working_day=True) self.assertEqual( financial_milestone['dueDate'], target_dueDate.isoformat(), "dueDate of financial milestone wasn't calculated right")
def test_patch_internal_type(self): contract = create_contract(self) # set allowed status response = patch_contract(self, contract, {'data': { '_internal_type': 'lucy_lu' }}, status=422) self.assertEqual(response.status, '422 Unprocessable Entity')
def test_post_ok(self): contract = create_contract(self) contract_id = contract.data.id contract_before_document_post = get_contract(self, contract_id) assert contract_before_document_post.documents == [] response = post_document(self, contract) assert response.status == '201 Created' contract_after_document_post = get_contract(self, contract_id) assert len(contract_after_document_post.documents) == 1
def test_get_contract(self): contract = create_contract(self) contract_id = contract.data.id self.app.authorization = ('Basic', ('broker1', '')) response = self.app.get( ENDPOINTS['contracts'].format(contract_id=contract_id)) assert response.status == '200 OK' response_data_keys = response.json['data'].keys() assert '_internal_type' not in response_data_keys assert 'period' not in response_data_keys assert 'terminationDetails' not in response_data_keys assert 'dateModified' in response_data_keys
def test_patch_response_have_not_excessive_fields(self): contract = create_contract(self) response = patch_contract( self, contract, {'data': { 'status': 'active.payment' }}, ) self.assertEqual(response.status, '200 OK') response_data_keys = response.json['data'].keys() self.check_forbidden_contract_fields(response_data_keys)
def test_patch_contract_forbidden_status(self): contract = create_contract(self) # set allowed status patch_contract( self, contract, {'data': { 'status': 'active.payment' }}, ) patch_contract(self, contract, {'data': { 'status': 'active.approval' }}, status=403)
def test_post_with_wrong_user(self): contract = create_contract(self) self.app.authorization = ('Basic', ('petro', '')) post_document(self, contract, status_code=403)
def test_milestone_post(self): contract = create_contract(self) self.app.post_json(ENDPOINTS['milestones_collection'].format( contract_id=contract.data.id), status=404)