def test_article_less_than_operator(): article_1 = Movie( "",2019 ) article_2 = Movie( "", 2020 ) assert article_1 < article_2
def load_movies_and_genres_and_actors_and_directors(data_path: str, repo: MemoryRepository): tags = dict() actors = dict() directors = dict() for data_row in read_csv_file(os.path.join(data_path, 'news_articles.csv')): article_key = int(data_row[0]) number_of_tags = len(data_row[2].split()) article_tags = data_row[2].split(",") movie_actors = data_row[5].split(",") movie_director = data_row[4] movie_description = data_row[3] # Add any new tags; associate the current article with tags. for tag in article_tags: if tag not in tags.keys(): tags[tag] = list() tags[tag].append(article_key) #del data_row[-number_of_tags:] for actor in movie_actors: if actor not in actors.keys(): actors[actor] = list() actors[actor].append(article_key) # Create Article object. if movie_director not in directors.keys(): directors[movie_director] = list() directors[movie_director].append(article_key) movie = Movie(title=data_row[1], release_year=int(data_row[6])) repo.add_movie(movie, article_key, movie_description) # Create Tag objects, associate them with Articles and add them to the repository. for tag_name in tags.keys(): tag = Genre(tag_name) # Add the Article to the repository. for article_id in tags[tag_name]: movie = repo.get_movie(article_id) make_genre_association(movie, tag) repo.add_genre(tag) for actor_name in actors.keys(): actor = Actor(actor_name) for article_id in actors[actor_name]: movie = repo.get_movie(article_id) make_actor_association(movie, actor) repo.add_actor(actor) for director_name in directors.keys(): director = Director(director_name) for movie_id in directors[director_name]: movie = repo.get_movie(movie_id) make_director_association(movie, director) repo.add_director(director)
def test_repository_can_add_article(in_memory_repo): article = Movie( 'Second US coronavirus cruise tests negative amid delays and cancellations', 2019) in_memory_repo.add_movie(article, 3, "blahbalah") assert in_memory_repo.get_movie(3) is article
def test_tag_construction(genre): assert genre.genre_name == 'New Zealand' for movie in genre.genre_movie: assert False assert not genre.is_applied_to(Movie("", 1900))
def test_repository_can_add_movie(session_factory): repo = SqlAlchemyRepository(session_factory) number_of_movies = repo.get_number_of_movie() new_movie_rank = number_of_movies + 1 desc = "" movie = Movie("Cool World", 2015) repo.add_movie(movie, new_movie_rank, desc) assert repo.get_movie(new_movie_rank) == movie
def add_movie(self, article: Movie, rank: int, description: str): insort_left(self._articles, article) article.set_id(rank) article.description = description self._articles_index[article.id] = article
def movie(): return Movie('Coronavirus travel restrictions: Self-isolation deadline pushed back to give airlines breathing room',2020)
def dict_to_article(dict): article = Movie(dict.title, dict.release_year) # Note there's no comments or tags. return article
def make_movie(): movie = Movie('Prometheus', 2012) return movie
def make_movie(new_movie_year): movie = Movie("Cool Word", 2015) return movie