def test_post_permit_amendment_with_date_params(test_client, db_session, auth_headers): permit = PermitFactory() permit_guid = permit.permit_guid #TODO Figure out how to make permit factory make it's own initial permittee permittee = MinePartyAppointmentFactory( permit_guid=permit_guid, mine_party_appt_type_code='PMT', mine=permit.mine) party_guid = PartyFactory(company=True).party_guid data = { 'permittee_party_guid': party_guid, 'received_date': datetime.today().date().isoformat(), 'issue_date': datetime.today().date().isoformat(), 'authorization_end_date': (datetime.today() + timedelta(days=1)).date().isoformat(), } post_resp = test_client.post( f'/mines/{permit.mine_guid}/permits/{permit_guid}/amendments', json=data, headers=auth_headers['full_auth_header']) post_data = json.loads(post_resp.data.decode()) assert post_resp.status_code == 200, post_resp.response #assert post_data['permit_guid'] == str(permit_guid), str(post_data) assert parser.parse(post_data['received_date']) == parser.parse(data['received_date']) assert parser.parse(post_data['issue_date']) == parser.parse(data['issue_date']) assert parser.parse(post_data['authorization_end_date']) == parser.parse( data['authorization_end_date']) assert permit.permittee_appointments[0].party_guid == party_guid #permit_amdendment is actually in db assert PermitAmendment.find_by_permit_amendment_guid(post_data['permit_amendment_guid'])
def put(self, mine_guid, permit_guid, permit_amendment_guid): permit_amendment = PermitAmendment.find_by_permit_amendment_guid( permit_amendment_guid) if not permit_amendment: raise NotFound("Permit Amendment not found.") if not str(permit_amendment.mine_guid) == mine_guid: raise BadRequest( 'Permits mine_guid and supplied mine_guid mismatch.') data = self.parser.parse_args() current_app.logger.info(f'updating {permit_amendment} with >> {data}') for key, value in data.items(): if key == 'uploadedFiles': for newFile in value: new_pa_doc = PermitAmendmentDocument( document_name=newFile['fileName'], document_manager_guid=newFile['document_manager_guid'], mine_guid=permit_amendment.mine_guid, ) permit_amendment.related_documents.append(new_pa_doc) else: setattr(permit_amendment, key, value) permit_amendment.save() return permit_amendment
def put(self, mine_guid, permit_amendment_guid, permit_guid): permit_amendment = PermitAmendment.find_by_permit_amendment_guid( permit_amendment_guid) if not permit_amendment: raise NotFound('Permit amendment not found.') if not str(permit_amendment.permit_guid) == permit_guid: raise BadRequest('Amendment and permit permit_guid mismatch.') if not str(permit_amendment.mine_guid) == mine_guid: raise BadRequest( 'Permits mine_guid and supplied mine_guid mismatch.') data = self.parser.parse_args() if data.get('document_manager_guid'): # Register and associate a new file upload filename = data.get('filename') if not filename: raise BadRequest('Must supply filename for new file upload.') new_pa_doc = PermitAmendmentDocument( mine_guid=permit_amendment.permit.mine_guid, document_manager_guid=data.get('document_manager_guid'), document_name=filename) permit_amendment.related_documents.append(new_pa_doc) permit_amendment.save() else: raise BadRequest( 'Must provide the doc manager guid for the newly uploaded file.' ) return new_pa_doc
def get(self, mine_guid, permit_guid, permit_amendment_guid): permit_amendment = PermitAmendment.find_by_permit_amendment_guid(permit_amendment_guid) if not permit_amendment: raise NotFound("Permit Amendment not found.") if not str(permit_amendment.mine_guid) == mine_guid: raise BadRequest('Permits mine_guid and supplied mine_guid mismatch.') return permit_amendment
def test_delete_permit_amendment(test_client, db_session, auth_headers): permit_amendment = PermitAmendmentFactory() del_resp = test_client.delete( f'/mines/{permit_amendment.mine_guid}/permits/{permit_amendment.permit_guid}/amendments/{permit_amendment.permit_amendment_guid}', headers=auth_headers['full_auth_header']) assert del_resp.status_code == 200, del_resp assert PermitAmendment.find_by_permit_amendment_guid( str(permit_amendment.permit_amendment_guid)) is None
def delete(self, mine_guid, permit_guid, permit_amendment_guid): permit_amendment = PermitAmendment.find_by_permit_amendment_guid( permit_amendment_guid) if not permit_amendment: raise NotFound("Permit Amendment not found.") if not str(permit_amendment.mine_guid) == mine_guid: raise BadRequest( 'Permits mine_guid and supplied mine_guid mismatch.') permit_amendment.deleted_ind = True permit_amendment.save() return
def delete(self, mine_guid, permit_guid, permit_amendment_guid): permit_amendment = PermitAmendment.find_by_permit_amendment_guid(permit_amendment_guid) if not permit_amendment: raise NotFound("Permit Amendment not found.") if not str(permit_amendment.mine_guid) == mine_guid: raise BadRequest('Permits mine_guid and supplied mine_guid mismatch.') try: permit_amendment.soft_delete() except Exception as e: raise BadRequest(e) return
def test_post_permit_amendment_with_type_params(test_client, db_session, auth_headers): permit_guid = PermitFactory().permit_guid data = {'permit_amendment_type_code': 'OGP'} post_resp = test_client.post( f'/permits/{permit_guid}/amendments', json=data, headers=auth_headers['full_auth_header']) post_data = json.loads(post_resp.data.decode()) assert post_resp.status_code == 200, post_resp.response #assert post_data['permit_guid'] == str(permit_guid), str(post_data) assert post_data['permit_amendment_type_code'] == "OGP" assert post_data['permit_amendment_status_code'] == "ACT" #permit_amdendment is actually in db assert PermitAmendment.find_by_permit_amendment_guid(post_data['permit_amendment_guid'])
def test_post_permit_amendment_no_params(test_client, db_session, auth_headers): permit = PermitFactory() permit_guid = permit.permit_guid post_resp = test_client.post( f'/mines/{permit.mine_guid}/permits/{permit_guid}/amendments', headers=auth_headers['full_auth_header']) post_data = json.loads(post_resp.data.decode()) assert post_resp.status_code == 200, post_resp.response #assert post_data['permit_guid'] == str(permit_guid), str(post_data) assert post_data['received_date'] is None assert post_data['issue_date'] is None assert post_data['authorization_end_date'] is None #permit_amdendment is actually in db assert PermitAmendment.find_by_permit_amendment_guid(post_data['permit_amendment_guid'])
def delete(self, mine_guid, permit_guid, permit_amendment_guid, permit_amendment_document_guid): permit_amendment = PermitAmendment.find_by_permit_amendment_guid( permit_amendment_guid) permit_amendment_doc = PermitAmendmentDocument.find_by_permit_amendment_document_guid( permit_amendment_document_guid) if permit_amendment is None: raise NotFound('The permit amendment was not found.') if permit_amendment_doc is None: raise NotFound('The amendments attached document was not found.') if not str(permit_amendment.permit_guid) == permit_guid: raise BadRequest('Amendment and permit permit_guid mismatch.') if not str(permit_amendment.mine_guid) == mine_guid: raise BadRequest( 'Permits mine_guid and supplied mine_guid mismatch.') permit_amendment.related_documents.remove(permit_amendment_doc) permit_amendment.save() return
def test_post_permit_amendment_with_date_params(test_client, db_session, auth_headers): permit = PermitFactory() permit_guid = permit.permit_guid party_guid = PartyFactory(company=True).party_guid data = { 'permittee_party_guid': party_guid, 'received_date': datetime.today().strftime('%Y-%m-%d'), 'issue_date': datetime.today().strftime('%Y-%m-%d'), 'authorization_end_date': (datetime.today() + timedelta(days=1)).strftime('%Y-%m-%d') } post_resp = test_client.post( f'/mines/{permit.mine_guid}/permits/{permit_guid}/amendments', json=data, headers=auth_headers['full_auth_header']) post_data = json.loads(post_resp.data.decode()) permittees = MinePartyAppointment.find_by_permit_guid(permit_guid) assert post_resp.status_code == 200, post_resp.response assert post_data['permit_guid'] == str(permit_guid), str(post_data) assert post_data['received_date'] == data['received_date'] assert post_data['issue_date'] == data['issue_date'] assert post_data['authorization_end_date'] == data[ 'authorization_end_date'] assert permittees[0].party_guid == party_guid #permit_amdendment is actually in db assert PermitAmendment.find_by_permit_amendment_guid( post_data['permit_amendment_guid'])