def post(self): current_app.logger.debug('Attempting to load application') try: application = Application._schema().load(request.json) except MarshmallowError as e: raise BadRequest(e) if application.application_guid is not None: raise BadRequest( f'messageid: {application.messageid} already exists.') if application.applicant.clientid == application.submitter.clientid: application.submitter = application.applicant current_app.logger.debug('Attempting to load the mine') mine = Mine.find_by_mine_no(application.minenumber) if mine is None: raise BadRequest('Mine not found from the minenumber supplied.') application.mine = mine application.now_application_identity = NOWApplicationIdentity( mine=mine, mine_guid=mine.mine_guid, now_submission=application, now_number=NOWApplicationIdentity.create_now_number(mine)) current_app.logger.debug('Attempting to Save') application.save() return application, 201
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 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 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_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_no(test_client, auth_headers): mine = Mine.find_by_mine_no(TEST_MINE_NO) assert str(mine.mine_no) == TEST_MINE_NO