示例#1
0
def best_match(title: str, base_url: str = DEFAULT_BASE_URL) -> Optional[Film]:
    response = requests.get(f"{base_url}/", params={"title": title})
    if response.ok:
        return Film.parse_raw(response.content,
                              content_type=response.headers["Content-Type"])

    if response.status_code == 404:
        return None

    response.raise_for_status()
示例#2
0
def test_best_autocomplete_match_with_multiple_results(
        search_interstellar_json):
    result = best_autocomplete_match(search_interstellar_json,
                                     title="Interstellar")
    assert result == Film(title="Interstellar", age_rating=AgeRating.AGE_12)
示例#3
0
def test_best_autocomplete_match_with_one_result(search_a_silent_voice_json):
    result = best_autocomplete_match(search_a_silent_voice_json,
                                     title="A Silent Voice")
    assert result == Film(title="A Silent Voice", age_rating=AgeRating.AGE_12)
示例#4
0
async def test_best_match(mock_search_interstellar):
    result = await best_match(title="interstellar")
    assert result == Film(title="Interstellar", age_rating=AgeRating.AGE_12)
示例#5
0
def test_integration_best_match(app_url):
    actual = best_match("Interstellar", base_url=app_url)
    assert actual == Film(title="Interstellar", age_rating=AgeRating.AGE_12)
示例#6
0
文件: parser.py 项目: Fustra/bbfcapi
def _result_to_film(result: Dict[str, Any]) -> Film:
    return Film(
        title=result["title"],
        age_rating=_classification_to_age_rating(result["classification"]),
    )