コード例 #1
0
ファイル: test_domain_model.py プロジェクト: nbel113/CS235-A2
def test_user():  # add movie
    user1 = User('  Martin   ', 'pw12345')
    #print(user1.user_name)
    assert user1.user_name == "martin"

    user1 = User('Martin', 'pw12345')
    user2 = User('Ian', 'pw67890')
    user3 = User('Daniel', 'pw87465')

    #print(user1)
    #print(user2)
    #print(user3)

    assert repr(user1) == "<User martin>"
    assert repr(user2) == "<User ian>"
    assert repr(user3) == "<User daniel>"

    movie1 = Movie("Up", 2009)
    movie1.runtime_minutes = 150
    user1.watch_movie(movie1)
    user1.watch_movie(movie1)

    #print("Watched Movies:", user1.watched_movies)
    #print("Watching Time:", user1.time_spent_watching_movies_minutes)

    assert repr(user1.watched_movies) == "[<Movie Up, 2009>]"
    assert user1.time_spent_watching_movies_minutes == 150

    review1 = Review(movie1, "test", 5)
    user1.add_review(review1)
    user1.add_review(review1)

    #print(user1.reviews)
    assert repr(user1.reviews) == "[<Review <Movie Up, 2009>, test, 5>]"
コード例 #2
0
ファイル: test_domain_model.py プロジェクト: nbel113/CS235-A2
def test_watching_sim_add_review():
    a = MovieWatchingSimulation()
    movie1 = Movie("Moana", 2016)
    movie2 = Movie("Ice Age", 2002)
    movie3 = Movie("Guardians of the Galaxy", 2012)
    user1 = User('Jack', 'pw12345')
    user2 = User('James', 'pw67890')
    user3 = User('Janice', 'pw87465')
    review1 = Review(movie1, "Was good", 6)
    review2 = Review(movie1, "Average", 5)
    review3 = Review(movie1, "Very Great", 8)
    review4 = Review(movie2, "Great", 7)
    review5 = Review(movie2, "Excellent", 9)
    review6 = Review(movie3, "Boring", 3)

    a.add_movie_review(review1.movie, user1, review1.rating)
    a.add_movie_review(review2.movie, user2, review2.rating)
    a.add_movie_review(review3.movie, user3, review3.rating)
    a.add_movie_review(review4.movie, user1, review4.rating)
    a.add_movie_review(review5.movie, user2, review5.rating)
    a.add_movie_review(review6.movie, user1, review6.rating)
    a.add_movie_review(review4.movie, user1, review4.rating)

    assert a.movie_dict == {
        movie1: [[user1, 6], [user2, 5], [user3, 8]],
        movie2: [[user1, 7], [user2, 9], [user1, 7]],
        movie3: [[user1, 3]]
    }
コード例 #3
0
ファイル: test_domain_model.py プロジェクト: nbel113/CS235-A2
def test_watching_sim_review_average():
    a = MovieWatchingSimulation()
    movie1 = Movie("Moana", 2016)
    movie2 = Movie("Ice Age", 2002)
    movie3 = Movie("Guardians of the Galaxy", 2012)
    user1 = User('Jack', 'pw12345')
    user2 = User('James', 'pw67890')
    user3 = User('Janice', 'pw87465')
    review1 = Review(movie1, "Was good", 6)
    review2 = Review(movie1, "Average", 5)
    review3 = Review(movie1, "Very Great", 8)
    review4 = Review(movie2, "Great", 7)
    review5 = Review(movie2, "Excellent", 9)
    review6 = Review(movie3, "Boring", 3)

    a.add_movie_review(review1.movie, user1, review1.rating)
    a.add_movie_review(review2.movie, user2, review2.rating)
    a.add_movie_review(review3.movie, user3, review3.rating)
    a.add_movie_review(review4.movie, user1, review4.rating)
    a.add_movie_review(review5.movie, user2, review5.rating)
    a.add_movie_review(review6.movie, user1, review6.rating)

    #print(a.get_movie_rating_average(movie1))
    #print(a.get_movie_rating_average(movie2))
    #print(a.get_movie_rating_average(movie3))

    assert a.get_movie_rating_average(movie1) == "Average Rating: 6.33"
    assert a.get_movie_rating_average(movie2) == "Average Rating: 8.0"
    assert a.get_movie_rating_average(movie3) == "Average Rating: 3.0"
コード例 #4
0
def test_repo_can_retrieve_user_count(memory_repo):
    original_user_count = len(memory_repo.get_all_users())
    user1 = User('qwerty', '123Qweasd')
    user2 = User('qwe', '123Qweasd')
    memory_repo.add_user(user1)
    memory_repo.add_user(user2)
    assert len(memory_repo.get_all_users()) == original_user_count + 2
コード例 #5
0
def test_3():
    name1 = User("Banana", "abcd1234")
    name2 = User("Apple", "abcd1234")
    name3 = User("Banana", "1234abcd")
    name4 = 123
    assert name1 != name2
    assert name1 == name3
    assert name1 != name4
コード例 #6
0
def test_loading_of_users(empty_session):
    users = list()
    users.append(("andrew", "1234"))
    users.append(("cindy", "1111"))
    insert_users(empty_session, users)

    expected = [User("andrew", "1234"), User("cindy", "999")]
    assert empty_session.query(User).all() == expected
コード例 #7
0
def test_repository_can_add_a_user(session_factory):
    repo = SqlAlchemyRepository(session_factory)

    user = User('Dave', '123456789')
    repo.add_user(user)

    repo.add_user(User('Martin', '123456789'))

    user2 = repo.get_user('Dave')

    assert user2 == user and user2 is user
コード例 #8
0
def test_repository_can_delete_movie_in_user_watchlist(in_memory_repo):
    user = User("Dave", '123456789')
    movie = Movie("Moana", 2016)
    in_memory_repo.add_user(user)
    in_memory_repo.add_user_watch_list(user, movie)
    in_memory_repo.delete_movie_from_watch_list(user, movie)
    assert movie not in in_memory_repo.get_user_watch_list(user)
コード例 #9
0
def in_memory_repo():
    repo.repo_instance = MemoryRepository()
    read_csv_file(os.path.join(TEST_DATA_PATH, 'movies.csv'),
                  repo.repo_instance)

    with open(os.path.join(TEST_DATA_PATH, 'users.csv'),
              mode='r',
              encoding='utf-8-sig') as csvfile:
        reader = csv.DictReader(csvfile)
        for row in reader:
            if row == 0:
                continue
            repo.repo_instance.add_user(User(row["username"], row['password']))

    with open(os.path.join(TEST_DATA_PATH, 'reviews.csv'),
              mode='r',
              encoding='utf-8-sig') as csvfile:
        reader = csv.DictReader(csvfile)
        for row in reader:
            if row == 0:
                continue
            movie = repo.repo_instance.get_movie(row['title'])
            user = repo.repo_instance.get_user(row['user'])
            review = Review(user, movie, row['comment-text'],
                            float(row['rating']))
            review.time_stamp = row["timestamp"]
            repo.repo_instance.add_review(review)
            movie.review.append(review)
    return repo.repo_instance
コード例 #10
0
def test_repository_can_add_a_review(session_factory):
    repo = SqlAlchemyRepository(session_factory)
    user = User('Dave', '123456789')
    repo.add_user(user)
    review = Review('Dave', 'Prometheus', None, None, None, '?', 8)
    repo.add_review(review)
    review1 = repo.get_review()[0]
    assert review == review1 and review1 is review
コード例 #11
0
def load_users(data_path: str, repo: MemoryRepository):
    users = dict()

    for row in read_csv_file(os.path.join(data_path, 'user.csv')):
        user = User(user_name=row[1], password=generate_password_hash(row[2]))
        repo.add_user(user)
        users[row[0]] = user
    return users
コード例 #12
0
def test_add_review(in_memory_repo):
    user = User('Dave', '123456789')
    in_memory_repo.add_user(user)
    movie_1 = in_memory_repo.get_movie_by_id(1)
    #review_1 = Review(user, movie_1, "Good!", 8.8)
    review_1 = make_review(user, movie_1, "Good!")
    in_memory_repo.add_review(review_1)
    assert len(in_memory_repo.get_reviews()) == 4
コード例 #13
0
def add_user(user_name, password, repo: AbstractRepository):
    user = repo.get_user(user_name.lower())
    if user is not None:
        raise NameNotUniqueException

    password_hash = generate_password_hash(password)

    user = User(user_name, password_hash)
    repo.add_user(user)
コード例 #14
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)  # 不知道这个 function在哪 import?
    # Create and store the new User, with password encrypted.
    user = User(username, password_hash)
    repo.add_user(user)
コード例 #15
0
    def read_csv_file(self):
        with open(self.__file_name, mode='r', encoding='utf-8-sig') as csvfile:
            user_file_reader = csv.DictReader(csvfile)

            index = 0
            for row in user_file_reader:
                user_name = row['user_name']
                password = generate_password_hash(row['password'])
                user = User(user_name, password)
                if user not in self.dataset_of_users:
                    self.dataset_of_users.append(user)
                index += 1
コード例 #16
0
def load_users(data_path: str, repo: MemoryRepository):
    filename = os.path.join(data_path, 'users.csv')
    with open(filename, mode='r', encoding='utf-8-sig') as csvfile:
        user_file_reader = csv.DictReader(csvfile)
        users = dict()
        for row in user_file_reader:
            username = row['username']
            password = generate_password_hash(row['password'])
            user = User(username, password)
            repo.add_user(user)
            user_id = row['id']
            users[user_id] = user
    return users
コード例 #17
0
ファイル: test_services.py プロジェクト: nbel113/CS235-A3
def test_can_add_review(memory_repo):
    new_username = "******"
    new_password = "******"
    user = User(new_username, new_password)
    memory_repo.add_user(user)

    review_movie_title = "Star Trek"
    review_movie = memory_repo.get_movie(review_movie_title)
    review_text = "Not as good as the original series"
    review_score = 6
    review = Review(review_movie, review_text, review_score)

    review_services.add_review(user, review)
    assert review in user.reviews
コード例 #18
0
ファイル: test_services.py プロジェクト: nbel113/CS235-A3
def test_can_delete_review(memory_repo):
    new_username = "******"
    new_password = "******"
    user = User(new_username, new_password)
    memory_repo.add_user(user)

    review_movie_title = "Star Trek"
    review_movie = memory_repo.get_movie(review_movie_title)
    review_text = "Not as good as the original series"
    review_rating = 6
    review = Review(review_movie, review_text, review_rating)

    review_services.add_review(user, review)
    review_services.delete_review(new_username, review, memory_repo)

    assert review not in review_services.get_reviews_from_user(
        new_username, memory_repo)
コード例 #19
0
ファイル: test_services.py プロジェクト: nbel113/CS235-A3
def test_can_get_review_by_user_and_id(memory_repo):
    new_username = "******"
    new_password = "******"
    user = User(new_username, new_password)
    memory_repo.add_user(user)

    review_movie_title = "Star Trek"
    review_movie = memory_repo.get_movie(review_movie_title)
    review_text = "Not as good as the original series"
    review_score = 6
    review = Review(review_movie, review_text, review_score)

    session_user_name = new_username
    review_id = review.review_id

    # Call the service layer to add the comment.
    review_services.add_review(user, review)
    a = review_services.get_review_by_user_and_id(session_user_name, review_id,
                                                  memory_repo)

    assert review is a
コード例 #20
0
def test_repo_can_retrieve_review_count(memory_repo):
    new_username = "******"
    new_password = "******"
    user = User(new_username, new_password)
    memory_repo.add_user(user)

    review_movie_title_1 = "Star Trek"
    review_movie_1 = memory_repo.get_review(review_movie_title_1)
    review_text_1 = "Not as good as the original series"
    review_score_1 = 6
    review1 = Review(review_movie_1, review_text_1, review_score_1)

    review_movie_title_2 = "Split"
    review_movie_2 = memory_repo.get_review(review_movie_title_2)
    review_text_2 = "Pretty good"
    review_score_2 = 8
    review2 = Review(review_movie_2, review_text_2, review_score_2)

    memory_repo.add_review(user, review1)
    memory_repo.add_review(user, review2)

    assert len(memory_repo.get_all_reviews()) == 2
コード例 #21
0
ファイル: test_services.py プロジェクト: nbel113/CS235-A3
def test_can_edit_review_change_none(memory_repo):
    new_username = "******"
    new_password = "******"
    user = User(new_username, new_password)
    memory_repo.add_user(user)

    review_movie_title = "Star Trek"
    review_movie = memory_repo.get_movie(review_movie_title)
    review_text = "Not as good as the original series"
    review_rating = 6
    review = Review(review_movie, review_text, review_rating)

    new_review_movie_title = None
    new_review_movie = memory_repo.get_movie(new_review_movie_title)
    new_review_text = ""
    new_review_rating = None
    new_review = TempReview(new_review_movie, new_review_text,
                            new_review_rating)

    review_services.edit_review(review, new_review)
    assert review.movie == review_movie
    assert review.review_text == review_text
    assert review.rating == review_rating
コード例 #22
0
def test_repository_can_retrieve_user_watchlist(in_memory_repo):
    user = User("Dave", '123456789')
    movie = Movie("Moana", 2016)
    in_memory_repo.add_user(user)
    in_memory_repo.add_user_watch_list(user, movie)
    assert movie in in_memory_repo.get_user_watch_list(user)
コード例 #23
0
def test_repository_can_retrieve_user_watched_movies(in_memory_repo):
    user = User("Dave", '123456789')
    movie = Movie("Moana", 2016)
    in_memory_repo.add_user(user)
    in_memory_repo.add_user_watched_movie(user, movie)
    assert in_memory_repo.get_user_watched_movies(user) == [movie]
コード例 #24
0
def test_repository_can_add_a_user(in_memory_repo):
    user = User("Dave", '123456789')
    in_memory_repo.add_user(user)

    assert in_memory_repo.get_user("dave") is user
コード例 #25
0
ファイル: review_services.py プロジェクト: nbel113/CS235-A2
def add_review(user: User, review: Review):
    if user is None:
        raise UnknownUserException
    if (review not in user.reviews):
        user.add_review(review)
コード例 #26
0
def test_repo_can_retrieve_a_user(memory_repo):
    user = User('qwerty', '123Qweasd')
    memory_repo.add_user(user)
    retrieve_user = memory_repo.get_user('qwerty')
    assert retrieve_user == User('qwerty', '123Qweasd')
コード例 #27
0
def test_repository_does_not_retrieve_a_movie_in_empty_watchlist(
        in_memory_repo):
    user = User("Dave", '123456789')
    movie = Movie("Moana", 2016)
    in_memory_repo.add_user(user)
    assert in_memory_repo.get_user_watch_list(user).size() == 0
コード例 #28
0
def user():
    return User('piggyyo', '1234567890')
コード例 #29
0
def test_repository_can_retrieve_a_user(in_memory_repo):
    user = in_memory_repo.get_user('fmercury')
    assert user == User('fmercury', '8734gfe2058v')
コード例 #30
0
def test_repo_can_add_a_user(memory_repo):
    user = User('qwerty', '123Qweasd')
    memory_repo.add_user(user)

    assert memory_repo.get_user('qwerty') is user
    assert user in memory_repo.get_all_users()