Beispiel #1
0
 def add_film(self, name: str, year: int,
              storage: List[Film]) -> Union[Film, None]:
     for film in storage:
         if film.name == name and int(film.year) == year:
             return None
     film = Film(name, year, [], [])
     return film
Beispiel #2
0
def add_mark(username: str) -> Any:
    """Добавляем оценку к фильму или получаем информацию, что такого фильма еще нет"""
    if (not request.json or 'name' not in request.json
            or 'year' not in request.json or 'mark' not in request.json):
        return (
            jsonify({
                'ERROR':
                'Invalid data, please give name and year of film and your mark'
            }),
            400,
        )
    user = find_user(username, USER_STORAGE)
    name_film: str = request.json.get('name')
    year_film: int = int(request.json.get('year'))
    mark_film: int = int(request.json.get('mark'))
    film = user.add_review_or_mark(Film(name_film, year_film, [], []),
                                   FILM_STORAGE, mark_film)
    if film is None:
        return (
            jsonify({
                'ERROR':
                'This film does not exist or you mark less 0 or more zero, check it'
            }),
            404,
        )

    return jsonify({'ADD_MARK': {'name': name_film, 'mark': mark_film}})
Beispiel #3
0
def add_review(username: str) -> Any:
    """Добавляем ревью к фильму или получаем информацию, что такого фильма еще нет"""
    if (not request.json or 'name' not in request.json
            or 'year' not in request.json or 'review' not in request.json):
        return (
            jsonify({
                'ERROR':
                'Invalid data, please give name and year of film and your review'
            }),
            400,
        )
    user = find_user(username, USER_STORAGE)
    name_film: str = request.json.get('name')
    try:
        year_film: int = int(request.json.get('year'))
    except ValueError:
        return jsonify({'ERROR':
                        'Year of film must be a number, check it'}), 404
    review_film: str = request.json.get('review')
    film = user.add_review_or_mark(Film(name_film, year_film, [], []),
                                   FILM_STORAGE, review_film)

    if film is None:
        return jsonify({'ERROR': 'This film does not exist'}), 404

    return jsonify({'ADD_REVIEW': {'name': name_film, 'review': review_film}})
Beispiel #4
0
def film_not_exist():
    not_exist_film = Film('FILM', 2000, [], [])
    yield not_exist_film
Beispiel #5
0
def film_exist():
    exist_film = Film('film', 2000, [], [])
    yield exist_film
def film():
    return Film('film', 2010, [], [])
def film_with_data():
    return Film('film', 2010, [5, 4], ['review1', 'review2'])
Beispiel #8
0
def bad_film():
    return Film('NOT_EXIST_FILM', 1000, [], [])
Beispiel #9
0
def storage():
    return [Film('film', 2010, [], [])]