def load_movies_and_genre(data_path: str, repo: memoryRepository):
    genres = dict()
    actors = dict()
    directors = dict()

    for data_row in read_csv_file(
            os.path.join(data_path, 'Data1000MoviesWithImage')):
        movie_genre = data_row[2].split(",")
        movie_actor = data_row[5].split(",")
        movie_actor = map(lambda x: x.strip(), movie_actor)
        movie_genre = map(lambda x: x.strip(), movie_genre)
        director = data_row[4]

        # Create Movie object.
        movie = Movie(data_row[1], int(data_row[6]))

        movie.rank = int(data_row[0])
        movie.description = data_row[3]
        movie.metascore = data_row[11]
        movie.votes = int(data_row[9])
        movie.rating = float(data_row[8])

        if director not in directors:
            directors[director] = list()
        directors[director].append(movie.rank)

        # Add the Movie to the repository.
        repo.add_movie(movie)

        if data_row[-1] and data_row[-1] != 'N/A':
            movie.poster = data_row[-1]

        for genre in movie_genre:
            if genre not in genres.keys():
                genres[genre] = list()
            genres[genre].append(movie.rank)

        for actor in movie_actor:
            if actor not in actors.keys():
                actors[actor] = list()
            actors[actor].append(movie.rank)

    for director_name in directors.keys():
        director = Director(director_name)
        for rank in directors[director_name]:
            movie = repo.get_movie(rank)
            director.movies = movie
            movie.director = director
        if director not in repo.directors:
            repo.directors = director

    for genre_name in genres.keys():
        genre = Genre(genre_name)
        for rank in genres[genre_name]:
            movie = repo.get_movie(rank)
            genre.genre_movies = movie
            movie.genres = genre
        if genre not in repo.genres:
            repo.genres = genre

    for actor_name in actors.keys():
        actor = Actor(actor_name)
        for rank in actors[actor_name]:
            movie = repo.get_movie(rank)
            actor.movies = movie
            movie.actors = actor
        if actor not in repo.actor:
            repo.actor = actor
def test_repository_can_add_movie(in_memory_repo):
    movie = Movie("abc", 2016)
    movie.rank = 12
    in_memory_repo.add_movie(movie)

    assert in_memory_repo.get_movie(12) is movie