def put(self, mine_guid, mine_party_appt_guid): parser = CustomReqparser() # Arguments required by MineDocument parser.add_argument('document_name', type=str, required=True) parser.add_argument('document_manager_guid', type=str, required=True) mine_party_appt = MinePartyAppointment.find_by_mine_party_appt_guid( mine_party_appt_guid) if not mine_party_appt: raise NotFound('Mine Party Appointment.') data = parser.parse_args() document_name = data.get('document_name') document_manager_guid = data.get('document_manager_guid') # Register new file upload mine_doc = MineDocument(mine_guid=mine_guid, document_manager_guid=document_manager_guid, document_name=document_name) if not mine_doc: raise BadRequest('Unable to register uploaded file as document') mine_doc.save() mine_party_appt.documents.append(mine_doc) mine_party_appt.save() return mine_party_appt
def put(self, mine_party_appt_guid=None): if not mine_party_appt_guid: raise BadRequest('missing mine party appointment guid') data = self.parser.parse_args() mpa = MinePartyAppointment.find_by_mine_party_appt_guid( mine_party_appt_guid) if not mpa: raise NotFound('mine party appointment not found') for key, value in data.items(): if key in ['party_guid', 'mine_guid']: continue elif key == "related_guid": mpa.assign_related_guid(data.get('related_guid')) else: setattr(mpa, key, value) try: mpa.save() except alch_exceptions.IntegrityError as e: if "daterange_excl" in str(e): mpa_type_name = mpa.mine_party_appt_type.description raise BadRequest( f'Date ranges for {mpa_type_name} must not overlap.') return mpa.json()
def test_permittee_model_find_by_permit_guid(test_client, db_session, auth_headers): appt_guid = MinePartyAppointmentFactory( mine_party_appt_type_code='PMT').mine_party_appt_guid permittee = MinePartyAppointment.find_by_mine_party_appt_guid( str(appt_guid)) assert permittee.mine_party_appt_guid == appt_guid
def delete(self, mine_party_appt_guid=None): if not mine_party_appt_guid: raise BadRequest('Expected mine party appointment guid.') data = self.parser.parse_args() mpa = MinePartyAppointment.find_by_mine_party_appt_guid( mine_party_appt_guid) if not mpa: raise NotFound('Mine party appointment not found.') mpa.deleted_ind = True mpa.save() return ('', 204)
def test_post_mine_manager_happy_after(test_client, auth_headers, setup_info): test_data = { 'mine_guid': TEST_MINE_GUID, 'party_guid': TEST_PARTY_PER_GUID_1, 'mine_party_appt_type_code': "MMG", 'start_date': str(INIT_START_DATE + MM_APPT_LENGTH + timedelta(days=1)), 'end_date': str(INIT_END_DATE + MM_APPT_LENGTH + timedelta(days=1)), } post_resp = test_client.post('/parties/mines', data=test_data, headers=auth_headers['full_auth_header']) post_data = json.loads(post_resp.data.decode()) assert post_resp.status_code == 200, post_resp.response #clean-up new_mpa = MinePartyAppointment.find_by_mine_party_appt_guid( post_data["mine_party_appt_guid"]) db.session.delete(new_mpa) db.session.commit()
def get(self, mine_party_appt_guid=None): relationships = request.args.get('relationships') relationships = relationships.split(',') if relationships else [] if mine_party_appt_guid: mpa = MinePartyAppointment.find_by_mine_party_appt_guid( mine_party_appt_guid) if not mpa: raise NotFound('Mine Party Appointment not found') result = mpa.json(relationships=relationships) else: mine_guid = request.args.get('mine_guid') party_guid = request.args.get('party_guid') types = request.args.getlist('types') #list mpas = MinePartyAppointment.find_by( mine_guid=mine_guid, party_guid=party_guid, mine_party_appt_type_codes=types) result = [x.json(relationships=relationships) for x in mpas] return result
def test_permittee_model_find_by_permit_guid(test_client, auth_headers): permittee = MinePartyAppointment.find_by_mine_party_appt_guid(TEST_PERMITTEE_GUID) assert str(permittee.mine_party_appt_guid) == TEST_PERMITTEE_GUID
def test_permittee_model_find_by_permit_guid(test_client, setup_info, auth_headers): permittee = MinePartyAppointment.find_by_mine_party_appt_guid(setup_info.get('permittee_guid')) assert str(permittee.mine_party_appt_guid) == setup_info.get('permittee_guid')