def test_add_user():
    # Create instance
    movie = Movie("Test", 2020)
    movie.runtime_minutes = 120
    user = User("Host", "password123")
    watch_simulation = MovieWatchingSimulation(movie, user)

    # Add users
    guest1 = User("Guest1", "password123")
    guest2 = User("Guest2", "password123")
    guest3 = User("Guest3", "password123")
    guest4 = "Guest4"  # invalid

    # Good input
    watch_simulation.add_user(guest1)
    assert watch_simulation.users_watching == {user, guest1}
    assert movie in guest1.watched_movies

    # Good input
    watch_simulation.add_user(guest2)
    assert watch_simulation.users_watching == {user, guest1, guest2}
    assert movie in guest2.watched_movies

    # Good input
    watch_simulation.add_user(guest3)
    assert watch_simulation.users_watching == {user, guest1, guest2, guest3}
    assert movie in guest3.watched_movies

    # Invalid input
    watch_simulation.add_user(guest4)
    assert watch_simulation.users_watching == {user, guest1, guest2, guest3}
def test_add_review():
    # Create instance
    movie = Movie("Test", 2020)
    movie.runtime_minutes = 120
    user = User("Host", "password123")
    watch_simulation = MovieWatchingSimulation(movie, user)
    review = Review(user, movie, "wow!", 10)

    # Test works as intended
    watch_simulation.add_review(review, user)
    assert watch_simulation.reviews == [review]
    assert user.reviews == [review]

    # Test for invalid inputs
    user2 = "Host"
    review2 = "wow!"

    watch_simulation.add_review(review2, user)
    assert watch_simulation.reviews == [review]

    watch_simulation.add_review(review, user2)
    assert watch_simulation.reviews == [review]

    # Test for movie which isn't the movie being watched
    movie2 = Movie("Test2", 2020)
    review3 = Review(user, movie2, "wow!", 10)
    watch_simulation.add_review(review3, user)
    assert watch_simulation.reviews == [review]
    assert user.reviews == [review]

    # Test for user not in the party leaving a review
    user3 = User("Random User", "password123")
    review4 = Review(user3, movie, "hacked", 1)
    watch_simulation.add_review(review4, user3)
    assert watch_simulation.reviews == [review]
    def __init__(self, movie: Movie, host: User):
        if isinstance(movie, Movie):
            self.__movie = movie
        else:
            raise TypeError("The simulation must be initialised with a Movie and User object")

        if isinstance(host, User):
            self.__users_watching = {host}
            host.watch_movie(movie)
        else:
            raise TypeError("The simulation must be initialised with a Movie and User object")
        
        self.__reviews = []
Example #4
0
def test_remove_review():
    movie = Movie("Sharknado", 2020)
    review = Review(User('Test', 'Test'), movie, "Wow!", 10)
    movie.add_review(review)
    assert movie.reviews == [review]

    movie.remove_review(review)
    assert movie.reviews == []
Example #5
0
def test_timestamp():
    user = User('Test', 'Test')
    movie = Movie("Moana", 2016)
    review_text = "This movie was very enjoyable."
    rating = 8
    review = Review(user, movie, review_text, rating)

    assert type(review.timestamp) == datetime.datetime
Example #6
0
def test_user():
    user = User('Test', 'Test')
    movie = Movie("Moana", 2016)
    review_text = "This movie was very enjoyable."
    rating = 8
    review = Review(user, movie, review_text, rating)

    assert review.user == user
    
def test_make_review():
    user = User('Test', 'Test')
    movie = Movie("Moana", 2016)
    review_text = "This movie was very enjoyable."
    rating = 8
    review = make_review(user, movie, review_text,rating)

    assert user.reviews == [review]
    assert review.user == user
    assert movie.reviews == [review]
Example #8
0
def load_users(repository: MemoryRepository, filename: str):
    with open(filename, encoding='utf-8-sig') as csvfile:
        reader = csv.DictReader(csvfile)

        # Read remaining rows from the CSV file.
        for row in reader:
            user = User(
                username=row['username'],
                password=generate_password_hash(row['password'])
            )
            repository.add_user(user)
Example #9
0
def add_user(username: str, password: str, repo: AbstractRepository):
    # Check that the given username is available
    user = repo.get_user(username)
    if user is not None:
        raise NameNotUniqueException

    # Encrypt password so that the database doesn't store passwords 'in the clear'
    password_hash = generate_password_hash(password)

    # Create and store the new User, with password encrypted
    user = User(username, password_hash)
    repo.add_user(user)
def test_init():
    # Create instance
    movie = Movie("Test", 2020)
    movie.runtime_minutes = 120
    user = User("Host", "password123")
    watch_simulation = MovieWatchingSimulation(movie, user)

    # Uses the properties to check valid init
    assert watch_simulation.movie == movie
    assert watch_simulation.reviews == []
    assert watch_simulation.users_watching == {user}

    # Check movie was added to users watch list
    assert movie in user.watched_movies

    # create bad instances
    movie2 = "Test"
    user2 = "Host"
    with pytest.raises(TypeError):
        watch_simulation2 = MovieWatchingSimulation(movie2, user)
        watch_simulation3 = MovieWatchingSimulation(movie, user2)
def test_repository_can_retrieve_a_user(empty_memory_repo):
    user = User('jebulious', '1278371das89f')
    empty_memory_repo.add_user(user)

    user = empty_memory_repo.get_user('jebulious')
    assert user == User('jebulious', '1278371das89f')
def test_repository_can_add_a_user(empty_memory_repo):
    user = User('Lex', 'testpassword')
    empty_memory_repo.add_user(user)

    assert empty_memory_repo.get_user('Lex') is user
Example #13
0
 def add_review(self, review: Review, user: User):
     if isinstance(review, Review) and isinstance(user, User) and review.movie == self.movie and user in self.users_watching:
         self.__reviews.append(review)
         user.add_review(review)
Example #14
0
 def add_user(self, user: User):
     if isinstance(user, User):
         self.__users_watching.add(user)
         user.watch_movie(self.movie)
Example #15
0
def test_user_watchlist():
    user = User('Test', 'Test')

    assert user.watchlist.size() == 0
    assert user.watchlist.watchlist == []