def test_mine_model_find_by_mine_no_or_guid(db_session): init_mine = MineFactory() mine = Mine.find_by_mine_no_or_guid(init_mine.mine_no) assert mine.mine_no == init_mine.mine_no mine = Mine.find_by_mine_no_or_guid(str(init_mine.mine_guid)) assert mine.mine_guid == init_mine.mine_guid
def get(self, mine_no): result = cache.get(NRIS_COMPLIANCE_DATA(mine_no)) if result is None: mine = Mine.find_by_mine_no_or_guid(mine_no) if not mine: raise NotFound("No mine record in CORE.") try: raw_data = NRIS_API_service._get_NRIS_data_by_mine( request.headers.get('Authorization'), mine_no) except requests.exceptions.Timeout: current_app.logger.error( f'NRIS_API Connection Timeout <mine_no={mine_no}>') raise except requests.exceptions.HTTPError as e: current_app.logger.error( f'NRIS_API Connection HTTPError <mine_no={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_no), result, timeout=TIMEOUT_60_MINUTES) return result
def get(self, mine_no_or_guid): mine = Mine.find_by_mine_no_or_guid(mine_no_or_guid) if not mine: raise NotFound('Mine not found.') return mine
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_mine_model_find_by_mine_no_or_guid(test_client, auth_headers): mine = Mine.find_by_mine_no_or_guid(TEST_MINE_NO) assert str(mine.mine_no) == TEST_MINE_NO mine = Mine.find_by_mine_no_or_guid(TEST_MINE_GUID) assert str(mine.mine_guid) == TEST_MINE_GUID