From e4d38671fec0f81a7341ee2a043dedfddf9b031f Mon Sep 17 00:00:00 2001 From: Ashley Benson Date: Fri, 25 Mar 2022 12:00:44 -0700 Subject: [PATCH 1/2] Project Done --- tests/test_wave_01.py | 24 ++--- tests/test_wave_02.py | 8 +- tests/test_wave_03.py | 10 +- tests/test_wave_04.py | 4 +- tests/test_wave_05.py | 12 +-- viewing_party/party.py | 204 ++++++++++++++++++++++++++++++++++++++++- 6 files changed, 231 insertions(+), 31 deletions(-) diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index c033af09f..233f40bb7 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -4,7 +4,7 @@ from viewing_party.party import * from tests.test_constants import * -@pytest.mark.skip() +#@pytest.mark.skip() def test_create_successful_movie(): # Arrange movie_title = MOVIE_TITLE_1 @@ -15,11 +15,11 @@ def test_create_successful_movie(): new_movie = create_movie(movie_title, genre, rating) # Assert - assert new_movie["title"] is MOVIE_TITLE_1 - assert new_movie["genre"] is GENRE_1 + assert new_movie["title"] == MOVIE_TITLE_1 + assert new_movie["genre"] == GENRE_1 assert new_movie["rating"] == pytest.approx(RATING_1) -@pytest.mark.skip() +#@pytest.mark.skip() def test_create_no_title_movie(): # Arrange movie_title = None @@ -32,7 +32,7 @@ def test_create_no_title_movie(): # Assert assert new_movie is None -@pytest.mark.skip() +#@pytest.mark.skip() def test_create_no_genre_movie(): # Arrange movie_title = "Title A" @@ -45,7 +45,7 @@ def test_create_no_genre_movie(): # Assert assert new_movie is None -@pytest.mark.skip() +##@pytest.mark.skip() def test_create_no_rating_movie(): # Arrange movie_title = "Title A" @@ -58,7 +58,7 @@ def test_create_no_rating_movie(): # Assert assert new_movie is None -@pytest.mark.skip() +#@pytest.mark.skip() def test_adds_movie_to_user_watched(): # Arrange movie = { @@ -74,12 +74,12 @@ def test_adds_movie_to_user_watched(): updated_data = add_to_watched(user_data, movie) # Assert - assert len(updated_data["watched"]) is 1 + assert len(updated_data["watched"]) == 1 assert updated_data["watched"][0]["title"] is MOVIE_TITLE_1 assert updated_data["watched"][0]["genre"] is GENRE_1 assert updated_data["watched"][0]["rating"] is RATING_1 -@pytest.mark.skip() +#@pytest.mark.skip() def test_adds_movie_to_user_watchlist(): # Arrange movie = { @@ -100,7 +100,7 @@ def test_adds_movie_to_user_watchlist(): assert updated_data["watchlist"][0]["genre"] is GENRE_1 assert updated_data["watchlist"][0]["rating"] is RATING_1 -@pytest.mark.skip() +#@pytest.mark.skip() def test_moves_movie_from_watchlist_to_empty_watched(): # Arrange janes_data = { @@ -123,7 +123,7 @@ def test_moves_movie_from_watchlist_to_empty_watched(): # ****** Add assertions here to test that the correct movie was added to "watched" ********** # ******************************************************************************************* -@pytest.mark.skip() +#@pytest.mark.skip() def test_moves_movie_from_watchlist_to_watched(): # Arrange movie_to_watch = HORROR_1 @@ -146,7 +146,7 @@ def test_moves_movie_from_watchlist_to_watched(): # ****** Add assertions here to test that the correct movie was added to "watched" ********** # ******************************************************************************************* -@pytest.mark.skip() +#@pytest.mark.skip() def test_does_nothing_if_movie_not_in_watchlist(): # Arrange movie_to_watch = HORROR_1 diff --git a/tests/test_wave_02.py b/tests/test_wave_02.py index 3a588299e..36b504008 100644 --- a/tests/test_wave_02.py +++ b/tests/test_wave_02.py @@ -2,7 +2,7 @@ from viewing_party.party import * from tests.test_constants import * -@pytest.mark.skip() +#@pytest.mark.skip() def test_calculates_watched_average_rating(): # Arrange janes_data = clean_wave_2_data() @@ -14,7 +14,7 @@ def test_calculates_watched_average_rating(): assert average == pytest.approx(3.58333) assert janes_data == clean_wave_2_data() -@pytest.mark.skip() +#@pytest.mark.skip() def test_empty_watched_average_rating_is_zero(): # Arrange janes_data = { @@ -27,7 +27,7 @@ def test_empty_watched_average_rating_is_zero(): # Assert assert average == pytest.approx(0.0) -@pytest.mark.skip() +#@pytest.mark.skip() def test_most_watched_genre(): # Arrange janes_data = clean_wave_2_data() @@ -39,7 +39,7 @@ def test_most_watched_genre(): assert popular_genre == "Fantasy" assert janes_data == clean_wave_2_data() -@pytest.mark.skip() +#@pytest.mark.skip() def test_genre_is_None_if_empty_watched(): # Arrange janes_data = { diff --git a/tests/test_wave_03.py b/tests/test_wave_03.py index 7c42a63c4..ea5170ab9 100644 --- a/tests/test_wave_03.py +++ b/tests/test_wave_03.py @@ -2,7 +2,7 @@ from viewing_party.party import * from tests.test_constants import * -@pytest.mark.skip() +#@pytest.mark.skip() def test_my_unique_movies(): # Arrange amandas_data = clean_wave_3_data() @@ -16,7 +16,7 @@ def test_my_unique_movies(): assert INTRIGUE_2 in amandas_unique_movies assert amandas_data == clean_wave_3_data() -@pytest.mark.skip() +#@pytest.mark.skip() def test_my_not_unique_movies(): # Arrange amandas_data = clean_wave_3_data() @@ -28,7 +28,7 @@ def test_my_not_unique_movies(): # Arrange assert len(amandas_unique_movies) == 0 -@pytest.mark.skip() +#@pytest.mark.skip() def test_friends_unique_movies(): # Arrange amandas_data = clean_wave_3_data() @@ -43,7 +43,7 @@ def test_friends_unique_movies(): assert FANTASY_4 in friends_unique_movies assert amandas_data == clean_wave_3_data() -@pytest.mark.skip() +#@pytest.mark.skip() def test_friends_unique_movies_not_duplicated(): # Arrange amandas_data = clean_wave_3_data() @@ -59,7 +59,7 @@ def test_friends_unique_movies_not_duplicated(): # ****** Add assertions here to test that the correct movies are in friends_unique_movies ********** # ************************************************************************************************** -@pytest.mark.skip() +#@pytest.mark.skip() def test_friends_not_unique_movies(): # Arrange amandas_data = { diff --git a/tests/test_wave_04.py b/tests/test_wave_04.py index 72888410f..8bb8958d4 100644 --- a/tests/test_wave_04.py +++ b/tests/test_wave_04.py @@ -2,7 +2,7 @@ from viewing_party.party import * from tests.test_constants import * -@pytest.mark.skip() +#@pytest.mark.skip() def test_get_available_friend_rec(): # Arrange amandas_data = clean_wave_4_data() @@ -16,7 +16,7 @@ def test_get_available_friend_rec(): assert FANTASY_4b in recommendations assert amandas_data == clean_wave_4_data() -@pytest.mark.skip() +#@pytest.mark.skip() def test_no_available_friend_recs(): # Arrange amandas_data = { diff --git a/tests/test_wave_05.py b/tests/test_wave_05.py index 8ce5b57db..ff86e4f8f 100644 --- a/tests/test_wave_05.py +++ b/tests/test_wave_05.py @@ -2,7 +2,7 @@ from viewing_party.party import * from tests.test_constants import * -@pytest.mark.skip() +#@pytest.mark.skip() def test_new_genre_rec(): # Arrange sonyas_data = clean_wave_5_data() @@ -17,7 +17,7 @@ def test_new_genre_rec(): assert FANTASY_4b in recommendations assert sonyas_data == clean_wave_5_data() -@pytest.mark.skip() +#@pytest.mark.skip() def test_new_genre_rec_from_empty_watched(): # Arrange sonyas_data = { @@ -38,7 +38,7 @@ def test_new_genre_rec_from_empty_watched(): # Assert assert len(recommendations) == 0 -@pytest.mark.skip() +#@pytest.mark.skip() def test_new_genre_rec_from_empty_friends(): # Arrange sonyas_data = { @@ -57,7 +57,7 @@ def test_new_genre_rec_from_empty_friends(): # ****** Complete the Act and Assert Portions of theis tests ********** # ********************************************************************* -@pytest.mark.skip() +#@pytest.mark.skip() def test_unique_rec_from_favorites(): # Arrange sonyas_data = clean_wave_5_data() @@ -71,7 +71,7 @@ def test_unique_rec_from_favorites(): assert INTRIGUE_2b in recommendations assert sonyas_data == clean_wave_5_data() -@pytest.mark.skip() +#@pytest.mark.skip() def test_unique_from_empty_favorites(): # Arrange sonyas_data = { @@ -92,7 +92,7 @@ def test_unique_from_empty_favorites(): # Assert assert len(recommendations) == 0 -@pytest.mark.skip() +#@pytest.mark.skip() def test_new_rec_from_empty_friends(): # Arrange sonyas_data = { diff --git a/viewing_party/party.py b/viewing_party/party.py index 6d34a6b5f..543c244ab 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -1,23 +1,223 @@ # ------------- WAVE 1 -------------------- def create_movie(title, genre, rating): - pass + movie_dict ={} + if title and genre and rating: + movie_dict["title"] = title + movie_dict["genre"] = genre + movie_dict["rating"] = rating + return movie_dict + else: + return None + + +def add_to_watched(user_data, movie): + watched_movies = user_data + watched_movies["watched"].append(movie) + return watched_movies + + +def add_to_watchlist(user_data, movie): + watch_list = user_data + watch_list["watchlist"].append(movie) + return watch_list + + +def watch_movie(user_data, movie_title): + update_watched = user_data + for movie in user_data["watchlist"]: + if movie_title in movie["title"]: + update_watched["watched"].append(movie) + update_watched["watchlist"].remove(movie) + print(update_watched) + return update_watched # ----------------------------------------- # ------------- WAVE 2 -------------------- # ----------------------------------------- +def get_watched_avg_rating(user_data): + + users_data = user_data + avg_values = 0 + counter = 0 + movies = users_data["watched"] + if movies: + for items in users_data.values(): + for num in items: + avg_values += num["rating"] + counter += 1 + result = avg_values/counter + return result + else: + return 0 + +# for items in users_data.values(): is'nt this the same as "movies"? +# def get_most_watched_genre(user_data): +# users_data = user_data +# data = user_data.values() +# list = [] +# movies = users_data["watched"] + +# if movies: +# for item in data: +# for i in item: +# list.append(i["genre"]) +# most_commom = max(set(list), key = list.count) +# return most_commom +# else: +# return most_commom + + +def get_most_watched_genre(user_data): + + watched_genres = {} + watched_movies = user_data["watched"] + + if not watched_movies: + return None + + for movie in watched_movies: + if movie["genre"] in watched_genres: + watched_genres[movie["genre"]] += 1 + else: + watched_genres[movie["genre"]] = 1 + list_of_freq = list(watched_genres.values()) + list_of_freq.sort() + most_watched_value = list_of_freq[-1] + + for genre in watched_genres: + if watched_genres[genre] == most_watched_value: + most_watched_genre = genre + return most_watched_genre + +def friends_watched(user_data): + + users_data = user_data + my_movies = users_data["watched"] + friends = users_data["friends"] + friends_watched_movies = [] + if my_movies: + for movies in friends: + for movie in movies["watched"]: + if movie not in friends_watched_movies: + friends_watched_movies.append(movie) + return friends_watched_movies + else: + return friends_watched_movies # ----------------------------------------- # ------------- WAVE 3 -------------------- # ----------------------------------------- - +def get_unique_watched(user_data): + users_data = user_data + my_movies = users_data["watched"] + friends_watched_movies = friends_watched(user_data) + unique_list = [] + + + if my_movies: + for movie in my_movies: + if movie not in friends_watched_movies: + unique_list.append(movie) + return unique_list + else: + return unique_list + +def get_friends_unique_watched(user_data): + + users_data = user_data + your_watched_movies = users_data["watched"] + friends_watched_movies = friends_watched(user_data) + friends_unique_watched = [] + + for movie in friends_watched_movies: + if movie not in your_watched_movies: + friends_unique_watched.append(movie) + return friends_unique_watched + # ----------------------------------------- # ------------- WAVE 4 -------------------- # ----------------------------------------- +def get_available_recs(user_data): + users_data = user_data + recommended_movies = [] + friends_unique_watched = get_friends_unique_watched(user_data) + + for movie in friends_unique_watched: + if movie["host"] in users_data["subscriptions"]: + recommended_movies.append(movie) + return recommended_movies + + +def get_new_rec_by_genre(user_data): + + users_data = user_data + new_rec_by_genre = [] + most_watched_genre = get_most_watched_genre(users_data) + friends_unique_watched = get_friends_unique_watched(users_data) + + for movie in friends_unique_watched: + if movie["genre"] == most_watched_genre: + new_rec_by_genre.append(movie) + + return new_rec_by_genre + + +def get_rec_from_favorites(user_data): + + users_data = user_data + favorites = users_data["favorites"] + recommend = [] + friends_watched_movies = friends_watched(users_data) + + for movie in favorites: + if movie not in friends_watched_movies: + recommend.append(movie) + return recommend + # ----------------------------------------- # ------------- WAVE 5 -------------------- # ----------------------------------------- +def get_new_rec_by_genre(user_data): + + users_data = user_data + new_rec_by_genre = [] + most_watched_genre = get_most_watched_genre(users_data) + friends_unique_watched = get_friends_unique_watched(users_data) + + for movie in friends_unique_watched: + if movie["genre"] == most_watched_genre: + new_rec_by_genre.append(movie) + return new_rec_by_genre + + +def get_rec_from_favorites(user_data): + + users_data = user_data + favorites = users_data["favorites"] + recommend = [] + friends_watched_movies = friends_watched(users_data) + + for movie in favorites: + if movie not in friends_watched_movies: + recommend.append(movie) + return recommend + + + + + + + + + + + + + + + From 123c47f38191bb2f3ac4a70eb3638fd907dd0de8 Mon Sep 17 00:00:00 2001 From: Ashley Benson Date: Thu, 31 Mar 2022 20:31:51 -0700 Subject: [PATCH 2/2] Updates with assertions --- tests/test_wave_01.py | 29 ++++++++++++++++++++++++++--- tests/test_wave_03.py | 2 ++ tests/test_wave_05.py | 6 ++++++ 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index 233f40bb7..5fa12760d 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -123,6 +123,31 @@ def test_moves_movie_from_watchlist_to_empty_watched(): # ****** Add assertions here to test that the correct movie was added to "watched" ********** # ******************************************************************************************* + #Ashley's Test + def test_moves_movie_from_watchlist_to_prefilled_list(): + # Arrange + maddies_data = { + "watchlist": [{ + "title": MOVIE_TITLE_1, + "genre": GENRE_1, + "rating": RATING_1 + }], + "watched": [{ + "title": MOVIE_TITLE_1, + "genre": GENRE_1, + "rating": RATING_1 + }] + } + + # Act + updated_data = watch_movie(maddies_data, MOVIE_TITLE_1) + + # Assert + assert len(updated_data["watchlist"]) is 0 + assert len(updated_data["watched"]) is 2 + + + #@pytest.mark.skip() def test_moves_movie_from_watchlist_to_watched(): # Arrange @@ -142,9 +167,7 @@ def test_moves_movie_from_watchlist_to_watched(): assert len(updated_data["watchlist"]) is 1 assert len(updated_data["watched"]) is 2 - # ******************************************************************************************* - # ****** Add assertions here to test that the correct movie was added to "watched" ********** - # ******************************************************************************************* + #@pytest.mark.skip() def test_does_nothing_if_movie_not_in_watchlist(): diff --git a/tests/test_wave_03.py b/tests/test_wave_03.py index ea5170ab9..5eb337314 100644 --- a/tests/test_wave_03.py +++ b/tests/test_wave_03.py @@ -54,6 +54,8 @@ def test_friends_unique_movies_not_duplicated(): # Arrange assert len(friends_unique_movies) == 3 + #Ashley's assertion + assert INTRIGUE_3 in amandas_data["friends"][0]["watched"] # ************************************************************************************************* # ****** Add assertions here to test that the correct movies are in friends_unique_movies ********** diff --git a/tests/test_wave_05.py b/tests/test_wave_05.py index ff86e4f8f..a59df8ec0 100644 --- a/tests/test_wave_05.py +++ b/tests/test_wave_05.py @@ -53,6 +53,12 @@ def test_new_genre_rec_from_empty_friends(): ] } + # Ashley's Act + recommendations = get_new_rec_by_genre(sonyas_data) + # Ashley's Assert + assert len(recommendations) == 0 + + # ********************************************************************* # ****** Complete the Act and Assert Portions of theis tests ********** # *********************************************************************