def test_get_taxa_by_name_and_is_active(request): get_taxa(q="Lixus bardanae", is_active=False) request_kwargs = request.call_args[1] assert request_kwargs["params"] == { "q": "Lixus bardanae", "is_active": "false" }
def test_get_taxa_by_rank_range( mock_inaturalist_api_get_call, params, expected_ranks, ): # Make sure custom rank params result in the correct 'rank' param value get_taxa(**params) mock_inaturalist_api_get_call.assert_called_with( "taxa", {"rank": expected_ranks}, user_agent=None )
def test_get_taxa_by_rank_range( mock_inaturalist_api_get_call, params, expected_ranks, ): # Make sure custom rank params result in the correct 'rank' param value get_taxa(**params) kwargs = mock_inaturalist_api_get_call.call_args[1] requested_rank = kwargs["params"]["rank"] assert requested_rank == expected_ranks
def test_get_taxa(requests_mock): params = urlencode({"q": "vespi", "rank": "genus,subgenus,species"}) requests_mock.get( urljoin(INAT_NODE_API_BASE_URL, "taxa?" + params), json=load_sample_data("get_taxa.json"), status_code=200, ) response = get_taxa(q="vespi", rank=["genus", "subgenus", "species"]) first_result = response["results"][0] assert len(response["results"]) == 30 assert response["total_results"] == 35 assert first_result["id"] == 70118 assert first_result["name"] == "Nicrophorus vespilloides" assert first_result["rank"] == "species" assert first_result["is_active"] is True assert len(first_result["ancestor_ids"]) == 14
def search_inaturalist(model_arr): # searches iNaturalist database of given names and return information and wiki url foo_outbrackets = model_arr[0] foo_inbrackets = model_arr[1] response = get_taxa(q=foo_inbrackets) response = ({taxon["id"]: taxon["name"] for taxon in response["results"]}) foo = None for num, name in response.items(): if name == foo_outbrackets or name == foo_inbrackets: foo = num response = get_taxa_by_id(foo) # only the id number foo_info = response["results"][0]["wikipedia_summary"] foo_url = response["results"][0]["wikipedia_url"] return foo_info, foo_url
def results(page: int) -> Callable[[int], List[InlineQueryResult]]: response = get_taxa(q=query, page=str(page + 1), per_page=10) results = response['results'] if results: answers = [ InlineQueryResultArticle( id=item['id'], title=item['name'], input_message_content=InputTextMessageContent( f'*{item["name"].title()}*', parse_mode='MarkdownV2'), description=item['rank'].title(), thumb_url=item['default_photo']['url'] if 'default_photo' in item else None, reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton(text='See more', callback_data=item['id']) ]])) for item in results ] return answers if answers else None return None