def test_equality_when_not_equal(review):
    # Check not equal when reviews are partially equal
    movie = Movie("Test", 2000, 1)
    review_text = review.review_text
    rating = review.rating
    other = Review(movie, review_text, rating)
    assert review != other

    movie = review.movie
    review_text = "Test"
    rating = review.rating
    other = Review(movie, review_text, rating)
    assert review != other

    movie = review.movie
    review_text = review.review_text
    rating = 5
    other = Review(movie, review_text, rating)
    assert review != other

    # Check not equal when reviews are completely different
    movie = Movie("Test", 2000, 1)
    review_text = "Test"
    rating = 5
    other = Review(movie, review_text, rating)
    assert review != other
예제 #2
0
def test_loading_of_movies(empty_session):
    movies = list()
    movies.append(("Andrew", 2020))
    movies.append(("Cindy", 1999))
    insert_movies(empty_session, movies)

    expected = [Movie("Andrew", 2020), Movie("Cindy", 1999)]
    assert empty_session.query(Movie).all() == expected
예제 #3
0
def test_equality_when_not_equal(movie):
    # Check not equal when partially equal
    other = Movie("TestMovie", 2000, 1)
    assert movie != other

    other = Movie("123", 2020, 1)
    assert movie != other

    # Check not equal when title and release date both differ
    other = Movie("123", 2000, 1)
    assert movie != other
예제 #4
0
 def test_post(self):
     payload = {'name': 'test', 'description': 'test', 'length': 30}
     res = requests.post(current_config.MOVIE_SERVICE_URL + current_config.MOVIE_SERVICE_PATH +
                         current_config.CREATE_PATH, data=jsonpickle.encode(payload))
     self.assertEqual(res.status_code, 201)
     movie = Movie.from_json(res.content)
     requests.delete(current_config.MOVIE_SERVICE_URL + current_config.MOVIE_SERVICE_PATH + "/%s" % str(movie.id))
예제 #5
0
 def test_get_right(self):
     rep = MovieRepository()
     movie_id = rep.create('a', 'a', 100)
     movie1 = rep.get(movie_id)
     movie2 = Movie(movie_id=fields.ObjectId(movie_id), name='a', description='a', length=100)
     self.assertEqual(movie1, movie2)
     rep.delete(movie_id)
예제 #6
0
 def get(self, movie_id):
     if self.exists(movie_id):
         movie = Movies.query.get(movie_id)
         return Movie(movie_id=movie.mongo_id, name=movie.name, description=movie.description,
                                        length=movie.length)
     else:
         return None
예제 #7
0
 def test_post(self):
     gmr = GatewayMovieCreateResource()
     res = gmr.post()
     self.assertEqual(res.status_code, 201)
     mr = MovieResource()
     movie = Movie.from_json(res.data)
     mr.delete(str(movie.id))
예제 #8
0
 def test_get(self, mock_movie):
     movies = []
     movie = Movie(name='movie', description='description', length=60, movie_id="123")
     movies.append(movie)
     mock_movie.return_value.read_paginated.return_value = movies, False, True
     mr = MovieListResource()
     res = mr.get()
     self.assertEqual(res.status_code, 200)
예제 #9
0
 def test_get_right(self):
     mr = MovieResource()
     mcr = MovieCreateResource()
     res = mcr.post()
     movie = Movie.from_json(res.data)
     gmr = GatewayMovieResource()
     res = gmr.get(str(movie.id))
     self.assertEqual(res.status_code, 200)
     mr.delete(str(movie.id))
예제 #10
0
 def read_paginated(self, page_number, page_size):
     movies = []
     movies_paginated = Movies.query.paginate(page=page_number, per_page=page_size)
     for movie in movies_paginated.items:
         movies.append(Movie(movie_id=movie.mongo_id, name=movie.name, description=movie.description,
                             length=movie.length))
     is_prev_num = (movies_paginated.prev_num > 0)
     is_next_num = (movies_paginated.next_num <= movies_paginated.pages)
     return movies, is_prev_num, is_next_num
def test_contains(watchlist, movie, movies):
    for movie in movies:
        watchlist.add_movie(movie)

    for i, movie in enumerate(movies):
        assert movie in watchlist

    assert not (Movie("test", 2020, 1234) in watchlist)
    assert not (123 in watchlist)
예제 #12
0
파일: gateway_api.py 프로젝트: AnkoSkl/rsoi
    def get(self, seance_id):
        app.logger.info(
            'Получен запрос на получение подробной информации о сеансе с идентификатором %s'
            % seance_id)
        response_seance = requests.get(current_config.SEANCE_SERVICE_URL +
                                       current_config.SEANCE_SERVICE_PATH +
                                       "/%s" % seance_id)
        if response_seance.status_code == 200:
            app.logger.info(
                'Запрос на получение информации о сеансе с идентификатором %s успешно обработан'
                % seance_id)
        else:
            app.logger.warning(
                'Информация о сеансе с идентификатором %s не модет быть получена'
                % seance_id)
            result = flask.Response(status=response_seance.status_code,
                                    headers=response_seance.headers.items(),
                                    response=response_seance.content)
            return result

        seance = Seance.from_json(
            response_seance.content
        )  #jsonpickle.decode(response_seance.content)
        movie_id = str(seance.movie_id)

        response_movie = requests.get(current_config.MOVIE_SERVICE_URL +
                                      current_config.MOVIE_SERVICE_PATH +
                                      "/%s" % movie_id)
        if response_movie.status_code == 200:
            app.logger.info(
                'Запрос на получение информации о фильме с идентификатором %s успешно обработан'
                % movie_id)
        else:
            app.logger.warning(
                'Информация о фильме с идентификатором %s не модет быть получена'
                % movie_id)
            result = flask.Response(status=response_movie.status_code,
                                    headers=response_movie.headers.items(),
                                    response=response_movie.content)
            return result
        movie = Movie.from_json(response_movie.content)
        response = seance.to_json() + '\n' + movie.to_json()
        result = flask.Response(status=response_seance.status_code,
                                headers=response_seance.headers.items(),
                                response=response)
        app.logger.info(
            'Запрос на получение подробной информации о сеансе с идентификатором %s успешно обработан'
            % seance_id)
        return result
예제 #13
0
def test_hash_changes():
    a = Movie("1234", 2020, 1)
    b = Movie("123", 2020, 2)
    assert hash(a) != hash(b)

    a = Movie("123", 2021, 1)
    b = Movie("123", 2020, 2)
    assert hash(a) != hash(b)

    a = Movie("1234", 2021, 1)
    b = Movie("123", 2020, 2)
    assert hash(a) != hash(b)
예제 #14
0
def test_less_than_when_true():
    a = Movie("123", 2020, 1)
    b = Movie("1234", 2020, 2)
    assert a < b

    a = Movie("123", 2020, 1)
    b = Movie("123", 2021, 2)
    assert a < b

    a = Movie("123", 2020, 1)
    b = Movie("1234", 2021, 2)
    assert a < b
예제 #15
0
def test_less_than_when_false():
    a = Movie("1234", 2020, 1)
    b = Movie("123", 2020, 2)
    assert not (a < b)

    a = Movie("123", 2021, 1)
    b = Movie("123", 2020, 2)
    assert not (a < b)

    a = Movie("123", 2020, 1)
    b = Movie("123", 2020, 2)
    assert not (a < b)
    assert not (b < a)
예제 #16
0
def test_constructor_empty_string_title():
    movie = Movie("", 2000, 1)
    assert movie.title is None
예제 #17
0
def test_constructor_invalid_title():
    movie = Movie(123, 2000, 1)
    assert movie.title is None
예제 #18
0
def test_repr_with_no_name():
    movie = Movie("", 2020, 1)
    assert repr(movie) == "<Movie 1, None, 2020>"
예제 #19
0
def populated_movies(genres, directors, actors):
    movies = []

    for i in range(10):
        movie = Movie(f'Movie{i}', 2000 + i, i)
        movie.genres = [genres[i]]
        movie.description = f'Description{i}'
        movie.director = directors[i]
        movie.actors = [actors[i]]
        movie.runtime_minutes = i + 1
        movie.rating = float(i)
        movie.votes = i

        if i % 2 == 0:
            movie.revenue_millions = float(i + 1)

        if i % 4 == 0:
            movie.metascore = i * 10

        movies.append(movie)

    return movies
예제 #20
0
def movies():
    return [Movie(f'Movie{i}', 2020, i) for i in range(10)]
예제 #21
0
def movie():
    return Movie("TestMovie", 2020, 1)
예제 #22
0
def test_equality_when_equal(movie):
    other = Movie("TestMovie", 2020, 1)
    assert movie == other
예제 #23
0
def test_constructor_invalid_release_date_type():
    with pytest.raises(TypeError):
        _ = Movie("Test", 2000.9, 1)
예제 #24
0
def test_constructor_invalid_movies_type():
    with pytest.raises(TypeError):
        _ = MovieWatchingSimulation(123)

    with pytest.raises(TypeError):
        _ = MovieWatchingSimulation([Movie("Test", 2020), 123])
예제 #25
0
def test_constructor_invalid_release_date_value():
    with pytest.raises(ValueError):
        _ = Movie("Test", 1899, 1)
예제 #26
0
 def test_get_right(self, mock_movie):
     movie = Movie(name='a', description='b', length=90, movie_id="123")
     mock_movie.return_value.get.return_value = movie
     mr1 = MovieResource()
     res = mr1.get('123')
     self.assertEqual(res.status_code, 200)
예제 #27
0
    def _read_row(self, row: _ROW, id_: int) -> Movie:
        """
        Helper method to construct a Movie from a row.

        Raises:
            ValueError: unable to parse row: {row}
         """
        error = False

        try:
            title = row['Title']
            genres = [
                self._get_genre(Genre(name))
                for name in row['Genre'].split(',')
            ]
            description = row['Description']
            director = self._get_director(Director(row['Director']))
            actors = [
                self._get_actor(Actor(name))
                for name in row['Actors'].split(',')
            ]
            release_year = int(row['Year'])
            runtime_minutes = int(row['Runtime (Minutes)'])
            rating = float(row['Rating'])
            votes = int(row['Votes'])
            revenue_millions = float(
                row['Revenue (Millions)']
            ) if row['Revenue (Millions)'] != 'N/A' else None
            metascore = int(
                row['Metascore']) if row['Metascore'] != 'N/A' else None
        except KeyError:
            error = True
        except ValueError:
            error = True

        if error:
            raise ValueError(f'unable to parse row: {row}')

        movie = Movie(title, release_year, id_)
        movie.genres = genres
        movie.description = description
        movie.director = director
        movie.actors = actors
        movie.runtime_minutes = runtime_minutes
        movie.rating = rating
        movie.votes = votes

        if revenue_millions:
            movie.revenue_millions = revenue_millions

        if metascore:
            movie.metascore = metascore

        return movie
예제 #28
0
def test_constructor():
    movie = Movie("   Movie   name  with    spaces  \n", 1900, 1)
    assert movie.title == "Movie   name  with    spaces"