def post(self, mine_guid): data = self.parser.parse_args() mine = Mine.find_by_mine_guid(mine_guid) if not mine: raise NotFound( 'There was no mine found with the provided mine_guid.') party = Party.find_by_party_guid(data.get('permittee_party_guid')) if not party: raise NotFound('Party not found') permit = Permit.find_by_permit_no(data.get('permit_no')) if permit: raise BadRequest("That permit number is already in use.") uploadedFiles = data.get('uploadedFiles', []) permit = Permit.create(mine.mine_guid, data.get('permit_no'), data.get('permit_status_code')) amendment = PermitAmendment.create( permit, data.get('received_date'), data.get('issue_date'), data.get('authorization_end_date'), 'OGP', description='Initial permit issued.') db.session.add(permit) db.session.add(amendment) for newFile in uploadedFiles: new_pa_doc = PermitAmendmentDocument( document_name=newFile['fileName'], document_manager_guid=newFile['document_manager_guid'], mine_guid=permit.mine_guid, ) amendment.related_documents.append(new_pa_doc) db.session.commit() permittee = MinePartyAppointment.create( mine.mine_guid, data.get('permittee_party_guid'), 'PMT', datetime.utcnow(), None, self.get_user_info(), permit.permit_guid, True) db.session.commit() return permit
def put(self, mine_no_or_guid): mine = Mine.find_by_mine_no_or_guid(mine_no_or_guid) refresh_cache = False if not mine: raise NotFound("Mine not found.") data = self.parser.parse_args() lat = data.get('latitude') lon = data.get('longitude') if (lat and not lon) or (not lat and lon): raise BadRequest( 'latitude and longitude must both be empty, or both provided') # Mine Detail if 'mine_name' in data and mine.mine_name != data['mine_name']: _throw_error_if_mine_exists(data['mine_name']) mine.mine_name = data['mine_name'] refresh_cache = True if 'mine_note' in data: mine.mine_note = data['mine_note'] if 'major_mine_ind' in data: mine.major_mine_ind = data['major_mine_ind'] if 'mine_region' in data: mine.mine_region = data['mine_region'] if 'ohsc_ind' in data: mine.ohsc_ind = data['ohsc_ind'] if 'union_ind' in data: mine.union_ind = data['union_ind'] if 'latitude' in data and 'longitude' in data: mine.latitude = data['latitude'] mine.longitude = data['longitude'] refresh_cache = True if 'exemption_fee_status_code' in data: mine.exemption_fee_status_code = data['exemption_fee_status_code'] if 'exemption_fee_status_code' in data: mine.exemption_fee_status_note = data['exemption_fee_status_note'] mine.save() _mine_status_processor(data.get('mine_status'), data.get('status_date'), mine) # refresh cache will need to be called for all supported fields, should more be added in the future if refresh_cache: cache.delete(MINE_MAP_CACHE) MineMapResource.rebuild_map_cache_async() return mine
def test_post_mine_report_comment(test_client, db_session, auth_headers): mine = MineFactory() num_comments = len(mine.comments) data = {'mine_comment': 'Test comment'} post_resp = test_client.post(f'/mines/{mine.mine_guid}/comments', headers=auth_headers['full_auth_header'], json=data) updated_mine = Mine.find_by_mine_guid(str(mine.mine_guid)) comments = updated_mine.comments assert post_resp.status_code == 201 assert len(comments) == num_comments + 1 assert comments[-1].mine_comment == 'Test comment'
def post(self, application_guid): data = self.parser.parse_args() mine_guid = data.get('mine_guid') mine = Mine.find_by_mine_guid(mine_guid) if not mine: raise NotFound('Mine not found') now_application_identity = NOWApplicationIdentity.query.filter_by( now_application_guid=application_guid).first() if not now_application_identity: raise NotFound('No identity record for this application guid.') application = transmogrify_now(now_application_identity) application.mine_guid = mine_guid application.now_application_guid = application_guid application.save() return {'now_application_guid': str(application.now_application_guid)}
def get(self): result = "" now_info = "" response_message = "" try: mine_no = request.args.get('a_MineNumber') mine = Mine.find_by_mine_no(mine_no) # Mine must be operating. if mine.mine_status or mine.mine_status[ 0].mine_status_xref.mine_operation_status_code != "OP": permits = Permit.find_by_mine_guid(mine.mine_guid) for permit in permits: for permit_amendment in permit.permit_amendments: if permit_amendment.now_identity: now_info = now_info + str( permit_amendment.now_identity.now_number ) + " - " + str( permit_amendment.authorization_end_date) + '\r' else: now_info = now_info + " - " + str( permit_amendment.authorization_end_date) + '\r' break if now_info != "": result = "Success" else: result = "Failure" response_message = "NoValidNowsForMine" except Exception as e: current_app.logger.error(str(e)) result = "Failure" now_info = "" response_message = "Unhandled Exception" return { "a_Result": result, "a_NoWInfo": now_info, "a_ResponseMessage": response_message, "a_Timestamp": datetime.utcnow() }
def get(self): mine_guid = request.args.get('mine_guid', None) if mine_guid is None: raise BadRequest('Please provide a mine_guid.') mine = Mine.find_by_mine_guid(mine_guid) if mine is None: return [] permits = Permit.find_by_mine_guid(mine.mine_guid) if not permits: return [] bonds = [bond for permit in permits for bond in permit.bonds] return bonds
def put(self, mine_guid, mine_incident_guid, mine_document_guid): parser = CustomReqparser() parser.add_argument('filename', type=str, required=True) parser.add_argument('document_manager_guid', type=str, required=True) parser.add_argument('mine_incident_document_type', type=str, required=True) mine_incident = MineIncident.find_by_mine_incident_guid( mine_incident_guid) mine = Mine.find_by_mine_guid(mine_guid) if not mine_incident: raise NotFound('Mine incident not found') if not mine: raise NotFound('Mine not found.') data = parser.parse_args() document_manager_guid = data.get('document_manager_guid') file_name = data.get('filename') mine_incident_document_type = data.get('mine_incident_document_type') mine_doc = MineDocument(mine_guid=mine.mine_guid, document_name=file_name, document_manager_guid=document_manager_guid) if not mine_doc: raise BadRequest('Unable to register uploaded file as document') mine_doc.save() mine_incident_doc = MineIncidentDocumentXref( mine_document_guid=mine_doc.mine_document_guid, mine_incident_id=mine_incident.mine_incident_id, mine_incident_document_type_code=mine_incident_document_type if mine_incident_document_type else 'INI') mine_incident.documents.append(mine_incident_doc) mine_incident.save() return mine_incident
def post(self, mine_guid): mine = Mine.find_by_mine_guid(mine_guid) if not mine: raise NotFound('Mine not found') data = self.parser.parse_args() if not data['mine_comment']: raise BadRequest('Empty comment') mine_comment = MineComment.create( mine=mine, mine_comment=data['mine_comment'], ) current_app.logger.info(f'Creating comment {mine_comment}') mine_comment.save() return mine_comment, 201
def get(self, mine_no): mine = Mine.find_by_mine_no_or_guid(mine_no) if not mine: raise NotFound("No mine record in CORE.") result = cache.get(NRIS_COMPLIANCE_DATA(mine.mine_no)) if result is None: try: raw_data = NRIS_API_service._get_NRIS_data_by_mine( request.headers.get('Authorization'), mine.mine_no) except requests.exceptions.Timeout: current_app.logger.error(f'NRIS_API Connection Timeout <mine_no={mine.mine_no}>') raise except requests.exceptions.HTTPError as e: current_app.logger.error( f'NRIS_API Connection HTTPError <mine_no={mine.mine_no}>, {str(e)}') raise result = NRIS_API_service._process_NRIS_data(raw_data) if len(result['orders']) > 0: cache.set(NRIS_COMPLIANCE_DATA(mine.mine_no), result, timeout=TIMEOUT_60_MINUTES) return result
def post(self): data = self.parser.parse_args() mine = Mine.find_by_mine_guid(data['mine_guid']) permit = Permit.find_by_permit_guid(data['permit_guid']) err_str = '' if not mine: err_str += 'Mine not Found. ' if not permit: err_str += 'Permit not Found. ' if mine and not mine.major_mine_ind: err_str += 'Permit Applications can only be created on mines where major_mine_ind=True' if err_str: raise BadRequest(err_str) new_now = NOWApplicationIdentity(mine_guid=data['mine_guid'], permit=permit) new_now.now_application = NOWApplication( notice_of_work_type_code=data['notice_of_work_type_code'], now_application_status_code='REC', submitted_date=data['submitted_date'], received_date=data['received_date']) new_now.save() return new_now, 201
def get(self): mine_guid = request.args.get('mine_guid', None) if mine_guid is None: raise BadRequest('Please provide a mine_guid.') mine = Mine.find_by_mine_guid(mine_guid) if mine is None: return [] permits = Permit.find_by_mine_guid(mine.mine_guid) if not permits: return [] reclamation_invoices = [ reclamation_invoice for permit in permits for reclamation_invoice in permit.reclamation_invoices ] return reclamation_invoices
def post(self, mine_guid): data = self.parser.parse_args() compliance_article_id = data['compliance_article_id'] received_date = data['received_date'] inspector_party_guid = data.get('inspector_party_guid') mine = Mine.find_by_mine_guid(mine_guid) if mine is None: raise NotFound('Mine') # A manual check to prevent a stack trace dump on a foreign key / # constraint error because global error handling doesn't currently work # with these errors variance_application_status_code = data.get('variance_application_status_code') or 'REV' issue_date = data.get('issue_date') expiry_date = data.get('expiry_date') Variance.validate_status_with_other_values(status=variance_application_status_code, issue=issue_date, expiry=expiry_date, inspector=inspector_party_guid) variance = Variance.create( compliance_article_id=compliance_article_id, mine_guid=mine_guid, received_date=received_date, # Optional fields variance_application_status_code=variance_application_status_code, applicant_guid=data.get('applicant_guid'), inspector_party_guid=inspector_party_guid, note=data.get('note'), parties_notified_ind=data.get('parties_notified_ind'), issue_date=issue_date, expiry_date=expiry_date) if not variance: raise BadRequest('Error: Failed to create variance') variance.save() return variance
def post(self, mine_guid): mine = Mine.find_by_mine_guid(mine_guid) if not mine: raise NotFound('Mine not found.') data = self.parser.parse_args() mine_tsf_list = mine.mine_tailings_storage_facilities is_mine_first_tsf = len(mine_tsf_list) == 0 mine_tsf = MineTailingsStorageFacility.create( mine, mine_tailings_storage_facility_name=data[ 'mine_tailings_storage_facility_name']) mine.mine_tailings_storage_facilities.append(mine_tsf) if is_mine_first_tsf: try: tsf_required_reports = MineReportDefinition.find_required_reports_by_category( 'TSF') for tsf_req_doc in tsf_required_reports: calculated_due_date = tsf_req_doc.default_due_date or datetime.utcnow( ) MineReport.create( mine_report_definition_id=tsf_req_doc. mine_report_definition_id, mine_guid=mine.mine_guid, due_date=calculated_due_date, received_date=None, submission_year=calculated_due_date.year - 1, permit_id=None) except Exception as e: db.session.rollback() current_app.logger.error(str(e)) raise InternalServerError(str(e) + ", tsf not created") mine.save() return mine_tsf, 201
def put(self, application_guid): now_application_identity = NOWApplicationIdentity.find_by_guid( application_guid) if not now_application_identity: raise NotFound('No identity record for this application guid.') if now_application_identity.now_application_id is None: raise NotImplemented( 'This application has not been imported. Please import an application before making changes.' ) data = request.json lead_inspector_party_guid = data.get('lead_inspector_party_guid', None) if lead_inspector_party_guid is not None: now_application_identity.now_application.lead_inspector_party_guid = lead_inspector_party_guid now_application_status_code = data.get('now_application_status_code', None) if now_application_status_code is not None and now_application_identity.now_application.now_application_status_code != now_application_status_code: now_application_identity.now_application.status_updated_date = datetime.today( ) if data.get('mine_guid', None): mine = Mine.find_by_mine_guid(data['mine_guid']) if not mine: raise BadRequest('mine not found') current_app.logger.info( f'Assigning {now_application_identity} to {mine}') now_application_identity.mine = mine now_application_identity.save() now_application_identity.now_application.deep_update_from_dict(data) NROSNOWStatusService.nros_now_status_update( now_application_identity.now_number, now_application_identity.now_application.status.description, now_application_identity.now_application.status_updated_date. strftime("%Y-%m-%dT%H:%M:%S")) return now_application_identity.now_application
def post(self, mine_guid): mine = Mine.find_by_mine_guid(mine_guid) if not mine: raise NotFound('Mine not found') data = self.parser.parse_args() do_sub_codes = [] if data['determination_type_code'] == 'DO': do_sub_codes = data['dangerous_occurrence_subparagraph_ids'] if not do_sub_codes: raise BadRequest( 'Dangerous occurrences require one or more cited sections of HSRC code 1.7.3') incident = MineIncident.create( mine, data['incident_timestamp'], data['incident_description'], determination_type_code=data['determination_type_code'] or 'PEN', followup_type_code=data['followup_type_code'] or 'UND', followup_inspection_no=data['followup_inspection_no'], reported_timestamp=data['reported_timestamp'], reported_by=data['reported_by'], reported_by_role=data['reported_by_role'], ) for id in do_sub_codes: sub = ComplianceArticle.find_by_compliance_article_id(id) if not _compliance_article_is_do_subparagraph(sub): raise BadRequest( 'One of the provided compliance articles is not a sub-paragraph of section 1.7.3 (dangerous occurrences)' ) incident.dangerous_occurrence_subparagraphs.append(sub) try: incident.save() except Exception as e: raise InternalServerError(f'Error when saving: {e}') return incident, 201
def get(self): mine_guid = request.args.get('mine_guid', None) if mine_guid is None: raise BadRequest('Please provide a mine_guid.') mine = Mine.find_by_mine_guid(mine_guid) if mine is None: return [] permits = Permit.find_by_mine_guid(mine.mine_guid) if not permits: return [] bonds = [bond for permit in permits for bond in permit.bonds] if jwt.validate_roles([MINESPACE_PROPONENT]): bonds = marshal(bonds, BOND_MINESPACE) return bonds
def post(self): try: application_nda = ApplicationNDA._schema().load(request.json) except MarshmallowError as e: raise BadRequest(e) if application_nda.application_nda_guid is not None: raise BadRequest( f'messageid: {application_nda.messageid} already exists.') if application_nda.applicant.clientid == application_nda.submitter.clientid: application_nda.submitter = application_nda.applicant mine = Mine.find_by_mine_no(application_nda.minenumber) if mine is None: raise BadRequest('Mine not found from the minenumber supplied.') application_nda.mine_guid = mine.mine_guid application_nda.nownumber = NOWApplicationIdentity.create_now_number( mine) application_nda.save() return application_nda, 201
def test_post_mine_report(test_client, db_session, auth_headers): mine = MineFactory(mine_reports=ONE_REPORT) mine_report = mine.mine_reports[0] mine_report_definition = MineReportDefinition.active() num_reports = len(mine.mine_reports) new_report_definition = [ x for x in mine_report_definition if x.mine_report_definition_guid != mine_report.mine_report_definition_guid ][0] data = { 'mine_report_definition_guid': str(new_report_definition.mine_report_definition_guid), 'submission_year': '2019', 'due_date': '2019-07-05', 'permit_guid': None, 'received_date': None, } post_resp = test_client.post(f'/mines/{mine.mine_guid}/reports', headers=auth_headers['full_auth_header'], json=data) post_data = json.loads(post_resp.data.decode()) updated_mine = Mine.find_by_mine_guid(str(mine.mine_guid)) reports = updated_mine.mine_reports assert post_resp.status_code == 201 assert len(reports) == num_reports + 1 assert new_report_definition.mine_report_definition_id in [ x.mine_report_definition_id for x in reports ]
def test_mine_model_find_by_mine_guid_fail(db_session): init_mine = MineFactory() mine = Mine.find_by_mine_guid('jflkjfsdl') assert mine is None
def get(self, mine_guid): mine = Mine.find_by_mine_guid(mine_guid) if not mine: raise NotFound('Mine not found.') return mine.mine_tailings_storage_facilities
def post(self, mine_guid): mine = Mine.find_by_mine_guid(mine_guid) if not mine: raise NotFound('Mine not found') data = self.parser.parse_args() do_sub_codes = [] if data['determination_type_code'] == 'DO': do_sub_codes = data['dangerous_occurrence_subparagraph_ids'] if not do_sub_codes: raise BadRequest( 'Dangerous occurrences require one or more cited sections of HSRC code 1.7.3' ) incident = MineIncident.create( mine, data['incident_timestamp'], data['incident_description'], determination_type_code=data['determination_type_code'], mine_determination_type_code=data['mine_determination_type_code'], mine_determination_representative=data[ 'mine_determination_representative'], followup_investigation_type_code=data[ 'followup_investigation_type_code'], reported_timestamp=data['reported_timestamp'], reported_by_name=data['reported_by_name'], ) incident.reported_by_email = data.get('reported_by_email') incident.reported_by_phone_no = data.get('reported_by_phone_no') incident.reported_by_phone_ext = data.get('reported_by_phone_ext') incident.number_of_fatalities = data.get('number_of_fatalities') incident.number_of_injuries = data.get('number_of_injuries') incident.emergency_services_called = data.get( 'emergency_services_called') incident.followup_inspection = data.get('followup_inspection') incident.followup_inspection_date = data.get( 'followup_inspection_date') incident.status_code = data.get('status_code') incident.proponent_incident_no = data.get('proponent_incident_no') # lookup and validated inspector party relationships tmp_party = Party.query.filter_by( party_guid=data.get('reported_to_inspector_party_guid')).first() if tmp_party and 'INS' in tmp_party.business_roles_codes: incident.reported_to_inspector_party_guid = tmp_party.party_guid tmp_party = Party.query.filter_by( party_guid=data.get('responsible_inspector_party_guid')).first() if tmp_party and 'INS' in tmp_party.business_roles_codes: incident.responsible_inspector_party_guid = tmp_party.party_guid tmp_party = Party.query.filter_by( party_guid=data.get('determination_inspector_party_guid')).first() if tmp_party and 'INS' in tmp_party.business_roles_codes: incident.determination_inspector_party_guid = tmp_party.party_guid incident.determination_type_code = data.get('determination_type_code') incident.followup_investigation_type_code = data.get( 'followup_investigation_type_code') for id in do_sub_codes: sub = ComplianceArticle.find_by_compliance_article_id(id) if not _compliance_article_is_do_subparagraph(sub): raise BadRequest( 'One of the provided compliance articles is not a sub-paragraph of section 1.7.3 (dangerous occurrences)' ) incident.dangerous_occurrence_subparagraphs.append(sub) updated_documents = data.get('updated_documents') if updated_documents is not None: for updated_file in updated_documents: mine_doc = MineDocument( mine_guid=mine.mine_guid, document_name=updated_file['document_name'], document_manager_guid=updated_file['document_manager_guid'] ) if not mine_doc: raise BadRequest( 'Unable to register uploaded file as document') mine_doc.save() mine_incident_doc = MineIncidentDocumentXref( mine_document_guid=mine_doc.mine_document_guid, mine_incident_id=incident.mine_incident_id, mine_incident_document_type_code=updated_file[ 'mine_incident_document_type_code'] if updated_file['mine_incident_document_type_code'] else 'INI') incident.documents.append(mine_incident_doc) try: incident.save() except Exception as e: raise InternalServerError(f'Error when saving: {e}') recommendations = data.get('recommendations') if recommendations is not None: for recommendation in recommendations: rec_string = recommendation.get('recommendation') if rec_string is None: continue new_recommendation = MineIncidentRecommendation.create( rec_string, mine_incident_id=incident.mine_incident_id) new_recommendation.save() return incident, 201
def generate_mine_no(): mine_no = random_key_gen(prefix='B', key_length=6, letters=False) while Mine.find_by_mine_no(mine_no): mine_no = random_key_gen(prefix='B', key_length=6, letters=False) return mine_no
def test_mine_model_find_by_mine_guid_fail(test_client, auth_headers): mine = Mine.find_by_mine_guid('jflkjfsdl') assert mine is None
def get(self, mine_guid): mine = Mine.find_by_mine_guid(mine_guid) if not mine: raise NotFound("Mine not found") return mine.mine_incidents
def test_mine_model_find_by_mine_no(test_client, auth_headers): mine = Mine.find_by_mine_no(TEST_MINE_NO) assert str(mine.mine_no) == TEST_MINE_NO
def test_mine_model_find_by_mine_guid(test_client, auth_headers): mine = Mine.find_by_mine_guid(TEST_MINE_GUID) assert str(mine.mine_guid) == TEST_MINE_GUID
def test_mine_model_find_by_mine_no(db_session): init_mine_no = MineFactory().mine_no mine = Mine.find_by_mine_no(init_mine_no) assert mine.mine_no == init_mine_no
def test_mine_model_find_by_mine_guid(db_session): init_mine_guid = MineFactory().mine_guid mine = Mine.find_by_mine_guid(str(init_mine_guid)) assert mine.mine_guid == init_mine_guid
def put(self, mine_guid, mine_report_guid): mine = Mine.find_by_mine_guid(mine_guid) mine_report = MineReport.find_by_mine_report_guid(mine_report_guid) if not mine_report or str(mine_report.mine_guid) != mine_guid: raise NotFound("Mine Report not found") data = self.parser.parse_args() if 'due_date' in data: mine_report.due_date = data.get('due_date') if 'received_date' in data: mine_report.received_date = data['received_date'] if 'submission_year' in data: mine_report.submission_year = data['submission_year'] if data.get('mine_report_submission_status') is not None: mine_report_submission_status = data.get( 'mine_report_submission_status') else: mine_report_submission_status = 'NRQ' report_submissions = data.get('mine_report_submissions') submission_iterator = iter(report_submissions) new_submission = next( (x for x in submission_iterator if x.get('mine_report_submission_guid') is None), None) if new_submission is not None: new_report_submission = MineReportSubmission( submission_date=datetime.now(), mine_report_submission_status_code=mine_report_submission_status ) # Copy the current list of documents for the report submission last_submission_docs = mine_report.mine_report_submissions[ -1].documents.copy() if len( mine_report.mine_report_submissions) > 0 else [] # Gets the difference between the set of documents in the new submission and the last submission new_docs = [ x for x in new_submission.get('documents') if not any( str(doc.document_manager_guid) == x['document_manager_guid'] for doc in last_submission_docs) ] # Get the documents that were on the last submission but not part of the new submission removed_docs = [ x for x in last_submission_docs if not any(doc['document_manager_guid'] == str( x.document_manager_guid) for doc in new_submission.get('documents')) ] # Remove the deleted documents from the existing set. for doc in removed_docs: last_submission_docs.remove(doc) if len(last_submission_docs) > 0: new_report_submission.documents.extend(last_submission_docs) for doc in new_docs: mine_doc = MineDocument( mine_guid=mine.mine_guid, document_name=doc['document_name'], document_manager_guid=doc['document_manager_guid']) if not mine_doc: raise BadRequest( 'Unable to register uploaded file as document') mine_doc.save() new_report_submission.documents.append(mine_doc) mine_report.mine_report_submissions.append(new_report_submission) # if the status has changed, update the status of the last submission elif ( len(mine_report.mine_report_submissions) > 0 ) and mine_report_submission_status != mine_report.mine_report_submissions[ -1].mine_report_submission_status_code: mine_report.mine_report_submissions[ -1].mine_report_submission_status_code = mine_report_submission_status try: mine_report.save() except Exception as e: raise InternalServerError(f'Error when saving: {e}') return mine_report
def setup_data(session): # Clear data clear_data(session) # Insert Region Code for region_code_value, display_order_value in zip( TEST_REGION_CODES, TEST_REGION_CODE_DISPLAY_ORDER): region_code = MineRegionCode(mine_region_code=region_code_value, description=TEST_REGION_DESCRIPTION, display_order=display_order_value, **DUMMY_USER_KWARGS) region_code.save() # Insert Mine Tenure Types for code, description in zip(TEST_MINE_TENURE_TYPE_CODES, TEST_MINE_TENURE_TYPE_DESCRIPTIONS): mine_tenure_type_code = MineTenureTypeCode(mine_tenure_type_code=code, description=description, **DUMMY_USER_KWARGS) mine_tenure_type_code.save() # Insert Mine Disturbance Codes for code, description in zip(TEST_MINE_DISTURBANCE_CODES, TEST_MINE_DISTURBANCE_DESCRIPTIONS): mine_disturbance_code = MineDisturbanceCode(mine_disturbance_code=code, description=description, **DUMMY_USER_KWARGS) mine_disturbance_code.save() # Insert Mine Commodity Codes for code, description in zip(TEST_MINE_COMMODITY_CODES, TEST_MINE_COMMODITY_DESCRIPTIONS): mine_commodity_code = MineCommodityCode(mine_commodity_code=code, description=description, **DUMMY_USER_KWARGS) mine_commodity_code.save() # Test Mine Data mine = Mine(mine_guid=uuid.UUID(TEST_MINE_GUID), mine_no=TEST_MINE_NO, mine_name=TEST_MINE_NAME, mine_region=TEST_REGION_CODE, **DUMMY_USER_KWARGS) mine.save() # Test Mine Type mine_type = MineType(mine_type_guid=uuid.UUID(TEST_MINE_TYPE_GUID), mine_guid=uuid.UUID(TEST_MINE_GUID), mine_tenure_type_code=TEST_MINE_TENURE_TYPE_CODES[0], active_ind=True, **DUMMY_USER_KWARGS) mine_type.save() # Test Mine Type Detail mine_type_detail = MineTypeDetail( mine_type_detail_xref_guid=uuid.UUID(TEST_MINE_TYPE_DETAIL_GUID), mine_type_guid=uuid.UUID(TEST_MINE_TYPE_GUID), mine_disturbance_code=TEST_MINE_DISTURBANCE_CODES[0], active_ind=True, **DUMMY_USER_KWARGS) mine_type_detail.save() # Test Tenure Data tenure = MineralTenureXref( mineral_tenure_xref_guid=uuid.UUID(TEST_TENURE_GUID), mine_guid=uuid.UUID(TEST_MINE_GUID), tenure_number_id=TEST_TENURE_ID, **DUMMY_USER_KWARGS) tenure.save() # Test Location Data mine_location = MineLocation( mine_location_guid=uuid.UUID(TEST_LOCATION_GUID), mine_guid=uuid.UUID(TEST_MINE_GUID), latitude=TEST_LAT_1, longitude=TEST_LONG_1, effective_date=datetime.today(), expiry_date=datetime.today(), **DUMMY_USER_KWARGS) mine_location.save() # Test Person Type Codes for k, v in PARTY_STATUS_CODE.items(): party_code = PartyTypeCode(party_type_code=v, description=v, **DUMMY_USER_KWARGS) party_code.save() session.commit() # Test Party Region Codes for code, description in zip(TEST_SUB_DIVISION_CODES, TEST_SUB_DIVISION_CODE_DESCRIPTIONS): sub_division_code = SubDivisionCode(sub_division_code=code, description=description, **DUMMY_USER_KWARGS) sub_division_code.save() # Test Operation Codes for k, v in MINE_OPERATION_STATUS.items(): mine_operation_status_code = MineOperationStatusCode( mine_operation_status_code=v['value'], description=v['label'], **DUMMY_USER_KWARGS) mine_operation_status_code.save() for k, v in MINE_OPERATION_STATUS_REASON.items(): mine_operation_status_reason_code = MineOperationStatusReasonCode( mine_operation_status_reason_code=v['value'], description=v['label'], **DUMMY_USER_KWARGS) mine_operation_status_reason_code.save() for k, v in MINE_OPERATION_STATUS_SUB_REASON.items(): mine_operation_status_sub_reason_code = MineOperationStatusSubReasonCode( mine_operation_status_sub_reason_code=v['value'], description=v['label'], **DUMMY_USER_KWARGS) mine_operation_status_sub_reason_code.save() session.commit() # Insert Operation Code Xref for status_k, status_v in MINE_OPERATION_STATUS.items(): for reason_k, reason_v in MINE_OPERATION_STATUS_REASON.items(): for sub_k, sub_v in MINE_OPERATION_STATUS_SUB_REASON.items(): mine_status_xref = MineStatusXref( mine_status_xref_guid=uuid.uuid4(), mine_operation_status_code=status_v['value'], mine_operation_status_reason_code=reason_v['value'], mine_operation_status_sub_reason_code=sub_v['value'], **DUMMY_USER_KWARGS) mine_status_xref.save() # Test Person Data person = Party(party_guid=uuid.UUID(TEST_PARTY_PER_GUID_1), first_name=TEST_PARTY_PER_FIRST_NAME_1, party_name=TEST_PARTY_PER_PARTY_NAME_1, email=TEST_PARTY_PER_EMAIL_1, phone_no=TEST_PARTY_PER_PHONE_1, phone_ext=TEST_PARTY_PER_PHONE_EXT_1, party_type_code=TEST_PARTY_TYPE, **DUMMY_USER_KWARGS) person.save(commit=False) person2 = Party(party_guid=uuid.UUID(TEST_PARTY_PER_GUID_2), first_name=TEST_PARTY_PER_FIRST_NAME_2, party_name=TEST_PARTY_PER_PARTY_NAME_2, email=TEST_PARTY_PER_EMAIL_2, phone_no=TEST_PARTY_PER_PHONE_2, phone_ext=TEST_PARTY_PER_PHONE_EXT_2, party_type_code=TEST_PARTY_TYPE, **DUMMY_USER_KWARGS) person2.save(commit=False) person3 = Party(party_guid=uuid.UUID(TEST_PARTY_PER_GUID_3), first_name=TEST_PARTY_PER_FIRST_NAME_3, party_name=TEST_PARTY_PER_PARTY_NAME_3, email=TEST_PARTY_PER_EMAIL_3, phone_no=TEST_PARTY_PER_PHONE_3, phone_ext=TEST_PARTY_PER_PHONE_EXT_3, party_type_code=TEST_PARTY_TYPE, **DUMMY_USER_KWARGS) person3.save(commit=False) party_org = Party(party_guid=uuid.UUID(TEST_PARTY_ORG_GUID), party_name=TEST_PARTY_ORG_NAME, email=TEST_PARTY_ORG_EMAIL, phone_no=TEST_PARTY_ORG_PHONE, phone_ext=TEST_PARTY_ORG_EXT, party_type_code=TEST_ORG_TYPE, **DUMMY_USER_KWARGS) party_org.save() # Test Permit Status Codes for permit_code_value in TEST_PERMIT_STATUS_CODES: permit_code = PermitStatusCode( permit_status_code=permit_code_value, description=TEST_PERMIT_STATUS_CODE_NAME_1, **DUMMY_USER_KWARGS) permit_code.save() # Test Permit Data permit = Permit(permit_guid=TEST_PERMIT_GUID_1, mine_guid=TEST_MINE_GUID, permit_no=TEST_PERMIT_NO_1, permit_status_code=TEST_PERMIT_STATUS_CODE_1, **DUMMY_USER_KWARGS) permit.save() permit_amendment_status_code = PermitAmendmentStatusCode( permit_amendment_status_code=TEST_PERMIT_AMENDMENT_STATUS_CODE, description=TEST_PERMIT_AMENDMENT_STATUS_CODE_NAME, **DUMMY_USER_KWARGS) permit_amendment_status_code.save() permit_amendment_status_code2 = PermitAmendmentStatusCode( permit_amendment_status_code=TEST_PERMIT_AMENDMENT_STATUS_CODE_2, description=TEST_PERMIT_AMENDMENT_STATUS_CODE_NAME, **DUMMY_USER_KWARGS) permit_amendment_status_code2.save() permit_amendment_type_code = PermitAmendmentTypeCode( permit_amendment_type_code=TEST_PERMIT_AMENDMENT_TYPE_CODE, description=TEST_PERMIT_AMENDMENT_TYPE_CODE_NAME, **DUMMY_USER_KWARGS) permit_amendment_type_code.save() permit_amendment_type_code2 = PermitAmendmentTypeCode( permit_amendment_type_code=TEST_PERMIT_AMENDMENT_TYPE_CODE_2, description=TEST_PERMIT_AMENDMENT_TYPE_CODE_NAME, **DUMMY_USER_KWARGS) permit_amendment_type_code2.save() required_document_due_date_type1 = RequiredDocumentDueDateType( req_document_due_date_type=TEST_REQUIRED_REPORT_DUE_DATE_TYPE[0], req_document_due_date_description= TEST_REQUIRED_REPORT_DUE_DATE_DESCRIPTION[0], **DUMMY_USER_KWARGS) required_document_due_date_type1.save() required_document_due_date_type2 = RequiredDocumentDueDateType( req_document_due_date_type=TEST_REQUIRED_REPORT_DUE_DATE_TYPE[1], req_document_due_date_description= TEST_REQUIRED_REPORT_DUE_DATE_DESCRIPTION[1], **DUMMY_USER_KWARGS) required_document_due_date_type2.save() required_document_category1 = RequiredDocumentCategory( req_document_category=TEST_REQUIRED_REPORT_CATEGORY_TAILINGS) required_document_category1.save() required_document_category2 = RequiredDocumentCategory( req_document_category='OTH') required_document_category2.save() required_document1 = RequiredDocument( req_document_guid=uuid.UUID(TEST_REQUIRED_REPORT_GUID1), req_document_name=TEST_REQUIRED_REPORT_NAME1, req_document_category=required_document_category1. req_document_category, req_document_due_date_type=TEST_REQUIRED_REPORT_DUE_DATE_TYPE[0], req_document_due_date_period_months=12, **DUMMY_USER_KWARGS) required_document1.save() required_document_sub_category = RequiredDocumentSubCategory( req_document_sub_category_code=TEST_REQUIRED_REPORT_SUB_CATEGORY_1) required_document_sub_category.save() required_document2 = RequiredDocument( req_document_guid=uuid.UUID(TEST_REQUIRED_REPORT_GUID2), req_document_name=TEST_REQUIRED_REPORT_NAME2, req_document_category=required_document_category1. req_document_category, req_document_sub_category_code=required_document_sub_category. req_document_sub_category_code, req_document_due_date_type=TEST_REQUIRED_REPORT_DUE_DATE_TYPE[0], req_document_due_date_period_months=12, **DUMMY_USER_KWARGS) required_document2.save() required_document3 = RequiredDocument( req_document_guid=uuid.UUID(TEST_REQUIRED_REPORT_GUID3), req_document_name=TEST_REQUIRED_REPORT_NAME3, req_document_category=required_document_category2. req_document_category, req_document_due_date_type=TEST_REQUIRED_REPORT_DUE_DATE_TYPE[1], req_document_due_date_period_months=12, **DUMMY_USER_KWARGS) required_document3.save() expected_document_status1 = ExpectedDocumentStatus( exp_document_status_code=TEST_EXPECTED_DOCUMENT_STATUS_CODE1, description="Not Received", display_order=10, **DUMMY_USER_KWARGS) expected_document_status1.save() expected_document_status2 = ExpectedDocumentStatus( exp_document_status_code=TEST_EXPECTED_DOCUMENT_STATUS_CODE2, description="Pending Review", display_order=20, **DUMMY_USER_KWARGS) expected_document_status2.save() expected_document1 = MineExpectedDocument( exp_document_guid=uuid.UUID(TEST_EXPECTED_DOCUMENT_GUID1), req_document_guid=uuid.UUID(TEST_REQUIRED_REPORT_GUID1), mine_guid=TEST_MINE_GUID, exp_document_name=TEST_EXPECTED_DOCUMENT_NAME1, due_date=datetime.strptime('1984-06-18', '%Y-%m-%d'), received_date=datetime.strptime('1984-06-18', '%Y-%m-%d'), exp_document_status_code=expected_document_status1. exp_document_status_code, **DUMMY_USER_KWARGS) expected_document1.save() mine_tsf1 = MineTailingsStorageFacility( mine_tailings_storage_facility_guid= TEST_TAILINGS_STORAGE_FACILITY_GUID1, mine_guid=TEST_MINE_GUID, mine_tailings_storage_facility_name= TEST_TAILINGS_STORAGE_FACILITY_NAME1, **DUMMY_USER_KWARGS) mine_tsf1.save() mpat1 = MinePartyAppointmentType( mine_party_appt_type_code=TEST_MINE_PARTY_APPT_TYPE_CODE1, description=TEST_MINE_PARTY_APPT_TYPE_DESCRIPTION1, grouping_level=2, **DUMMY_USER_KWARGS) mpat1.save() mpat2 = MinePartyAppointmentType( mine_party_appt_type_code=TEST_MINE_PARTY_APPT_TYPE_CODE2, description=TEST_MINE_PARTY_APPT_TYPE_DESCRIPTION2, grouping_level=2, **DUMMY_USER_KWARGS) mpat2.save() mpat3 = MinePartyAppointmentType(mine_party_appt_type_code='EOR', description='Engineer of Record', grouping_level=1, **DUMMY_USER_KWARGS) mpat3.save() mpat4 = MinePartyAppointmentType(mine_party_appt_type_code='PMT', description='Engineer of Record', grouping_level=1, **DUMMY_USER_KWARGS) mpat4.save() mpat5 = MinePartyAppointmentType(mine_party_appt_type_code='MMG', description='Mine Manager', grouping_level=1, **DUMMY_USER_KWARGS) mpat5.save() mine_doc1 = MineDocument( mine_guid=uuid.UUID(TEST_MINE_GUID), document_name=TEST_MINE_DOCUMENT_NAME1, document_manager_guid=TEST_DOCUMENT_MANAGER_FILE_GUID, **DUMMY_USER_KWARGS) mine_doc1.mine_expected_document.append(expected_document1) mine_doc1.save() application_status_code_1 = ApplicationStatusCode( application_status_code='RIP', description='In Review', display_order=10, **DUMMY_USER_KWARGS) application_status_code_1.save() application_status_code_2 = ApplicationStatusCode( application_status_code='APR', description='Approved', display_order=20, **DUMMY_USER_KWARGS) application_status_code_2.save()