From 50fd8611a5091be65cf4cf1ee87880434707c73e Mon Sep 17 00:00:00 2001 From: Becca Date: Sun, 24 Jan 2021 12:52:33 -0800 Subject: [PATCH 01/46] move wave1 and wave2 to beccaelenzil repo --- viewing_party/main.py | 100 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/viewing_party/main.py b/viewing_party/main.py index e69de29bb..d2f232796 100644 --- a/viewing_party/main.py +++ b/viewing_party/main.py @@ -0,0 +1,100 @@ +#Wave 1 + +def create_movie(title, genre, rating): + if title and genre and rating: + movie = { + "title": title, + "genre": genre, + "rating": rating + } + return movie + +def add_to_watched(user_data, movie): + user_data["watched"].append(movie) + return user_data + +def add_to_watchlist(user_data, movie): + user_data["watchlist"].append(movie) + return user_data + +def watch_movie(user_data, title): + for movie in user_data["watchlist"]: + if movie["title"] == title: + user_data["watchlist"].remove(movie) + user_data["watched"].append(movie) + return user_data + +def get_watched_avg_rating(user_data): + total = 0 + movies = user_data["watched"] + n = len(movies) + + if n == 0: + return 0 + + for movie in movies: + total += movie["rating"] + + return total/n + +def calculate_genre_freq(user_data): + # make genre frequency hash + genre_freqs = {} + movies = user_data["watched"] + for movie in movies: + genre = movie['genre'] + try: + if genre_freqs[genre] == 0: + genre_freqs[genre] += 1 + except: + genre_freqs[genre] = 1 + + return genre_freqs + +def get_most_watched_genre(user_data): + + + movies = user_data["watched"] + + if movies == []: + return None + + genre_freqs = calculate_genre_freq(user_data) + + highest_freq = 0 + + # find most frequent + for genre in genre_freqs: + freq = genre_freqs[genre] + if freq > highest_freq: + most_frequent = genre + highest_freq = freq + + return most_frequent + +# janes_data = { +# "watched": [ +# { +# "title": "Title A", +# "genre": "Fantasy" +# }, +# { +# "title": "Title B", +# "genre": "Intrigue" +# }, +# { +# "title": "Title C", +# "genre": "Intrigue" +# }, +# { +# "title": "Title D", +# "genre": "Fantasy" +# }, +# { +# "title": "Title E", +# "genre": "Intrigue" +# }, +# ] +# } + +# get_most_watched_genre(janes_data) \ No newline at end of file From b2dc63d8833e98e2124b65491bf4be373481b677 Mon Sep 17 00:00:00 2001 From: Becca Date: Sun, 24 Jan 2021 12:55:08 -0800 Subject: [PATCH 02/46] wave 2 tests passing --- viewing_party/main.py | 34 ++++------------------------------ 1 file changed, 4 insertions(+), 30 deletions(-) diff --git a/viewing_party/main.py b/viewing_party/main.py index d2f232796..463bf3f74 100644 --- a/viewing_party/main.py +++ b/viewing_party/main.py @@ -44,7 +44,7 @@ def calculate_genre_freq(user_data): for movie in movies: genre = movie['genre'] try: - if genre_freqs[genre] == 0: + if genre_freqs[genre] != 0: genre_freqs[genre] += 1 except: genre_freqs[genre] = 1 @@ -59,8 +59,9 @@ def get_most_watched_genre(user_data): if movies == []: return None + #call helper function to get frequencies genre_freqs = calculate_genre_freq(user_data) - + print(genre_freqs) highest_freq = 0 # find most frequent @@ -70,31 +71,4 @@ def get_most_watched_genre(user_data): most_frequent = genre highest_freq = freq - return most_frequent - -# janes_data = { -# "watched": [ -# { -# "title": "Title A", -# "genre": "Fantasy" -# }, -# { -# "title": "Title B", -# "genre": "Intrigue" -# }, -# { -# "title": "Title C", -# "genre": "Intrigue" -# }, -# { -# "title": "Title D", -# "genre": "Fantasy" -# }, -# { -# "title": "Title E", -# "genre": "Intrigue" -# }, -# ] -# } - -# get_most_watched_genre(janes_data) \ No newline at end of file + return most_frequent \ No newline at end of file From 85ef1e43d9c48486c844fa0da8a4c143f4d5a080 Mon Sep 17 00:00:00 2001 From: Becca Date: Sun, 24 Jan 2021 13:26:15 -0800 Subject: [PATCH 03/46] get_unique_watched complete --- tests/test_wave_03.py | 6 +++--- viewing_party/main.py | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/tests/test_wave_03.py b/tests/test_wave_03.py index 11c85ad31..ca776b70b 100644 --- a/tests/test_wave_03.py +++ b/tests/test_wave_03.py @@ -95,7 +95,7 @@ def test_my_not_unique_movies(): # Arrange assert len(amandas_unique_movies) is 0 - +@pytest.mark.skip(reason="no way of currently testing this") def test_friends_unique_movies(): # Arrange amandas_data = { @@ -145,7 +145,7 @@ def test_friends_unique_movies(): assert {"title": "Title D"} in friends_unique_movies assert {"title": "Title E"} in friends_unique_movies - +@pytest.mark.skip(reason="no way of currently testing this") def test_friends_unique_movies_not_duplicated(): # Arrange amandas_data = { @@ -183,7 +183,7 @@ def test_friends_unique_movies_not_duplicated(): assert {"title": "Title B"} in friends_unique_movies assert {"title": "Title C"} in friends_unique_movies - +@pytest.mark.skip(reason="no way of currently testing this") def test_friends_not_unique_movies(): # Arrange amandas_data = { diff --git a/viewing_party/main.py b/viewing_party/main.py index 463bf3f74..f6aeb1fc8 100644 --- a/viewing_party/main.py +++ b/viewing_party/main.py @@ -1,4 +1,6 @@ -#Wave 1 +# ----------------------------------------- +# ------------- WAVE 1 -------------------- +# ----------------------------------------- def create_movie(title, genre, rating): if title and genre and rating: @@ -24,6 +26,10 @@ def watch_movie(user_data, title): user_data["watched"].append(movie) return user_data +# ----------------------------------------- +# ------------- WAVE 2 -------------------- +# ----------------------------------------- + def get_watched_avg_rating(user_data): total = 0 movies = user_data["watched"] @@ -71,4 +77,32 @@ def get_most_watched_genre(user_data): most_frequent = genre highest_freq = freq - return most_frequent \ No newline at end of file + return most_frequent + +# ----------------------------------------- +# ------------- WAVE 3 -------------------- +# ----------------------------------------- + +def get_unique_watched(user_data): + user_movies = user_data['watched'] + user_unique_movie_titles = [] + friend_movie_titles = [] + friends_watched = user_data['friends'] + + #get friends movie titles + for watched_dict in friends_watched: + for movie in watched_dict['watched']: + if movie['title'] not in friend_movie_titles: + friend_movie_titles.append(movie['title']) + + #check for unique titles + for movie in user_movies: + if movie['title'] not in friend_movie_titles: + user_unique_movie_titles.append({'title': movie['title']}) + + return user_unique_movie_titles + + +# ----------------------------------------- +# ------------- WAVE 4 -------------------- +# ----------------------------------------- \ No newline at end of file From cf5d2a2d4a7e0569bb411789f0da9020d6e262f5 Mon Sep 17 00:00:00 2001 From: Becca Date: Sun, 24 Jan 2021 13:32:00 -0800 Subject: [PATCH 04/46] wave 3 complete --- tests/test_wave_03.py | 6 +++--- viewing_party/main.py | 25 ++++++++++++++++++++----- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/tests/test_wave_03.py b/tests/test_wave_03.py index ca776b70b..8860c4ed9 100644 --- a/tests/test_wave_03.py +++ b/tests/test_wave_03.py @@ -95,7 +95,7 @@ def test_my_not_unique_movies(): # Arrange assert len(amandas_unique_movies) is 0 -@pytest.mark.skip(reason="no way of currently testing this") +#@pytest.mark.skip(reason="no way of currently testing this") def test_friends_unique_movies(): # Arrange amandas_data = { @@ -145,7 +145,7 @@ def test_friends_unique_movies(): assert {"title": "Title D"} in friends_unique_movies assert {"title": "Title E"} in friends_unique_movies -@pytest.mark.skip(reason="no way of currently testing this") +#@pytest.mark.skip(reason="no way of currently testing this") def test_friends_unique_movies_not_duplicated(): # Arrange amandas_data = { @@ -183,7 +183,7 @@ def test_friends_unique_movies_not_duplicated(): assert {"title": "Title B"} in friends_unique_movies assert {"title": "Title C"} in friends_unique_movies -@pytest.mark.skip(reason="no way of currently testing this") +#@pytest.mark.skip(reason="no way of currently testing this") def test_friends_not_unique_movies(): # Arrange amandas_data = { diff --git a/viewing_party/main.py b/viewing_party/main.py index f6aeb1fc8..a7baf81ef 100644 --- a/viewing_party/main.py +++ b/viewing_party/main.py @@ -83,18 +83,22 @@ def get_most_watched_genre(user_data): # ------------- WAVE 3 -------------------- # ----------------------------------------- -def get_unique_watched(user_data): - user_movies = user_data['watched'] - user_unique_movie_titles = [] +def get_friends_movie_titles(user_data): friend_movie_titles = [] - friends_watched = user_data['friends'] #get friends movie titles - for watched_dict in friends_watched: + for watched_dict in user_data['friends']: for movie in watched_dict['watched']: if movie['title'] not in friend_movie_titles: friend_movie_titles.append(movie['title']) + return friend_movie_titles + +def get_unique_watched(user_data): + user_movies = user_data['watched'] + user_unique_movie_titles = [] + friend_movie_titles = get_friends_movie_titles(user_data) + #check for unique titles for movie in user_movies: if movie['title'] not in friend_movie_titles: @@ -102,6 +106,17 @@ def get_unique_watched(user_data): return user_unique_movie_titles + +def get_friends_unique_watched(user_data): + friend_movie_titles = get_friends_movie_titles(user_data) + unique_friend_unique_movie_titles = [] + + for title in friend_movie_titles: + if {'title': title} not in user_data['watched']: + unique_friend_unique_movie_titles.append({'title': title}) + + return unique_friend_unique_movie_titles + # ----------------------------------------- # ------------- WAVE 4 -------------------- From 69f42b838a6d833f723b3556dba60988cee7d9a9 Mon Sep 17 00:00:00 2001 From: Becca Date: Sun, 24 Jan 2021 14:13:49 -0800 Subject: [PATCH 05/46] wave 3 refactor to not get list of titles but list of movie dictionaries --- viewing_party/main.py | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/viewing_party/main.py b/viewing_party/main.py index a7baf81ef..40da290d5 100644 --- a/viewing_party/main.py +++ b/viewing_party/main.py @@ -83,41 +83,51 @@ def get_most_watched_genre(user_data): # ------------- WAVE 3 -------------------- # ----------------------------------------- -def get_friends_movie_titles(user_data): - friend_movie_titles = [] +def get_friends_movies(user_data): + friend_movies = [] #get friends movie titles for watched_dict in user_data['friends']: for movie in watched_dict['watched']: - if movie['title'] not in friend_movie_titles: - friend_movie_titles.append(movie['title']) + if movie not in friend_movies: + friend_movies.append(movie) - return friend_movie_titles + return friend_movies def get_unique_watched(user_data): user_movies = user_data['watched'] user_unique_movie_titles = [] - friend_movie_titles = get_friends_movie_titles(user_data) + friend_movies = get_friends_movies(user_data) #check for unique titles for movie in user_movies: - if movie['title'] not in friend_movie_titles: - user_unique_movie_titles.append({'title': movie['title']}) + if movie not in friend_movies: + user_unique_movie_titles.append(movie) return user_unique_movie_titles def get_friends_unique_watched(user_data): - friend_movie_titles = get_friends_movie_titles(user_data) - unique_friend_unique_movie_titles = [] + friend_movies = get_friends_movies(user_data) + unique_friend_movies = [] - for title in friend_movie_titles: - if {'title': title} not in user_data['watched']: - unique_friend_unique_movie_titles.append({'title': title}) + for movie in friend_movies: + if {'title': movie['title']} not in user_data['watched']: + unique_friend_movies.append(movie) - return unique_friend_unique_movie_titles + return unique_friend_movies # ----------------------------------------- # ------------- WAVE 4 -------------------- -# ----------------------------------------- \ No newline at end of file +# ----------------------------------------- + +# def get_available_recs(user_data): + +# unique_friend_movies = get_friends_unique_watched(user_data) + +# # for title in friend_movie_titles: +# # if {'title': title} not in user_data['watched']: +# # unique_friend_unique_movie_titles.append({'title': title}) + +# # for movie in user_has_not_watched: From 360fd744dba1bfb35325791df402e81132ecd45c Mon Sep 17 00:00:00 2001 From: Becca Date: Sun, 24 Jan 2021 14:15:34 -0800 Subject: [PATCH 06/46] completed wave04 --- viewing_party/main.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/viewing_party/main.py b/viewing_party/main.py index 40da290d5..e2e3cccb0 100644 --- a/viewing_party/main.py +++ b/viewing_party/main.py @@ -122,12 +122,14 @@ def get_friends_unique_watched(user_data): # ------------- WAVE 4 -------------------- # ----------------------------------------- -# def get_available_recs(user_data): +def get_available_recs(user_data): -# unique_friend_movies = get_friends_unique_watched(user_data) + unique_friend_movies = get_friends_unique_watched(user_data) + recs = [] -# # for title in friend_movie_titles: -# # if {'title': title} not in user_data['watched']: -# # unique_friend_unique_movie_titles.append({'title': title}) + for movie in unique_friend_movies: + if movie['host'] in user_data['subscriptions']: + recs.append(movie) + + return recs -# # for movie in user_has_not_watched: From 06e17572179270f4411e64ccf0eed943338d6785 Mon Sep 17 00:00:00 2001 From: Becca Date: Sun, 24 Jan 2021 14:28:25 -0800 Subject: [PATCH 07/46] all tests pass --- viewing_party/main.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/viewing_party/main.py b/viewing_party/main.py index e2e3cccb0..7a6f0ccd7 100644 --- a/viewing_party/main.py +++ b/viewing_party/main.py @@ -133,3 +133,29 @@ def get_available_recs(user_data): return recs +# ----------------------------------------- +# ------------- WAVE 5 -------------------- +# ----------------------------------------- + +def get_new_rec_by_genre(user_data): + most_freq_genre = get_most_watched_genre(user_data) + unique_friend_movies = get_friends_unique_watched(user_data) + + recs = [] + + for movie in unique_friend_movies: + if movie['genre'] == most_freq_genre: + recs.append(movie) + + return recs + +def get_rec_from_favorites(user_data): + + movies = get_unique_watched(user_data) + recs = [] + + for movie in movies: + if movie in user_data['favorites']: + recs.append(movie) + + return recs From 08b4d731035c4128cbbee71e1b85eb4e9a3eb0d4 Mon Sep 17 00:00:00 2001 From: Becca Date: Wed, 24 Mar 2021 15:17:36 -0700 Subject: [PATCH 08/46] fix --- .vscode/settings.json | 8 ++++++++ viewing_party/main.py | 18 ++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..60400e381 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,8 @@ +{ + "python.testing.pytestArgs": [ + "tests" + ], + "python.testing.unittestEnabled": false, + "python.testing.nosetestsEnabled": false, + "python.testing.pytestEnabled": true +} \ No newline at end of file diff --git a/viewing_party/main.py b/viewing_party/main.py index 7a6f0ccd7..702da17e7 100644 --- a/viewing_party/main.py +++ b/viewing_party/main.py @@ -47,13 +47,23 @@ def calculate_genre_freq(user_data): # make genre frequency hash genre_freqs = {} movies = user_data["watched"] + #genre_freq = defaultdict(lambda: 0) + for movie in movies: genre = movie['genre'] - try: - if genre_freqs[genre] != 0: - genre_freqs[genre] += 1 - except: + if genre not in genre_freqs.keys(): genre_freqs[genre] = 1 + else: + genre_freqs[genre] += 1 + + + + # genre = movie['genre'] + # try: + # if genre_freqs[genre] != 0: + # genre_freqs[genre] += 1 + # except: + # genre_freqs[genre] = 1 return genre_freqs From 626bb3421d6d3f9b2636bd57e8b9ad28c9906263 Mon Sep 17 00:00:00 2001 From: Becca Date: Wed, 24 Mar 2021 15:40:36 -0700 Subject: [PATCH 09/46] fix --- viewing_party/main.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/viewing_party/main.py b/viewing_party/main.py index 702da17e7..3eef84e55 100644 --- a/viewing_party/main.py +++ b/viewing_party/main.py @@ -55,9 +55,7 @@ def calculate_genre_freq(user_data): genre_freqs[genre] = 1 else: genre_freqs[genre] += 1 - - - + # genre = movie['genre'] # try: # if genre_freqs[genre] != 0: From a749aba4c677109a7d79186cc68fd4c69db8adbd Mon Sep 17 00:00:00 2001 From: Becca Date: Sun, 28 Mar 2021 17:10:15 -0700 Subject: [PATCH 10/46] reviewed --- .vscode/launch.json | 16 ++++++++++++++++ playground.py | 11 +++++++++++ temp.py | 36 ++++++++++++++++++++++++++++++++++++ tests/temp.py | 20 ++++++++++++++++++++ viewing_party/main.py | 2 +- 5 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 .vscode/launch.json create mode 100644 playground.py create mode 100644 temp.py create mode 100644 tests/temp.py diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 000000000..5dba21720 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,16 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + + { + "name": "Python: Current File", + "type": "python", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal" + } + ] +} \ No newline at end of file diff --git a/playground.py b/playground.py new file mode 100644 index 000000000..81ec56651 --- /dev/null +++ b/playground.py @@ -0,0 +1,11 @@ +from viewing_party.main import * + +# Arrange +movie_title = "Title A" +genre = "Horror" +rating = 3.5 + +# Act +new_movie = create_movie(movie_title, genre, rating) + +print(new_movie) \ No newline at end of file diff --git a/temp.py b/temp.py new file mode 100644 index 000000000..cd01854cc --- /dev/null +++ b/temp.py @@ -0,0 +1,36 @@ +def calculate_genre_freq(user_data): + #dictionary where the keys are the genre e.g. "fantasy" + #go through watch list and check if it's in + #if it's already in dictionary, add 1 to it + + # build a frequency map + # { + # "Intrigue": 3, + # "Fantasy": 2 + # "Comedy": 5, + # "Horrr": 2 + # } + #dictionary where the keys are the genre e.g. "fantasy" + genre_freq_dict = {} + watch_list = user_data["watched"] + for movie in watch_list: + genre = movie["genres"] + #go through watch list and check if that genre is already a key + #if it's already in dictionary, add 1 to it + if genre in genre_freq_dict.keys(): + genre_freq_dict[genre] += 1 + #otherwise we'll make an entry and give a value of 1 + else: + genre_freq_dict[genre] = 1 + + return genre_freq_dict + +def get_most_watched_genre(user_data): + # call calculate_genre_freq to get genre_freq_dict + # initalize highest to 0 + # iterate through the genre_freq_dict + # check if the value (genre_freq_dict[genre]) is higher than the current value stored in highest + # if it is assign highest_genre to current genre + # and replace highest with the freq + + # return highest_genre \ No newline at end of file diff --git a/tests/temp.py b/tests/temp.py new file mode 100644 index 000000000..42f2d499f --- /dev/null +++ b/tests/temp.py @@ -0,0 +1,20 @@ + +# iterate through the lists of movies the user has watched +#user_data["watched"] + +# if it's not in the friends list, append it to a new list + +# iterate through users_data["friends"], we can create a list of the movies the friends has watched +# <-- create a list that's the movies all the friends have watched + +friends_list = [] +for watched_dict in user_data["friends"]: + # some more nesting to pull out the friends' movies + if friend_movie not in friends_list: + friends_list.append(friend_movie) + + +movie_list = [] +for user_movie in user_data["watched"]: + if user_movie not in friends_list: + movie_list.append(user_movie) \ No newline at end of file diff --git a/viewing_party/main.py b/viewing_party/main.py index 3eef84e55..447c78897 100644 --- a/viewing_party/main.py +++ b/viewing_party/main.py @@ -55,7 +55,7 @@ def calculate_genre_freq(user_data): genre_freqs[genre] = 1 else: genre_freqs[genre] += 1 - + # genre = movie['genre'] # try: # if genre_freqs[genre] != 0: From e418342e4584eccba818f37a563afb48c2e9ac43 Mon Sep 17 00:00:00 2001 From: Becca Elenzil Date: Thu, 16 Sep 2021 13:11:14 -0700 Subject: [PATCH 11/46] demo commit --- play_tester.py | 12 ++++++++ playground.py | 22 +++++++++------ temp.py | 64 +++++++++++++++++++++--------------------- tests/test_wave_01.py | 3 +- viewing_party/main.py | 2 ++ viewing_party/party.py | 0 6 files changed, 62 insertions(+), 41 deletions(-) create mode 100644 play_tester.py create mode 100644 viewing_party/party.py diff --git a/play_tester.py b/play_tester.py new file mode 100644 index 000000000..3cce9cbb9 --- /dev/null +++ b/play_tester.py @@ -0,0 +1,12 @@ +# from viewing_party.main import * +from viewing_party.party import * + +# Arrange +movie_title = "Title A" +genre = "Horror" +rating = 3.5 + +# Act +new_movie = create_movie(movie_title, genre, rating) + +print(new_movie) diff --git a/playground.py b/playground.py index 81ec56651..6a57a5f88 100644 --- a/playground.py +++ b/playground.py @@ -1,11 +1,17 @@ -from viewing_party.main import * +all_genres = ['horror', 'comedy', 'indie', 'comedy'] +max(set(all_genres), key=all_genres.count) -# Arrange -movie_title = "Title A" -genre = "Horror" -rating = 3.5 +max = 0 +max_genre = None -# Act -new_movie = create_movie(movie_title, genre, rating) +for genre in set(all_genres): + count = 0 + for genre_item in all_genres: + if genre_item == genre: + count += 1 + if count > max: + max = count + max_genre = genre -print(new_movie) \ No newline at end of file +print(max) +print(max_genre) \ No newline at end of file diff --git a/temp.py b/temp.py index cd01854cc..72878f3e4 100644 --- a/temp.py +++ b/temp.py @@ -1,36 +1,36 @@ -def calculate_genre_freq(user_data): - #dictionary where the keys are the genre e.g. "fantasy" - #go through watch list and check if it's in - #if it's already in dictionary, add 1 to it +# def calculate_genre_freq(user_data): +# #dictionary where the keys are the genre e.g. "fantasy" +# #go through watch list and check if it's in +# #if it's already in dictionary, add 1 to it - # build a frequency map - # { - # "Intrigue": 3, - # "Fantasy": 2 - # "Comedy": 5, - # "Horrr": 2 - # } - #dictionary where the keys are the genre e.g. "fantasy" - genre_freq_dict = {} - watch_list = user_data["watched"] - for movie in watch_list: - genre = movie["genres"] - #go through watch list and check if that genre is already a key - #if it's already in dictionary, add 1 to it - if genre in genre_freq_dict.keys(): - genre_freq_dict[genre] += 1 - #otherwise we'll make an entry and give a value of 1 - else: - genre_freq_dict[genre] = 1 +# # build a frequency map +# # { +# # "Intrigue": 3, +# # "Fantasy": 2 +# # "Comedy": 5, +# # "Horrr": 2 +# # } +# #dictionary where the keys are the genre e.g. "fantasy" +# genre_freq_dict = {} +# watch_list = user_data["watched"] +# for movie in watch_list: +# genre = movie["genres"] +# #go through watch list and check if that genre is already a key +# #if it's already in dictionary, add 1 to it +# if genre in genre_freq_dict.keys(): +# genre_freq_dict[genre] += 1 +# #otherwise we'll make an entry and give a value of 1 +# else: +# genre_freq_dict[genre] = 1 - return genre_freq_dict +# return genre_freq_dict -def get_most_watched_genre(user_data): - # call calculate_genre_freq to get genre_freq_dict - # initalize highest to 0 - # iterate through the genre_freq_dict - # check if the value (genre_freq_dict[genre]) is higher than the current value stored in highest - # if it is assign highest_genre to current genre - # and replace highest with the freq +# def get_most_watched_genre(user_data): +# # call calculate_genre_freq to get genre_freq_dict +# # initalize highest to 0 +# # iterate through the genre_freq_dict +# # check if the value (genre_freq_dict[genre]) is higher than the current value stored in highest +# # if it is assign highest_genre to current genre +# # and replace highest with the freq - # return highest_genre \ No newline at end of file +# # return highest_genre \ No newline at end of file diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index 502091943..2e9f1fd2a 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -1,6 +1,7 @@ import pytest # NOTE: In production code, we developers should change import * to something more specific. Due to some constraints of this project, we will import * in our test files. -from viewing_party.main import * +# from viewing_party.main import * +from viewing_party.party import * def test_create_successful_movie(): diff --git a/viewing_party/main.py b/viewing_party/main.py index 447c78897..7fa489bea 100644 --- a/viewing_party/main.py +++ b/viewing_party/main.py @@ -167,3 +167,5 @@ def get_rec_from_favorites(user_data): recs.append(movie) return recs + + diff --git a/viewing_party/party.py b/viewing_party/party.py new file mode 100644 index 000000000..e69de29bb From 8940f8889085e97c4662f0073b85111456a66dbb Mon Sep 17 00:00:00 2001 From: Becca Elenzil Date: Mon, 20 Sep 2021 11:34:00 -0700 Subject: [PATCH 12/46] Remove comment ----- --- viewing_party/main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/viewing_party/main.py b/viewing_party/main.py index 7fa489bea..abee1a63b 100644 --- a/viewing_party/main.py +++ b/viewing_party/main.py @@ -1,6 +1,5 @@ # ----------------------------------------- # ------------- WAVE 1 -------------------- -# ----------------------------------------- def create_movie(title, genre, rating): if title and genre and rating: From 50caf2773f482b63e2269f52fd19a972ab3a286d Mon Sep 17 00:00:00 2001 From: Becca Elenzil Date: Thu, 27 Jan 2022 09:59:16 -0800 Subject: [PATCH 13/46] Rename main to party and move tests to unit_tests directory --- tests/temp.py | 20 --- tests/{ => unit_tests}/__init__.py | 0 tests/{ => unit_tests}/test_wave_01.py | 0 tests/{ => unit_tests}/test_wave_02.py | 2 +- tests/{ => unit_tests}/test_wave_03.py | 2 +- tests/{ => unit_tests}/test_wave_04.py | 2 +- tests/{ => unit_tests}/test_wave_05.py | 2 +- viewing_party/main.py | 170 ------------------------- viewing_party/party.py | 169 ++++++++++++++++++++++++ 9 files changed, 173 insertions(+), 194 deletions(-) delete mode 100644 tests/temp.py rename tests/{ => unit_tests}/__init__.py (100%) rename tests/{ => unit_tests}/test_wave_01.py (100%) rename tests/{ => unit_tests}/test_wave_02.py (98%) rename tests/{ => unit_tests}/test_wave_03.py (99%) rename tests/{ => unit_tests}/test_wave_04.py (98%) rename tests/{ => unit_tests}/test_wave_05.py (99%) delete mode 100644 viewing_party/main.py diff --git a/tests/temp.py b/tests/temp.py deleted file mode 100644 index 42f2d499f..000000000 --- a/tests/temp.py +++ /dev/null @@ -1,20 +0,0 @@ - -# iterate through the lists of movies the user has watched -#user_data["watched"] - -# if it's not in the friends list, append it to a new list - -# iterate through users_data["friends"], we can create a list of the movies the friends has watched -# <-- create a list that's the movies all the friends have watched - -friends_list = [] -for watched_dict in user_data["friends"]: - # some more nesting to pull out the friends' movies - if friend_movie not in friends_list: - friends_list.append(friend_movie) - - -movie_list = [] -for user_movie in user_data["watched"]: - if user_movie not in friends_list: - movie_list.append(user_movie) \ No newline at end of file diff --git a/tests/__init__.py b/tests/unit_tests/__init__.py similarity index 100% rename from tests/__init__.py rename to tests/unit_tests/__init__.py diff --git a/tests/test_wave_01.py b/tests/unit_tests/test_wave_01.py similarity index 100% rename from tests/test_wave_01.py rename to tests/unit_tests/test_wave_01.py diff --git a/tests/test_wave_02.py b/tests/unit_tests/test_wave_02.py similarity index 98% rename from tests/test_wave_02.py rename to tests/unit_tests/test_wave_02.py index 1a88af796..f4d27f18a 100644 --- a/tests/test_wave_02.py +++ b/tests/unit_tests/test_wave_02.py @@ -1,5 +1,5 @@ import pytest -from viewing_party.main import * +from viewing_party.party import * def test_calculates_watched_average_rating(): diff --git a/tests/test_wave_03.py b/tests/unit_tests/test_wave_03.py similarity index 99% rename from tests/test_wave_03.py rename to tests/unit_tests/test_wave_03.py index 8860c4ed9..513470b24 100644 --- a/tests/test_wave_03.py +++ b/tests/unit_tests/test_wave_03.py @@ -1,5 +1,5 @@ import pytest -from viewing_party.main import * +from viewing_party.party import * def test_my_unique_movies(): diff --git a/tests/test_wave_04.py b/tests/unit_tests/test_wave_04.py similarity index 98% rename from tests/test_wave_04.py rename to tests/unit_tests/test_wave_04.py index 90c6fe3b2..c21341f27 100644 --- a/tests/test_wave_04.py +++ b/tests/unit_tests/test_wave_04.py @@ -1,5 +1,5 @@ import pytest -from viewing_party.main import * +from viewing_party.party import * def test_get_available_friend_rec(): diff --git a/tests/test_wave_05.py b/tests/unit_tests/test_wave_05.py similarity index 99% rename from tests/test_wave_05.py rename to tests/unit_tests/test_wave_05.py index c84bf8db8..b46d57684 100644 --- a/tests/test_wave_05.py +++ b/tests/unit_tests/test_wave_05.py @@ -1,5 +1,5 @@ import pytest -from viewing_party.main import * +from viewing_party.party import * def test_new_genre_rec(): diff --git a/viewing_party/main.py b/viewing_party/main.py deleted file mode 100644 index abee1a63b..000000000 --- a/viewing_party/main.py +++ /dev/null @@ -1,170 +0,0 @@ -# ----------------------------------------- -# ------------- WAVE 1 -------------------- - -def create_movie(title, genre, rating): - if title and genre and rating: - movie = { - "title": title, - "genre": genre, - "rating": rating - } - return movie - -def add_to_watched(user_data, movie): - user_data["watched"].append(movie) - return user_data - -def add_to_watchlist(user_data, movie): - user_data["watchlist"].append(movie) - return user_data - -def watch_movie(user_data, title): - for movie in user_data["watchlist"]: - if movie["title"] == title: - user_data["watchlist"].remove(movie) - user_data["watched"].append(movie) - return user_data - -# ----------------------------------------- -# ------------- WAVE 2 -------------------- -# ----------------------------------------- - -def get_watched_avg_rating(user_data): - total = 0 - movies = user_data["watched"] - n = len(movies) - - if n == 0: - return 0 - - for movie in movies: - total += movie["rating"] - - return total/n - -def calculate_genre_freq(user_data): - # make genre frequency hash - genre_freqs = {} - movies = user_data["watched"] - #genre_freq = defaultdict(lambda: 0) - - for movie in movies: - genre = movie['genre'] - if genre not in genre_freqs.keys(): - genre_freqs[genre] = 1 - else: - genre_freqs[genre] += 1 - - # genre = movie['genre'] - # try: - # if genre_freqs[genre] != 0: - # genre_freqs[genre] += 1 - # except: - # genre_freqs[genre] = 1 - - return genre_freqs - -def get_most_watched_genre(user_data): - - - movies = user_data["watched"] - - if movies == []: - return None - - #call helper function to get frequencies - genre_freqs = calculate_genre_freq(user_data) - print(genre_freqs) - highest_freq = 0 - - # find most frequent - for genre in genre_freqs: - freq = genre_freqs[genre] - if freq > highest_freq: - most_frequent = genre - highest_freq = freq - - return most_frequent - -# ----------------------------------------- -# ------------- WAVE 3 -------------------- -# ----------------------------------------- - -def get_friends_movies(user_data): - friend_movies = [] - - #get friends movie titles - for watched_dict in user_data['friends']: - for movie in watched_dict['watched']: - if movie not in friend_movies: - friend_movies.append(movie) - - return friend_movies - -def get_unique_watched(user_data): - user_movies = user_data['watched'] - user_unique_movie_titles = [] - friend_movies = get_friends_movies(user_data) - - #check for unique titles - for movie in user_movies: - if movie not in friend_movies: - user_unique_movie_titles.append(movie) - - return user_unique_movie_titles - - -def get_friends_unique_watched(user_data): - friend_movies = get_friends_movies(user_data) - unique_friend_movies = [] - - for movie in friend_movies: - if {'title': movie['title']} not in user_data['watched']: - unique_friend_movies.append(movie) - - return unique_friend_movies - - -# ----------------------------------------- -# ------------- WAVE 4 -------------------- -# ----------------------------------------- - -def get_available_recs(user_data): - - unique_friend_movies = get_friends_unique_watched(user_data) - recs = [] - - for movie in unique_friend_movies: - if movie['host'] in user_data['subscriptions']: - recs.append(movie) - - return recs - -# ----------------------------------------- -# ------------- WAVE 5 -------------------- -# ----------------------------------------- - -def get_new_rec_by_genre(user_data): - most_freq_genre = get_most_watched_genre(user_data) - unique_friend_movies = get_friends_unique_watched(user_data) - - recs = [] - - for movie in unique_friend_movies: - if movie['genre'] == most_freq_genre: - recs.append(movie) - - return recs - -def get_rec_from_favorites(user_data): - - movies = get_unique_watched(user_data) - recs = [] - - for movie in movies: - if movie in user_data['favorites']: - recs.append(movie) - - return recs - - diff --git a/viewing_party/party.py b/viewing_party/party.py index e69de29bb..5be3a89f3 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -0,0 +1,169 @@ +# ------------- WAVE 1 -------------------- + +def create_movie(title, genre, rating): + if title and genre and rating: + movie = { + "title": title, + "genre": genre, + "rating": rating + } + return movie + +def add_to_watched(user_data, movie): + user_data["watched"].append(movie) + return user_data + +def add_to_watchlist(user_data, movie): + user_data["watchlist"].append(movie) + return user_data + +def watch_movie(user_data, title): + for movie in user_data["watchlist"]: + if movie["title"] == title: + user_data["watchlist"].remove(movie) + user_data["watched"].append(movie) + return user_data + +# ----------------------------------------- +# ------------- WAVE 2 -------------------- +# ----------------------------------------- + +def get_watched_avg_rating(user_data): + total = 0 + movies = user_data["watched"] + n = len(movies) + + if n == 0: + return 0 + + for movie in movies: + total += movie["rating"] + + return total/n + +def calculate_genre_freq(user_data): + # make genre frequency hash + genre_freqs = {} + movies = user_data["watched"] + #genre_freq = defaultdict(lambda: 0) + + for movie in movies: + genre = movie['genre'] + if genre not in genre_freqs.keys(): + genre_freqs[genre] = 1 + else: + genre_freqs[genre] += 1 + + # genre = movie['genre'] + # try: + # if genre_freqs[genre] != 0: + # genre_freqs[genre] += 1 + # except: + # genre_freqs[genre] = 1 + + return genre_freqs + +def get_most_watched_genre(user_data): + + + movies = user_data["watched"] + + if movies == []: + return None + + #call helper function to get frequencies + genre_freqs = calculate_genre_freq(user_data) + print(genre_freqs) + highest_freq = 0 + + # find most frequent + for genre in genre_freqs: + freq = genre_freqs[genre] + if freq > highest_freq: + most_frequent = genre + highest_freq = freq + + return most_frequent + +# ----------------------------------------- +# ------------- WAVE 3 -------------------- +# ----------------------------------------- + +def get_friends_movies(user_data): + friend_movies = [] + + #get friends movie titles + for watched_dict in user_data['friends']: + for movie in watched_dict['watched']: + if movie not in friend_movies: + friend_movies.append(movie) + + return friend_movies + +def get_unique_watched(user_data): + user_movies = user_data['watched'] + user_unique_movie_titles = [] + friend_movies = get_friends_movies(user_data) + + #check for unique titles + for movie in user_movies: + if movie not in friend_movies: + user_unique_movie_titles.append(movie) + + return user_unique_movie_titles + + +def get_friends_unique_watched(user_data): + friend_movies = get_friends_movies(user_data) + unique_friend_movies = [] + + for movie in friend_movies: + if {'title': movie['title']} not in user_data['watched']: + unique_friend_movies.append(movie) + + return unique_friend_movies + + +# ----------------------------------------- +# ------------- WAVE 4 -------------------- +# ----------------------------------------- + +def get_available_recs(user_data): + + unique_friend_movies = get_friends_unique_watched(user_data) + recs = [] + + for movie in unique_friend_movies: + if movie['host'] in user_data['subscriptions']: + recs.append(movie) + + return recs + +# ----------------------------------------- +# ------------- WAVE 5 -------------------- +# ----------------------------------------- + +def get_new_rec_by_genre(user_data): + most_freq_genre = get_most_watched_genre(user_data) + unique_friend_movies = get_friends_unique_watched(user_data) + + recs = [] + + for movie in unique_friend_movies: + if movie['genre'] == most_freq_genre: + recs.append(movie) + + return recs + +def get_rec_from_favorites(user_data): + + movies = get_unique_watched(user_data) + recs = [] + + for movie in movies: + if movie in user_data['favorites']: + recs.append(movie) + + return recs + + From 9bbec8e6a5f2732ab99d758b05711392fc88a3d4 Mon Sep 17 00:00:00 2001 From: Becca Elenzil Date: Fri, 28 Jan 2022 10:16:43 -0800 Subject: [PATCH 14/46] Test organization and wave01 and 02 integrations tests --- tests/{unit_tests => }/__init__.py | 0 tests/integration_tests/__init__.py | 0 .../test_integration_wave_01.py | 41 +++++++++++++ .../test_integration_wave_02.py | 24 ++++++++ .../test_integration_wave_03.py | 6 ++ .../test_integration_wave_04.py | 0 .../test_integration_wave_05.py | 0 tests/test_constants.py | 60 +++++++++++++++++++ viewing_party/party.py | 2 +- 9 files changed, 132 insertions(+), 1 deletion(-) rename tests/{unit_tests => }/__init__.py (100%) create mode 100644 tests/integration_tests/__init__.py create mode 100644 tests/integration_tests/test_integration_wave_01.py create mode 100644 tests/integration_tests/test_integration_wave_02.py create mode 100644 tests/integration_tests/test_integration_wave_03.py create mode 100644 tests/integration_tests/test_integration_wave_04.py create mode 100644 tests/integration_tests/test_integration_wave_05.py create mode 100644 tests/test_constants.py diff --git a/tests/unit_tests/__init__.py b/tests/__init__.py similarity index 100% rename from tests/unit_tests/__init__.py rename to tests/__init__.py diff --git a/tests/integration_tests/__init__.py b/tests/integration_tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/integration_tests/test_integration_wave_01.py b/tests/integration_tests/test_integration_wave_01.py new file mode 100644 index 000000000..0774c2da7 --- /dev/null +++ b/tests/integration_tests/test_integration_wave_01.py @@ -0,0 +1,41 @@ +import pytest +from viewing_party.party import * +from tests.test_constants import * + +@pytest.mark.integration_test +def test_create_and_watch_movie(): + # Arrange + movie_title = MOVIE_TITLE_1 + genre = GENRE_1 + rating = RATING_1 + user_data = {"watched": [], "watchlist": []} + + # Act + # create movie + new_movie = create_movie(movie_title, genre, rating) + + # add movie to watchlist + add_to_watchlist(user_data, new_movie) + + # check that the movie is the first item in the watch list + assert user_data["watchlist"][0]["title"] == MOVIE_TITLE_1 + assert user_data["watchlist"][0]["genre"] == GENRE_1 + assert user_data["watchlist"][0]["rating"] == RATING_1 + + # watch movie + watch_movie(user_data, movie_title) + + #check that watch list is empty and new movie is in watched + assert user_data["watchlist"] == [] + assert user_data["watched"][0]["title"] == MOVIE_TITLE_1 + assert user_data["watched"][0]["genre"] == GENRE_1 + assert user_data["watched"][0]["rating"] == RATING_1 + + # try to watch movie not in watchlist + watch_movie(user_data, movie_title) + + # confirm there is still only 1 movie in watched + assert len(user_data["watched"]) == 1 + + + diff --git a/tests/integration_tests/test_integration_wave_02.py b/tests/integration_tests/test_integration_wave_02.py new file mode 100644 index 000000000..7fc3f7189 --- /dev/null +++ b/tests/integration_tests/test_integration_wave_02.py @@ -0,0 +1,24 @@ +import pytest +from viewing_party.party import * +from tests.test_constants import * + +@pytest.mark.integration_test +def test_get_most_watched_genre(): + # Arrange + user_data = USER_DATA_1 + empty_user_data = EMPTY_USER_DATA + + # user data + most_watched = get_most_watched_genre(user_data) + average_rating = get_watched_avg_rating(user_data) + assert most_watched == "Fantasy" + assert average_rating == pytest.approx(3.58333) + + # empty user data + most_watched = get_most_watched_genre(empty_user_data) + average_rating = get_watched_avg_rating(empty_user_data) + assert most_watched == None + assert average_rating == 0 + + + \ No newline at end of file diff --git a/tests/integration_tests/test_integration_wave_03.py b/tests/integration_tests/test_integration_wave_03.py new file mode 100644 index 000000000..8adeb8aaa --- /dev/null +++ b/tests/integration_tests/test_integration_wave_03.py @@ -0,0 +1,6 @@ +import pytest +from viewing_party.party import * +from tests.test_constants import * + +@pytest.mark.integration_test +def test_get_friends_unique(): \ No newline at end of file diff --git a/tests/integration_tests/test_integration_wave_04.py b/tests/integration_tests/test_integration_wave_04.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/integration_tests/test_integration_wave_05.py b/tests/integration_tests/test_integration_wave_05.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/test_constants.py b/tests/test_constants.py new file mode 100644 index 000000000..0c2134aa9 --- /dev/null +++ b/tests/test_constants.py @@ -0,0 +1,60 @@ +#----------WAVE01------------- +MOVIE_TITLE_1 = "It came from the stack trace" +GENRE_1 = "Horror" +RATING_1 = 3.5 + +#----------WAVE02------------- +HORROR_1 = { + "title": MOVIE_TITLE_1, + "genre": GENRE_1, + "rating": RATING_1 +} + +FANTASY_1 = { + "title": "Fantasy 1", + "genre": "Fantasy", + "rating": 4.8 +} + +FANTASY_2 = { + "title": "Fantasy 2", + "genre": "Fantasy", + "rating": 4.0 +} + +FANTASY_3 = { + "title": "Fantasy 3", + "genre": "Fantasy", + "rating": 4.0 +} + +ACTION_1 = { + "title": "Title B", + "genre": "Action", + "rating": 2.2 +} + +INTRIGUE_1 = { + "title": "Intrigue 1", + "genre": "Intrigue", + "rating": 2.0 +} + +INTRIGUE_2 = { + "title": "Intrigue 2", + "genre": "Intrigue", + "rating": 4.5 +} + +INTRIGUE_3 = { + "title": "Intrigue 3", + "genre": "Intrigue", + "rating": 3.0 +} +USER_DATA_1 = { + "watched": [FANTASY_1, FANTASY_2, FANTASY_3, ACTION_1, INTRIGUE_1, INTRIGUE_2], +} + +EMPTY_USER_DATA = { + "watched": [], +} diff --git a/viewing_party/party.py b/viewing_party/party.py index 5be3a89f3..5c4c88def 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -21,7 +21,7 @@ def watch_movie(user_data, title): for movie in user_data["watchlist"]: if movie["title"] == title: user_data["watchlist"].remove(movie) - user_data["watched"].append(movie) + add_to_watched(user_data, movie) return user_data # ----------------------------------------- From 4eaf7f40c46fe9b0aa8ac2134d8855f7dcebb490 Mon Sep 17 00:00:00 2001 From: Becca Elenzil Date: Fri, 28 Jan 2022 11:04:29 -0800 Subject: [PATCH 15/46] Add integration tests --- .../test_integration_wave_02.py | 2 +- .../test_integration_wave_03.py | 16 +++- .../test_integration_wave_04.py | 14 ++++ .../test_integration_wave_05.py | 19 +++++ tests/test_constants.py | 76 ++++++++++++++++++- viewing_party/party.py | 2 +- 6 files changed, 123 insertions(+), 6 deletions(-) diff --git a/tests/integration_tests/test_integration_wave_02.py b/tests/integration_tests/test_integration_wave_02.py index 7fc3f7189..5b6fb9ed4 100644 --- a/tests/integration_tests/test_integration_wave_02.py +++ b/tests/integration_tests/test_integration_wave_02.py @@ -5,7 +5,7 @@ @pytest.mark.integration_test def test_get_most_watched_genre(): # Arrange - user_data = USER_DATA_1 + user_data = USER_DATA empty_user_data = EMPTY_USER_DATA # user data diff --git a/tests/integration_tests/test_integration_wave_03.py b/tests/integration_tests/test_integration_wave_03.py index 8adeb8aaa..243d8ffb8 100644 --- a/tests/integration_tests/test_integration_wave_03.py +++ b/tests/integration_tests/test_integration_wave_03.py @@ -3,4 +3,18 @@ from tests.test_constants import * @pytest.mark.integration_test -def test_get_friends_unique(): \ No newline at end of file +def test_get_friends_unique(): + user_data = USER_DATA + + unique_movies = get_unique_watched(user_data) + + assert FANTASY_2 in unique_movies + assert INTRIGUE_2 in unique_movies + assert len(unique_movies) == 2 + + friend_unique_movies = get_friends_unique_watched(user_data) + + assert len(friend_unique_movies) == 3 + assert INTRIGUE_3 in friend_unique_movies + assert HORROR_1 in friend_unique_movies + assert FANTASY_4 in friend_unique_movies \ No newline at end of file diff --git a/tests/integration_tests/test_integration_wave_04.py b/tests/integration_tests/test_integration_wave_04.py index e69de29bb..4b2a15764 100644 --- a/tests/integration_tests/test_integration_wave_04.py +++ b/tests/integration_tests/test_integration_wave_04.py @@ -0,0 +1,14 @@ +import pytest +from viewing_party.party import * +from tests.test_constants import * + +@pytest.mark.integration_test +def test_get_available_recs(): + #Arrange + user_data = USER_DATA + + rec_movies = get_available_recs(user_data) + + assert len(rec_movies) == 2 + assert HORROR_1 in rec_movies + assert FANTASY_4 in rec_movies \ No newline at end of file diff --git a/tests/integration_tests/test_integration_wave_05.py b/tests/integration_tests/test_integration_wave_05.py index e69de29bb..d99ef893f 100644 --- a/tests/integration_tests/test_integration_wave_05.py +++ b/tests/integration_tests/test_integration_wave_05.py @@ -0,0 +1,19 @@ +from cmath import rect +import pytest +from viewing_party.party import * +from tests.test_constants import * + +@pytest.mark.integration_test +def test_recs(): + user_data = USER_DATA + + genre_rec = get_new_rec_by_genre(user_data) + + assert len(genre_rec) == 1 + assert FANTASY_4 in genre_rec + + favorite_recs = get_rec_from_favorites(user_data) + + assert len(favorite_recs) == 2 + assert FANTASY_2 in favorite_recs + assert INTRIGUE_2 in favorite_recs \ No newline at end of file diff --git a/tests/test_constants.py b/tests/test_constants.py index 0c2134aa9..80f869712 100644 --- a/tests/test_constants.py +++ b/tests/test_constants.py @@ -28,12 +28,30 @@ "rating": 4.0 } +FANTASY_4 = { + "title": "Fantasy 4", + "genre": "Fantasy", + "rating": 4.0 +} + ACTION_1 = { - "title": "Title B", + "title": "Action 1", "genre": "Action", "rating": 2.2 } +ACTION_2 = { + "title": "Action 2", + "genre": "Action", + "rating": 4.2 +} + +ACTION_3 = { + "title": "Action 3", + "genre": "Action", + "rating": 3.5 +} + INTRIGUE_1 = { "title": "Intrigue 1", "genre": "Intrigue", @@ -51,10 +69,62 @@ "genre": "Intrigue", "rating": 3.0 } -USER_DATA_1 = { - "watched": [FANTASY_1, FANTASY_2, FANTASY_3, ACTION_1, INTRIGUE_1, INTRIGUE_2], +USER_DATA = { + "watched": [ + FANTASY_1, + FANTASY_2, + FANTASY_3, + ACTION_1, + INTRIGUE_1, + INTRIGUE_2 + ], } EMPTY_USER_DATA = { "watched": [], } + +#-----WAVE 3-------- +USER_DATA["friends"] = [ + { + "watched": [ + FANTASY_1, + FANTASY_3, + FANTASY_4, + HORROR_1, + ] + }, + { + "watched": [ + FANTASY_1, + ACTION_1, + INTRIGUE_1, + INTRIGUE_3, + ] + } + ] + +#-----WAVE 4-------- +HORROR_1["host"] = "netflix" +FANTASY_1["host"] = "netflix" +FANTASY_2["host"] = "netflix" +FANTASY_3["host"] = "amazon" +FANTASY_4["host"] = "hulu" +ACTION_1["host"] = "amazon" +ACTION_2["host"] = "amazon" +ACTION_3["host"] = "hulu" +INTRIGUE_1["host"] = "hulu" +INTRIGUE_2["host"] = "disney+" +INTRIGUE_3["host"] = "disney+" + +USER_DATA["subscriptions"] = ["netflix", "hulu"] + + +#----WAVE 5----------- + +USER_DATA["favorites"] = [ + FANTASY_1, + FANTASY_2, + INTRIGUE_1, + INTRIGUE_2 + ] \ No newline at end of file diff --git a/viewing_party/party.py b/viewing_party/party.py index 5c4c88def..fa011e3e1 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -118,7 +118,7 @@ def get_friends_unique_watched(user_data): unique_friend_movies = [] for movie in friend_movies: - if {'title': movie['title']} not in user_data['watched']: + if movie not in user_data['watched']: unique_friend_movies.append(movie) return unique_friend_movies From 188b246119174a6575d2b142b1a31932a738f253 Mon Sep 17 00:00:00 2001 From: Becca Elenzil Date: Fri, 28 Jan 2022 11:08:14 -0800 Subject: [PATCH 16/46] Remove temp file --- temp.py | 36 ------------------------------------ 1 file changed, 36 deletions(-) delete mode 100644 temp.py diff --git a/temp.py b/temp.py deleted file mode 100644 index 72878f3e4..000000000 --- a/temp.py +++ /dev/null @@ -1,36 +0,0 @@ -# def calculate_genre_freq(user_data): -# #dictionary where the keys are the genre e.g. "fantasy" -# #go through watch list and check if it's in -# #if it's already in dictionary, add 1 to it - -# # build a frequency map -# # { -# # "Intrigue": 3, -# # "Fantasy": 2 -# # "Comedy": 5, -# # "Horrr": 2 -# # } -# #dictionary where the keys are the genre e.g. "fantasy" -# genre_freq_dict = {} -# watch_list = user_data["watched"] -# for movie in watch_list: -# genre = movie["genres"] -# #go through watch list and check if that genre is already a key -# #if it's already in dictionary, add 1 to it -# if genre in genre_freq_dict.keys(): -# genre_freq_dict[genre] += 1 -# #otherwise we'll make an entry and give a value of 1 -# else: -# genre_freq_dict[genre] = 1 - -# return genre_freq_dict - -# def get_most_watched_genre(user_data): -# # call calculate_genre_freq to get genre_freq_dict -# # initalize highest to 0 -# # iterate through the genre_freq_dict -# # check if the value (genre_freq_dict[genre]) is higher than the current value stored in highest -# # if it is assign highest_genre to current genre -# # and replace highest with the freq - -# # return highest_genre \ No newline at end of file From 761027b7d42481651f4d176ec59c008a79607ef5 Mon Sep 17 00:00:00 2001 From: Becca Elenzil Date: Mon, 7 Feb 2022 16:28:41 -0800 Subject: [PATCH 17/46] Update wave 01 unit tests with test constants --- tests/test_constants.py | 9 +-- tests/unit_tests/test_wave_01.py | 95 +++++++++++--------------------- 2 files changed, 38 insertions(+), 66 deletions(-) diff --git a/tests/test_constants.py b/tests/test_constants.py index 80f869712..8c248d469 100644 --- a/tests/test_constants.py +++ b/tests/test_constants.py @@ -3,6 +3,11 @@ GENRE_1 = "Horror" RATING_1 = 3.5 +EMPTY_USER_DATA = { + "watched": [], + "watchlist": [], +} + #----------WAVE02------------- HORROR_1 = { "title": MOVIE_TITLE_1, @@ -80,10 +85,6 @@ ], } -EMPTY_USER_DATA = { - "watched": [], -} - #-----WAVE 3-------- USER_DATA["friends"] = [ { diff --git a/tests/unit_tests/test_wave_01.py b/tests/unit_tests/test_wave_01.py index 2e9f1fd2a..603db597d 100644 --- a/tests/unit_tests/test_wave_01.py +++ b/tests/unit_tests/test_wave_01.py @@ -2,21 +2,22 @@ # NOTE: In production code, we developers should change import * to something more specific. Due to some constraints of this project, we will import * in our test files. # from viewing_party.main import * from viewing_party.party import * +from tests.test_constants import * def test_create_successful_movie(): # Arrange - movie_title = "Title A" - genre = "Horror" - rating = 3.5 + movie_title = MOVIE_TITLE_1 + genre = GENRE_1 + rating = RATING_1 # Act new_movie = create_movie(movie_title, genre, rating) # Assert - assert new_movie["title"] is "Title A" - assert new_movie["genre"] is "Horror" - assert new_movie["rating"] is 3.5 + assert new_movie["title"] is MOVIE_TITLE_1 + assert new_movie["genre"] is GENRE_1 + assert new_movie["rating"] is RATING_1 def test_create_no_title_movie(): @@ -61,9 +62,9 @@ def test_create_no_rating_movie(): def test_adds_movie_to_user_watched(): # Arrange movie = { - "title": "Title A", - "genre": "Horror", - "rating": 3.5 + "title": MOVIE_TITLE_1, + "genre": GENRE_1, + "rating": RATING_1 } user_data = { "watched": [] @@ -74,17 +75,17 @@ def test_adds_movie_to_user_watched(): # Assert assert len(updated_data["watched"]) is 1 - assert updated_data["watched"][0]["title"] is "Title A" - assert updated_data["watched"][0]["genre"] is "Horror" - assert updated_data["watched"][0]["rating"] is 3.5 + 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 def test_adds_movie_to_user_watchlist(): # Arrange movie = { - "title": "Title A", - "genre": "Horror", - "rating": 3.5 + "title": MOVIE_TITLE_1, + "genre": GENRE_1, + "rating": RATING_1 } user_data = { "watchlist": [] @@ -95,56 +96,42 @@ def test_adds_movie_to_user_watchlist(): # Assert assert len(updated_data["watchlist"]) is 1 - assert updated_data["watchlist"][0]["title"] is "Title A" - assert updated_data["watchlist"][0]["genre"] is "Horror" - assert updated_data["watchlist"][0]["rating"] is 3.5 + assert updated_data["watchlist"][0]["title"] is MOVIE_TITLE_1 + assert updated_data["watchlist"][0]["genre"] is GENRE_1 + assert updated_data["watchlist"][0]["rating"] is RATING_1 def test_moves_movie_from_watchlist_to_empty_watched(): # Arrange janes_data = { "watchlist": [{ - "title": "Title A", - "genre": "Fantasy", - "rating": 4.8 + "title": MOVIE_TITLE_1, + "genre": GENRE_1, + "rating": RATING_1 }], "watched": [] } # Act - updated_data = watch_movie(janes_data, "Title A") + updated_data = watch_movie(janes_data, MOVIE_TITLE_1) # Assert assert len(updated_data["watchlist"]) is 0 assert len(updated_data["watched"]) is 1 - assert updated_data["watched"][0]["title"] is "Title A" - assert updated_data["watched"][0]["genre"] is "Fantasy" - assert updated_data["watched"][0]["rating"] is 4.8 + 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 def test_moves_movie_from_watchlist_to_watched(): # Arrange - movie_to_watch = { - "title": "Title A", - "genre": "Fantasy", - "rating": 4.8 - } + movie_to_watch = HORROR_1 janes_data = { "watchlist": [ - { - "title": "Title B", - "genre": "Action", - "rating": 2.0 - }, + FANTASY_1, movie_to_watch ], - "watched": [ - { - "title": "Title C", - "genre": "Intrigue", - "rating": 3.9 - } - ] + "watched": [FANTASY_2] } # Act @@ -158,30 +145,14 @@ def test_moves_movie_from_watchlist_to_watched(): def test_does_nothing_if_movie_not_in_watchlist(): # Arrange - movie_to_watch = { - "title": "Title A", - "genre": "Fantasy", - "rating": 4.8 - } + movie_to_watch = HORROR_1 janes_data = { - "watchlist": [ - { - "title": "Title B", - "genre": "Action", - "rating": 2.0 - } - ], - "watched": [ - { - "title": "Title C", - "genre": "Intrigue", - "rating": 3.9 - } - ] + "watchlist": [FANTASY_1], + "watched": [FANTASY_2] } # Act - updated_data = watch_movie(janes_data, "Title A") + updated_data = watch_movie(janes_data, "Non-Existent Movie Title") # Assert assert len(updated_data["watchlist"]) is 1 From df2503ebbf56116a7fb9e0b2862c9c9f56ca3653 Mon Sep 17 00:00:00 2001 From: Becca Elenzil Date: Mon, 7 Feb 2022 16:39:37 -0800 Subject: [PATCH 18/46] Update test constants to make new user_data data structure for each wave --- play_tester.py | 24 ++++++++++++----- tests/test_constants.py | 57 +++++++++++++++++++++++++++-------------- 2 files changed, 55 insertions(+), 26 deletions(-) diff --git a/play_tester.py b/play_tester.py index 3cce9cbb9..122ae47ef 100644 --- a/play_tester.py +++ b/play_tester.py @@ -1,12 +1,22 @@ # from viewing_party.main import * from viewing_party.party import * +from tests.test_constants import * +import pprint -# Arrange -movie_title = "Title A" -genre = "Horror" -rating = 3.5 +pp = pprint.PrettyPrinter(indent=4) -# Act -new_movie = create_movie(movie_title, genre, rating) +# Wave 02 user data +print("\n-----Wave 02 user_data-----") +pp.pprint(USER_DATA_2) -print(new_movie) +# Wave 03 user data +print("\n-----Wave 03 user_data-----") +pp.pprint(USER_DATA_3) + +# Wave 04 user data +print("\n-----Wave 04 user_data-----") +pp.pprint(USER_DATA_4) + +# Wave 05 user data +print("\n-----Wave 05 user_data-----") +pp.pprint(USER_DATA_4) diff --git a/tests/test_constants.py b/tests/test_constants.py index 8c248d469..18317ab6e 100644 --- a/tests/test_constants.py +++ b/tests/test_constants.py @@ -1,3 +1,5 @@ +import copy + #----------WAVE01------------- MOVIE_TITLE_1 = "It came from the stack trace" GENRE_1 = "Horror" @@ -74,7 +76,7 @@ "genre": "Intrigue", "rating": 3.0 } -USER_DATA = { +USER_DATA_2 = { "watched": [ FANTASY_1, FANTASY_2, @@ -86,7 +88,8 @@ } #-----WAVE 3-------- -USER_DATA["friends"] = [ +USER_DATA_3 = copy.deepcopy(USER_DATA_2) +USER_DATA_3["friends"] = [ { "watched": [ FANTASY_1, @@ -106,26 +109,42 @@ ] #-----WAVE 4-------- -HORROR_1["host"] = "netflix" -FANTASY_1["host"] = "netflix" -FANTASY_2["host"] = "netflix" -FANTASY_3["host"] = "amazon" -FANTASY_4["host"] = "hulu" -ACTION_1["host"] = "amazon" -ACTION_2["host"] = "amazon" -ACTION_3["host"] = "hulu" -INTRIGUE_1["host"] = "hulu" -INTRIGUE_2["host"] = "disney+" -INTRIGUE_3["host"] = "disney+" -USER_DATA["subscriptions"] = ["netflix", "hulu"] +HORROR_1b = copy.deepcopy(HORROR_1) +FANTASY_1b = copy.deepcopy(FANTASY_1) +FANTASY_2b = copy.deepcopy(FANTASY_2) +FANTASY_3b = copy.deepcopy(FANTASY_3) +FANTASY_4b = copy.deepcopy(FANTASY_4) +ACTION_1b = copy.deepcopy(ACTION_1) +ACTION_2b = copy.deepcopy(ACTION_2) +ACTION_3b = copy.deepcopy(ACTION_3) +INTRIGUE_1b = copy.deepcopy(INTRIGUE_1) +INTRIGUE_2b = copy.deepcopy(INTRIGUE_2) +INTRIGUE_3b = copy.deepcopy(INTRIGUE_3) + +HORROR_1b["host"] = "netflix" +FANTASY_1b["host"] = "netflix" +FANTASY_2b["host"] = "netflix" +FANTASY_3b["host"] = "amazon" +FANTASY_4b["host"] = "hulu" +ACTION_1b["host"] = "amazon" +ACTION_2b["host"] = "amazon" +ACTION_3b["host"] = "hulu" +INTRIGUE_1b["host"] = "hulu" +INTRIGUE_2b["host"] = "disney+" +INTRIGUE_3b["host"] = "disney+" + +USER_DATA_4 = copy.deepcopy(USER_DATA_3) +USER_DATA_3["subscriptions"] = ["netflix", "hulu"] #----WAVE 5----------- -USER_DATA["favorites"] = [ - FANTASY_1, - FANTASY_2, - INTRIGUE_1, - INTRIGUE_2 +USER_DATA_5 = copy.deepcopy(USER_DATA_4) + +USER_DATA_5["favorites"] = [ + FANTASY_1b, + FANTASY_2b, + INTRIGUE_1b, + INTRIGUE_2b ] \ No newline at end of file From 8db21abf74ea078789e29e0870881034f9a6d1fc Mon Sep 17 00:00:00 2001 From: Becca Elenzil Date: Mon, 7 Feb 2022 16:42:35 -0800 Subject: [PATCH 19/46] Update wave 02 tests --- .../test_integration_wave_02.py | 2 +- tests/unit_tests/test_wave_02.py | 50 ++----------------- 2 files changed, 6 insertions(+), 46 deletions(-) diff --git a/tests/integration_tests/test_integration_wave_02.py b/tests/integration_tests/test_integration_wave_02.py index 5b6fb9ed4..fc971f4bb 100644 --- a/tests/integration_tests/test_integration_wave_02.py +++ b/tests/integration_tests/test_integration_wave_02.py @@ -5,7 +5,7 @@ @pytest.mark.integration_test def test_get_most_watched_genre(): # Arrange - user_data = USER_DATA + user_data = USER_DATA_2 empty_user_data = EMPTY_USER_DATA # user data diff --git a/tests/unit_tests/test_wave_02.py b/tests/unit_tests/test_wave_02.py index f4d27f18a..30bcfd704 100644 --- a/tests/unit_tests/test_wave_02.py +++ b/tests/unit_tests/test_wave_02.py @@ -1,34 +1,17 @@ import pytest from viewing_party.party import * +from tests.test_constants import USER_DATA_2 def test_calculates_watched_average_rating(): # Arrange - janes_data = { - "watched": [ - { - "title": "Title A", - "genre": "Fantasy", - "rating": 4.8 - }, - { - "title": "Title B", - "genre": "Action", - "rating": 2.0 - }, - { - "title": "Title C", - "genre": "Intrigue", - "rating": 3.9 - } - ] - } + janes_data = USER_DATA_2 # Act average = get_watched_avg_rating(janes_data) # Assert - assert average == pytest.approx(3.56666666664) + assert average == pytest.approx(3.58333) def test_empty_watched_average_rating_is_zero(): @@ -47,36 +30,13 @@ def test_empty_watched_average_rating_is_zero(): def test_most_watched_genre(): # Arrange - janes_data = { - "watched": [ - { - "title": "Title A", - "genre": "Fantasy" - }, - { - "title": "Title B", - "genre": "Intrigue" - }, - { - "title": "Title C", - "genre": "Intrigue" - }, - { - "title": "Title D", - "genre": "Fantasy" - }, - { - "title": "Title E", - "genre": "Intrigue" - }, - ] - } + janes_data = USER_DATA_2 # Act popular_genre = get_most_watched_genre(janes_data) # Assert - assert popular_genre is "Intrigue" + assert popular_genre is "Fantasy" def test_genre_is_None_if_empty_watched(): From ae090d144fdf1386a5b74438eca4efe1d66acf00 Mon Sep 17 00:00:00 2001 From: Becca Elenzil Date: Mon, 7 Feb 2022 16:54:05 -0800 Subject: [PATCH 20/46] Update wave 03 tests with test constants --- .../test_integration_wave_03.py | 2 +- tests/unit_tests/test_wave_03.py | 179 ++---------------- 2 files changed, 22 insertions(+), 159 deletions(-) diff --git a/tests/integration_tests/test_integration_wave_03.py b/tests/integration_tests/test_integration_wave_03.py index 243d8ffb8..73d28a4ba 100644 --- a/tests/integration_tests/test_integration_wave_03.py +++ b/tests/integration_tests/test_integration_wave_03.py @@ -4,7 +4,7 @@ @pytest.mark.integration_test def test_get_friends_unique(): - user_data = USER_DATA + user_data = USER_DATA_3 unique_movies = get_unique_watched(user_data) diff --git a/tests/unit_tests/test_wave_03.py b/tests/unit_tests/test_wave_03.py index 513470b24..091d30cba 100644 --- a/tests/unit_tests/test_wave_03.py +++ b/tests/unit_tests/test_wave_03.py @@ -1,93 +1,25 @@ import pytest from viewing_party.party import * +from tests.test_constants import * def test_my_unique_movies(): # Arrange - amandas_data = { - "watched": [ - { - "title": "Title A" - }, - { - "title": "Title B" - }, - { - "title": "Title C" - }, - { - "title": "Title D" - }, - { - "title": "Title E" - }, - ], - "friends": [ - { - "watched": [ - { - "title": "Title A" - }, - { - "title": "Title C" - } - ] - }, - { - "watched": [ - { - "title": "Title A" - }, - { - "title": "Title D" - }, - { - "title": "Title F" - } - ] - } - ] - } + amandas_data = USER_DATA_3 # Act amandas_unique_movies = get_unique_watched(amandas_data) # Arrange assert len(amandas_unique_movies) is 2 - assert {"title": "Title B"} in amandas_unique_movies - assert {"title": "Title E"} in amandas_unique_movies + assert FANTASY_2 in amandas_unique_movies + assert INTRIGUE_2 in amandas_unique_movies def test_my_not_unique_movies(): # Arrange - amandas_data = { - "watched": [], - "friends": [ - { - "watched": [ - { - "title": "Title A" - }, - { - "title": "Title C" - } - ] - }, - { - "watched": [ - { - "title": "Title A" - }, - { - "title": "Title D" - }, - { - "title": "Title F" - } - ] - } - ] - } + amandas_data = copy.deepcopy(USER_DATA_3) + amandas_data["watched"] = [] # Act amandas_unique_movies = get_unique_watched(amandas_data) @@ -98,115 +30,46 @@ def test_my_not_unique_movies(): #@pytest.mark.skip(reason="no way of currently testing this") def test_friends_unique_movies(): # Arrange - amandas_data = { - "watched": [ - { - "title": "Title A" - }, - { - "title": "Title B" - }, - { - "title": "Title C" - } - ], - "friends": [ - { - "watched": [ - { - "title": "Title A" - }, - { - "title": "Title C" - } - ] - }, - { - "watched": [ - { - "title": "Title A" - }, - { - "title": "Title D" - }, - { - "title": "Title E" - } - ] - } - ] - } + amandas_data = USER_DATA_3 # Act friends_unique_movies = get_friends_unique_watched(amandas_data) # Arrange - assert len(friends_unique_movies) is 2 - assert {"title": "Title D"} in friends_unique_movies - assert {"title": "Title E"} in friends_unique_movies + assert len(friends_unique_movies) is 3 + assert INTRIGUE_3 in friends_unique_movies + assert HORROR_1 in friends_unique_movies + assert FANTASY_4 in friends_unique_movies #@pytest.mark.skip(reason="no way of currently testing this") def test_friends_unique_movies_not_duplicated(): # Arrange - amandas_data = { - "watched": [], - "friends": [ - { - "watched": [ - { - "title": "Title A" - }, - { - "title": "Title B" - } - ] - }, - { - "watched": [ - { - "title": "Title A" - }, - { - "title": "Title C" - } - ] - } - ] - } + amandas_data = copy.deepcopy(USER_DATA_3) + amandas_data["friends"][0]["watched"].append(INTRIGUE_3) # Act friends_unique_movies = get_friends_unique_watched(amandas_data) # Arrange assert len(friends_unique_movies) is 3 - assert {"title": "Title A"} in friends_unique_movies - assert {"title": "Title B"} in friends_unique_movies - assert {"title": "Title C"} in friends_unique_movies + assert INTRIGUE_3 in friends_unique_movies + assert HORROR_1 in friends_unique_movies + assert FANTASY_4 in friends_unique_movies #@pytest.mark.skip(reason="no way of currently testing this") def test_friends_not_unique_movies(): # Arrange amandas_data = { "watched": [ - { - "title": "Title A" - }, - { - "title": "Title B" - }, - { - "title": "Title C" - } + HORROR_1, + FANTASY_1, + INTRIGUE_1 ], "friends": [ { "watched": [ - { - "title": "Title A" - }, - { - "title": "Title C" - } + HORROR_1, + FANTASY_1, ] }, { From 2e4ce993abdf3b2f513cb6d13800b6f3536df433 Mon Sep 17 00:00:00 2001 From: Becca Elenzil Date: Mon, 7 Feb 2022 17:01:54 -0800 Subject: [PATCH 21/46] Update wave04 tests with test constants --- .../test_integration_wave_04.py | 6 +- tests/test_constants.py | 32 ++++++++++- tests/unit_tests/test_wave_04.py | 56 +++---------------- 3 files changed, 40 insertions(+), 54 deletions(-) diff --git a/tests/integration_tests/test_integration_wave_04.py b/tests/integration_tests/test_integration_wave_04.py index 4b2a15764..d523c6e37 100644 --- a/tests/integration_tests/test_integration_wave_04.py +++ b/tests/integration_tests/test_integration_wave_04.py @@ -5,10 +5,10 @@ @pytest.mark.integration_test def test_get_available_recs(): #Arrange - user_data = USER_DATA + user_data = USER_DATA_4 rec_movies = get_available_recs(user_data) assert len(rec_movies) == 2 - assert HORROR_1 in rec_movies - assert FANTASY_4 in rec_movies \ No newline at end of file + assert HORROR_1b in rec_movies + assert FANTASY_4b in rec_movies \ No newline at end of file diff --git a/tests/test_constants.py b/tests/test_constants.py index 18317ab6e..4e071d5ae 100644 --- a/tests/test_constants.py +++ b/tests/test_constants.py @@ -134,8 +134,36 @@ INTRIGUE_2b["host"] = "disney+" INTRIGUE_3b["host"] = "disney+" -USER_DATA_4 = copy.deepcopy(USER_DATA_3) -USER_DATA_3["subscriptions"] = ["netflix", "hulu"] +USER_DATA_4 = USER_DATA_2 = { + "watched": [ + FANTASY_1b, + FANTASY_2b, + FANTASY_3b, + ACTION_1b, + INTRIGUE_1b, + INTRIGUE_2b + ], + "friends": [ + { + "watched": [ + FANTASY_1b, + FANTASY_3b, + FANTASY_4b, + HORROR_1b, + ] + }, + { + "watched": [ + FANTASY_1b, + ACTION_1b, + INTRIGUE_1b, + INTRIGUE_3b, + ] + } + ] +} + +USER_DATA_4["subscriptions"] = ["netflix", "hulu"] #----WAVE 5----------- diff --git a/tests/unit_tests/test_wave_04.py b/tests/unit_tests/test_wave_04.py index c21341f27..ef7ab44a5 100644 --- a/tests/unit_tests/test_wave_04.py +++ b/tests/unit_tests/test_wave_04.py @@ -1,74 +1,32 @@ import pytest from viewing_party.party import * +from tests.test_constants import * def test_get_available_friend_rec(): # Arrange - amandas_data = { - "subscriptions": ["Service A", "Service B"], - "watched": [], - "friends": [ - { - "watched": [ - { - "title": "Title A", - "host": "Service A" - }, - { - "title": "Title C", - "host": "Service C" - } - ] - }, - { - "watched": [ - { - "title": "Title A", - "host": "Service A" - }, - { - "title": "Title B", - "host": "Service B" - }, - { - "title": "Title D", - "host": "Service D" - } - ] - } - ] - } + amandas_data = USER_DATA_4 # Act recommendations = get_available_recs(amandas_data) # Arrange assert len(recommendations) is 2 - assert {"title": "Title A", "host": "Service A"} in recommendations - assert {"title": "Title B", "host": "Service B"} in recommendations + assert HORROR_1b in recommendations + assert FANTASY_4b in recommendations def test_no_available_friend_recs(): # Arrange amandas_data = { - "subscriptions": ["Service A", "Service B"], + "subscriptions": ["hulu", "disney+"], "watched": [], "friends": [ { - "watched": [ - { - "title": "Title C", - "host": "Service C" - } - ] + "watched": [HORROR_1b] }, { - "watched": [ - { - "title": "Title D", - "host": "Service D" - } - ] + "watched": [FANTASY_3b] } ] } From 5cb98bd1487d5c6d783f4960bd0c5fa58da78614 Mon Sep 17 00:00:00 2001 From: Becca Elenzil Date: Mon, 7 Feb 2022 17:08:48 -0800 Subject: [PATCH 22/46] Update wave 05 tests --- .../test_integration_wave_05.py | 8 +- tests/unit_tests/test_wave_05.py | 141 ++---------------- 2 files changed, 18 insertions(+), 131 deletions(-) diff --git a/tests/integration_tests/test_integration_wave_05.py b/tests/integration_tests/test_integration_wave_05.py index d99ef893f..32dbc3824 100644 --- a/tests/integration_tests/test_integration_wave_05.py +++ b/tests/integration_tests/test_integration_wave_05.py @@ -5,15 +5,15 @@ @pytest.mark.integration_test def test_recs(): - user_data = USER_DATA + user_data = USER_DATA_5 genre_rec = get_new_rec_by_genre(user_data) assert len(genre_rec) == 1 - assert FANTASY_4 in genre_rec + assert FANTASY_4b in genre_rec favorite_recs = get_rec_from_favorites(user_data) assert len(favorite_recs) == 2 - assert FANTASY_2 in favorite_recs - assert INTRIGUE_2 in favorite_recs \ No newline at end of file + assert FANTASY_2b in favorite_recs + assert INTRIGUE_2b in favorite_recs \ No newline at end of file diff --git a/tests/unit_tests/test_wave_05.py b/tests/unit_tests/test_wave_05.py index b46d57684..f625f93aa 100644 --- a/tests/unit_tests/test_wave_05.py +++ b/tests/unit_tests/test_wave_05.py @@ -1,47 +1,11 @@ import pytest from viewing_party.party import * +from tests.test_constants import * def test_new_genre_rec(): # Arrange - sonyas_data = { - "watched": [ - { - "title": "Title A", - "genre": "Intrigue" - }, - { - "title": "Title B", - "genre": "Intrigue" - }, - { - "title": "Title C", - "genre": "Fantasy" - } - ], - "friends": [ - { - "watched": [ - { - "title": "Title D", - "genre": "Intrigue" - } - ] - }, - { - "watched": [ - { - "title": "Title C", - "genre": "Fantasy" - }, - { - "title": "Title E", - "genre": "Intrigue" - } - ] - } - ] - } + sonyas_data = USER_DATA_5 # Act recommendations = get_new_rec_by_genre(sonyas_data) @@ -49,9 +13,8 @@ def test_new_genre_rec(): # Assert for rec in recommendations: assert rec not in sonyas_data["watched"] - assert len(recommendations) is 2 - assert {"title": "Title D", "genre": "Intrigue"} in recommendations - assert {"title": "Title E", "genre": "Intrigue"} in recommendations + assert len(recommendations) is 1 + assert FANTASY_4b in recommendations def test_new_genre_rec_from_empty_watched(): @@ -60,24 +23,10 @@ def test_new_genre_rec_from_empty_watched(): "watched": [], "friends": [ { - "watched": [ - { - "title": "Title A", - "genre": "Intrigue" - } - ] + "watched": [INTRIGUE_1b] }, { - "watched": [ - { - "title": "Title B", - "genre": "Fantasy" - }, - { - "title": "Title C", - "genre": "Intrigue" - } - ] + "watched": [INTRIGUE_2b,HORROR_1b] } ] } @@ -92,12 +41,7 @@ def test_new_genre_rec_from_empty_watched(): def test_new_genre_rec_from_empty_friends(): # Arrange sonyas_data = { - "watched": [ - { - "title": "Title A", - "genre": "Intrigue" - } - ], + "watched": [INTRIGUE_1b], "friends": [ { "watched": [] @@ -117,53 +61,15 @@ def test_new_genre_rec_from_empty_friends(): def test_unique_rec_from_favorites(): # Arrange - sonyas_data = { - "watched": [ - { - "title": "Title A" - }, - { - "title": "Title B" - }, - { - "title": "Title C" - } - ], - "favorites": [ - { - "title": "Title A" - }, - { - "title": "Title B" - } - ], - "friends": [ - { - "watched": [ - { - "title": "Title B" - } - ] - }, - { - "watched": [ - { - "title": "Title C" - }, - { - "title": "Title D" - } - ] - } - ] - } + sonyas_data = USER_DATA_5 # Act recommendations = get_rec_from_favorites(sonyas_data) # Assert - assert len(recommendations) is 1 - assert {"title": "Title A"} in recommendations + assert len(recommendations) is 2 + assert FANTASY_2b in recommendations + assert INTRIGUE_2b in recommendations def test_unique_from_empty_favorites(): @@ -172,24 +78,10 @@ def test_unique_from_empty_favorites(): "watched": [], "friends": [ { - "watched": [ - { - "title": "Title A", - "genre": "Intrigue" - } - ] + "watched": [INTRIGUE_1b] }, { - "watched": [ - { - "title": "Title B", - "genre": "Fantasy" - }, - { - "title": "Title C", - "genre": "Intrigue" - } - ] + "watched": [INTRIGUE_2b,HORROR_1b] } ] } @@ -204,12 +96,7 @@ def test_unique_from_empty_favorites(): def test_new_rec_from_empty_friends(): # Arrange sonyas_data = { - "watched": [ - { - "title": "Title A", - "genre": "Intrigue" - } - ], + "watched": [INTRIGUE_1b], "friends": [ { "watched": [] From a858892217a17ad205d259ca031d29b5c8266c05 Mon Sep 17 00:00:00 2001 From: Becca Elenzil Date: Mon, 7 Feb 2022 17:11:46 -0800 Subject: [PATCH 23/46] Add assertions to all tests that check the data is preserved --- tests/unit_tests/test_wave_02.py | 2 ++ tests/unit_tests/test_wave_03.py | 2 ++ tests/unit_tests/test_wave_04.py | 1 + tests/unit_tests/test_wave_05.py | 2 ++ 4 files changed, 7 insertions(+) diff --git a/tests/unit_tests/test_wave_02.py b/tests/unit_tests/test_wave_02.py index 30bcfd704..5d8fb769e 100644 --- a/tests/unit_tests/test_wave_02.py +++ b/tests/unit_tests/test_wave_02.py @@ -12,6 +12,7 @@ def test_calculates_watched_average_rating(): # Assert assert average == pytest.approx(3.58333) + assert janes_data is USER_DATA_2 def test_empty_watched_average_rating_is_zero(): @@ -37,6 +38,7 @@ def test_most_watched_genre(): # Assert assert popular_genre is "Fantasy" + assert janes_data is USER_DATA_2 def test_genre_is_None_if_empty_watched(): diff --git a/tests/unit_tests/test_wave_03.py b/tests/unit_tests/test_wave_03.py index 091d30cba..6287c0b48 100644 --- a/tests/unit_tests/test_wave_03.py +++ b/tests/unit_tests/test_wave_03.py @@ -14,6 +14,7 @@ def test_my_unique_movies(): assert len(amandas_unique_movies) is 2 assert FANTASY_2 in amandas_unique_movies assert INTRIGUE_2 in amandas_unique_movies + assert amandas_data is USER_DATA_3 def test_my_not_unique_movies(): @@ -40,6 +41,7 @@ def test_friends_unique_movies(): assert INTRIGUE_3 in friends_unique_movies assert HORROR_1 in friends_unique_movies assert FANTASY_4 in friends_unique_movies + assert amandas_data is USER_DATA_3 #@pytest.mark.skip(reason="no way of currently testing this") def test_friends_unique_movies_not_duplicated(): diff --git a/tests/unit_tests/test_wave_04.py b/tests/unit_tests/test_wave_04.py index ef7ab44a5..67ed09c0a 100644 --- a/tests/unit_tests/test_wave_04.py +++ b/tests/unit_tests/test_wave_04.py @@ -14,6 +14,7 @@ def test_get_available_friend_rec(): assert len(recommendations) is 2 assert HORROR_1b in recommendations assert FANTASY_4b in recommendations + assert amandas_data is USER_DATA_4 def test_no_available_friend_recs(): diff --git a/tests/unit_tests/test_wave_05.py b/tests/unit_tests/test_wave_05.py index f625f93aa..07d87f909 100644 --- a/tests/unit_tests/test_wave_05.py +++ b/tests/unit_tests/test_wave_05.py @@ -15,6 +15,7 @@ def test_new_genre_rec(): assert rec not in sonyas_data["watched"] assert len(recommendations) is 1 assert FANTASY_4b in recommendations + assert sonyas_data is USER_DATA_5 def test_new_genre_rec_from_empty_watched(): @@ -70,6 +71,7 @@ def test_unique_rec_from_favorites(): assert len(recommendations) is 2 assert FANTASY_2b in recommendations assert INTRIGUE_2b in recommendations + assert sonyas_data is USER_DATA_5 def test_unique_from_empty_favorites(): From ab71a1d28da3cfe614e754c5b9ba2b9163be3141 Mon Sep 17 00:00:00 2001 From: Becca Elenzil Date: Tue, 8 Feb 2022 09:10:09 -0800 Subject: [PATCH 24/46] Add fun movie names from Kaida --- tests/test_constants.py | 37 +++++++++++-------------------------- 1 file changed, 11 insertions(+), 26 deletions(-) diff --git a/tests/test_constants.py b/tests/test_constants.py index 4e071d5ae..f1a3ea79e 100644 --- a/tests/test_constants.py +++ b/tests/test_constants.py @@ -1,78 +1,63 @@ import copy #----------WAVE01------------- -MOVIE_TITLE_1 = "It came from the stack trace" +MOVIE_TITLE_1 = "It Came from the Stack Trace" GENRE_1 = "Horror" RATING_1 = 3.5 -EMPTY_USER_DATA = { - "watched": [], - "watchlist": [], -} - #----------WAVE02------------- HORROR_1 = { "title": MOVIE_TITLE_1, "genre": GENRE_1, "rating": RATING_1 } - FANTASY_1 = { - "title": "Fantasy 1", + "title": "The Lord of the Functions: The Fellowship of the Function", "genre": "Fantasy", "rating": 4.8 } - FANTASY_2 = { - "title": "Fantasy 2", + "title": "The Lord of the Functions: The Two Parameters", "genre": "Fantasy", "rating": 4.0 } - FANTASY_3 = { - "title": "Fantasy 3", + "title": "The Lord of the Functions: The Return of the Value", "genre": "Fantasy", "rating": 4.0 } - FANTASY_4 = { - "title": "Fantasy 4", + "title": "The Programmer: An Unexpected Stack Trace", "genre": "Fantasy", "rating": 4.0 } - ACTION_1 = { - "title": "Action 1", + "title": "The JavaScript and the React", "genre": "Action", "rating": 2.2 } - ACTION_2 = { - "title": "Action 2", + "title": "2 JavaScript 2 React", "genre": "Action", "rating": 4.2 } - ACTION_3 = { - "title": "Action 3", + "title": "JavaScript 3: VS Code Lint", "genre": "Action", "rating": 3.5 } - INTRIGUE_1 = { - "title": "Intrigue 1", + "title": "Recursion", "genre": "Intrigue", "rating": 2.0 } - INTRIGUE_2 = { - "title": "Intrigue 2", + "title": "Instructor Student TA Manager", "genre": "Intrigue", "rating": 4.5 } - INTRIGUE_3 = { - "title": "Intrigue 3", + "title": "Zero Dark Python", "genre": "Intrigue", "rating": 3.0 } From d9bc1e95d44d10fda7f3704eb01cf1d0b9a2dc76 Mon Sep 17 00:00:00 2001 From: Becca Elenzil Date: Tue, 8 Feb 2022 09:11:47 -0800 Subject: [PATCH 25/46] Delete integration tests and reorg unit tests --- tests/integration_tests/__init__.py | 0 .../test_integration_wave_01.py | 41 ------------------- .../test_integration_wave_02.py | 24 ----------- .../test_integration_wave_03.py | 20 --------- .../test_integration_wave_04.py | 14 ------- .../test_integration_wave_05.py | 19 --------- tests/{unit_tests => }/test_wave_01.py | 0 tests/{unit_tests => }/test_wave_02.py | 0 tests/{unit_tests => }/test_wave_03.py | 0 tests/{unit_tests => }/test_wave_04.py | 0 tests/{unit_tests => }/test_wave_05.py | 0 11 files changed, 118 deletions(-) delete mode 100644 tests/integration_tests/__init__.py delete mode 100644 tests/integration_tests/test_integration_wave_01.py delete mode 100644 tests/integration_tests/test_integration_wave_02.py delete mode 100644 tests/integration_tests/test_integration_wave_03.py delete mode 100644 tests/integration_tests/test_integration_wave_04.py delete mode 100644 tests/integration_tests/test_integration_wave_05.py rename tests/{unit_tests => }/test_wave_01.py (100%) rename tests/{unit_tests => }/test_wave_02.py (100%) rename tests/{unit_tests => }/test_wave_03.py (100%) rename tests/{unit_tests => }/test_wave_04.py (100%) rename tests/{unit_tests => }/test_wave_05.py (100%) diff --git a/tests/integration_tests/__init__.py b/tests/integration_tests/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/integration_tests/test_integration_wave_01.py b/tests/integration_tests/test_integration_wave_01.py deleted file mode 100644 index 0774c2da7..000000000 --- a/tests/integration_tests/test_integration_wave_01.py +++ /dev/null @@ -1,41 +0,0 @@ -import pytest -from viewing_party.party import * -from tests.test_constants import * - -@pytest.mark.integration_test -def test_create_and_watch_movie(): - # Arrange - movie_title = MOVIE_TITLE_1 - genre = GENRE_1 - rating = RATING_1 - user_data = {"watched": [], "watchlist": []} - - # Act - # create movie - new_movie = create_movie(movie_title, genre, rating) - - # add movie to watchlist - add_to_watchlist(user_data, new_movie) - - # check that the movie is the first item in the watch list - assert user_data["watchlist"][0]["title"] == MOVIE_TITLE_1 - assert user_data["watchlist"][0]["genre"] == GENRE_1 - assert user_data["watchlist"][0]["rating"] == RATING_1 - - # watch movie - watch_movie(user_data, movie_title) - - #check that watch list is empty and new movie is in watched - assert user_data["watchlist"] == [] - assert user_data["watched"][0]["title"] == MOVIE_TITLE_1 - assert user_data["watched"][0]["genre"] == GENRE_1 - assert user_data["watched"][0]["rating"] == RATING_1 - - # try to watch movie not in watchlist - watch_movie(user_data, movie_title) - - # confirm there is still only 1 movie in watched - assert len(user_data["watched"]) == 1 - - - diff --git a/tests/integration_tests/test_integration_wave_02.py b/tests/integration_tests/test_integration_wave_02.py deleted file mode 100644 index fc971f4bb..000000000 --- a/tests/integration_tests/test_integration_wave_02.py +++ /dev/null @@ -1,24 +0,0 @@ -import pytest -from viewing_party.party import * -from tests.test_constants import * - -@pytest.mark.integration_test -def test_get_most_watched_genre(): - # Arrange - user_data = USER_DATA_2 - empty_user_data = EMPTY_USER_DATA - - # user data - most_watched = get_most_watched_genre(user_data) - average_rating = get_watched_avg_rating(user_data) - assert most_watched == "Fantasy" - assert average_rating == pytest.approx(3.58333) - - # empty user data - most_watched = get_most_watched_genre(empty_user_data) - average_rating = get_watched_avg_rating(empty_user_data) - assert most_watched == None - assert average_rating == 0 - - - \ No newline at end of file diff --git a/tests/integration_tests/test_integration_wave_03.py b/tests/integration_tests/test_integration_wave_03.py deleted file mode 100644 index 73d28a4ba..000000000 --- a/tests/integration_tests/test_integration_wave_03.py +++ /dev/null @@ -1,20 +0,0 @@ -import pytest -from viewing_party.party import * -from tests.test_constants import * - -@pytest.mark.integration_test -def test_get_friends_unique(): - user_data = USER_DATA_3 - - unique_movies = get_unique_watched(user_data) - - assert FANTASY_2 in unique_movies - assert INTRIGUE_2 in unique_movies - assert len(unique_movies) == 2 - - friend_unique_movies = get_friends_unique_watched(user_data) - - assert len(friend_unique_movies) == 3 - assert INTRIGUE_3 in friend_unique_movies - assert HORROR_1 in friend_unique_movies - assert FANTASY_4 in friend_unique_movies \ No newline at end of file diff --git a/tests/integration_tests/test_integration_wave_04.py b/tests/integration_tests/test_integration_wave_04.py deleted file mode 100644 index d523c6e37..000000000 --- a/tests/integration_tests/test_integration_wave_04.py +++ /dev/null @@ -1,14 +0,0 @@ -import pytest -from viewing_party.party import * -from tests.test_constants import * - -@pytest.mark.integration_test -def test_get_available_recs(): - #Arrange - user_data = USER_DATA_4 - - rec_movies = get_available_recs(user_data) - - assert len(rec_movies) == 2 - assert HORROR_1b in rec_movies - assert FANTASY_4b in rec_movies \ No newline at end of file diff --git a/tests/integration_tests/test_integration_wave_05.py b/tests/integration_tests/test_integration_wave_05.py deleted file mode 100644 index 32dbc3824..000000000 --- a/tests/integration_tests/test_integration_wave_05.py +++ /dev/null @@ -1,19 +0,0 @@ -from cmath import rect -import pytest -from viewing_party.party import * -from tests.test_constants import * - -@pytest.mark.integration_test -def test_recs(): - user_data = USER_DATA_5 - - genre_rec = get_new_rec_by_genre(user_data) - - assert len(genre_rec) == 1 - assert FANTASY_4b in genre_rec - - favorite_recs = get_rec_from_favorites(user_data) - - assert len(favorite_recs) == 2 - assert FANTASY_2b in favorite_recs - assert INTRIGUE_2b in favorite_recs \ No newline at end of file diff --git a/tests/unit_tests/test_wave_01.py b/tests/test_wave_01.py similarity index 100% rename from tests/unit_tests/test_wave_01.py rename to tests/test_wave_01.py diff --git a/tests/unit_tests/test_wave_02.py b/tests/test_wave_02.py similarity index 100% rename from tests/unit_tests/test_wave_02.py rename to tests/test_wave_02.py diff --git a/tests/unit_tests/test_wave_03.py b/tests/test_wave_03.py similarity index 100% rename from tests/unit_tests/test_wave_03.py rename to tests/test_wave_03.py diff --git a/tests/unit_tests/test_wave_04.py b/tests/test_wave_04.py similarity index 100% rename from tests/unit_tests/test_wave_04.py rename to tests/test_wave_04.py diff --git a/tests/unit_tests/test_wave_05.py b/tests/test_wave_05.py similarity index 100% rename from tests/unit_tests/test_wave_05.py rename to tests/test_wave_05.py From 5e65697f393403973e9072e6ab9b7f81535b8bde Mon Sep 17 00:00:00 2001 From: Becca Elenzil Date: Tue, 8 Feb 2022 09:12:08 -0800 Subject: [PATCH 26/46] Remove extra playground file --- playground.py | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 playground.py diff --git a/playground.py b/playground.py deleted file mode 100644 index 6a57a5f88..000000000 --- a/playground.py +++ /dev/null @@ -1,17 +0,0 @@ -all_genres = ['horror', 'comedy', 'indie', 'comedy'] -max(set(all_genres), key=all_genres.count) - -max = 0 -max_genre = None - -for genre in set(all_genres): - count = 0 - for genre_item in all_genres: - if genre_item == genre: - count += 1 - if count > max: - max = count - max_genre = genre - -print(max) -print(max_genre) \ No newline at end of file From c12d458e57a365815ffbe6a020f777e773807184 Mon Sep 17 00:00:00 2001 From: Becca Elenzil Date: Tue, 8 Feb 2022 09:18:03 -0800 Subject: [PATCH 27/46] Add pprint to requirements.txt --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 77ffa3f4a..a1f490d3d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,6 +2,7 @@ attrs==20.3.0 iniconfig==1.1.1 packaging==20.8 pluggy==0.13.1 +pprintpp==0.4.0 py==1.10.0 pyparsing==2.4.7 pytest==6.2.1 From cd8367f22948889fb9cd4a42617a1b8ca3ed208c Mon Sep 17 00:00:00 2001 From: Becca Elenzil Date: Tue, 8 Feb 2022 09:41:13 -0800 Subject: [PATCH 28/46] Update steps in README to include writing tests --- README.md | 51 ++++++++++++++++++++++++++++++++--------- play_tester.py | 21 +++++++++-------- tests/test_constants.py | 4 +++- tests/test_wave_02.py | 1 - 4 files changed, 55 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 27fbdcf45..38cc15d8b 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,8 @@ Summary of one-time project setup: ## Project Development Workflow +We will use a Test Driven Development programming workflow to work on this project. + 1. When you want to begin work on this project, ensure that your virtual environment is activated: ```bash @@ -89,28 +91,46 @@ $ source venv/bin/activate - In that test file, read through each test case - Remove all lines that contain `@pytest.mark.skip()` -3. Run the tests! +3. Check if the test is complete or not. + + - If it is incomplete, write the test. + - Is this a nominal or edge case? + - What type of input do we need to test this case? + - What is the expected output for the given input? + + - If it is complete, read the test critically. + - How does this test map on to the requirement described in the project instructions? + - What is the expected output for the given input? + +4. Run the test(s)! (RED) ```bash -# Must be in activated virtual environment +# Must be in activated virtual environment in the project-root directory $ pytest ``` -4. Focus on the top test failure. Read through the test failure, and understand why the failure is happening. Confirm your findings with a classmate. +```bash +# To run a single test by name, for example +$ pytest tests/test_wave_01.py::test_create_successful_movie +``` + +5. Focus on the top test failure. Read through the test failure, and understand why the failure is happening. Confirm your findings with a classmate. -5. Make a plan to fix the test failure. +6. Make a plan to implement code to pass the test. -6. Write code to fix the test failure. +7. Write code to pass the test. -7. Re-run the tests. +8. Re-run the tests. -8. Repeat steps 5-7 until that test passes! +9. Repeat steps 4-8 until that test passes! (GREEN) -9. Repeats steps 4-8 until you have finished all tests in the file. +10. Repeats steps 3-9 until you have finished all tests in the file. -10. Begin using the test file of the next wave! +11. Begin using the test file of the next wave! -11. When you are finished working for the day, deactivate your environment with deactivate or closing the Terminal tab/window +12. Look for opportunities to improve your code (REFACTOR) + +13. When you are finished working for the day, deactivate your environment with deactivate or closing the Terminal tab/window ```bash $ deactivate @@ -118,6 +138,8 @@ $ deactivate ## Details About How to Run Tests +The following commands should be run from the project-root directory. + Run all unskipped tests that exist in this project with: ```bash @@ -139,7 +161,14 @@ If you want to run all unskipped tests that exist in one file, use: $ pytest tests/test_file_name.py ``` -... where `test_file_name.py` is relpaced with the correct test file name. +If you want to run a single test by name: + +```bash +# Must be in activated virtual environment +$ pytest tests/test_file_name.py::test_name +``` + +... where `test_name` is relpaced with the function name for the test. ## Project Write-Up: How to Complete and Submit diff --git a/play_tester.py b/play_tester.py index 122ae47ef..f201ceadc 100644 --- a/play_tester.py +++ b/play_tester.py @@ -1,22 +1,25 @@ -# from viewing_party.main import * +# import source code from viewing_party.party import * + +# import test data from tests.test_constants import * + +# import "pretty-print" library import pprint +# use library to print data structures in a nicely formatted way pp = pprint.PrettyPrinter(indent=4) -# Wave 02 user data print("\n-----Wave 02 user_data-----") pp.pprint(USER_DATA_2) -# Wave 03 user data -print("\n-----Wave 03 user_data-----") -pp.pprint(USER_DATA_3) +#print("\n-----Wave 03 user_data-----") +#pp.pprint(USER_DATA_3) # Wave 04 user data -print("\n-----Wave 04 user_data-----") -pp.pprint(USER_DATA_4) +#print("\n-----Wave 04 user_data-----") +#pp.pprint(USER_DATA_4) # Wave 05 user data -print("\n-----Wave 05 user_data-----") -pp.pprint(USER_DATA_4) +#print("\n-----Wave 05 user_data-----") +#pp.pprint(USER_DATA_5) diff --git a/tests/test_constants.py b/tests/test_constants.py index f1a3ea79e..1a4963c35 100644 --- a/tests/test_constants.py +++ b/tests/test_constants.py @@ -1,5 +1,7 @@ import copy +# Data for Unit Tests + #----------WAVE01------------- MOVIE_TITLE_1 = "It Came from the Stack Trace" GENRE_1 = "Horror" @@ -119,7 +121,7 @@ INTRIGUE_2b["host"] = "disney+" INTRIGUE_3b["host"] = "disney+" -USER_DATA_4 = USER_DATA_2 = { +USER_DATA_4 = { "watched": [ FANTASY_1b, FANTASY_2b, diff --git a/tests/test_wave_02.py b/tests/test_wave_02.py index 5d8fb769e..a8e2c047a 100644 --- a/tests/test_wave_02.py +++ b/tests/test_wave_02.py @@ -2,7 +2,6 @@ from viewing_party.party import * from tests.test_constants import USER_DATA_2 - def test_calculates_watched_average_rating(): # Arrange janes_data = USER_DATA_2 From bc04286bdc3ce11a675c6ff3d524e3396fee2c4b Mon Sep 17 00:00:00 2001 From: Becca Elenzil Date: Tue, 8 Feb 2022 09:53:46 -0800 Subject: [PATCH 29/46] Update project directions with C16 updates --- README.md | 76 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 45 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 38cc15d8b..aa7a187ee 100644 --- a/README.md +++ b/README.md @@ -138,41 +138,55 @@ $ deactivate ## Details About How to Run Tests -The following commands should be run from the project-root directory. +All the commands described below should be run from the project-root directory `viewing-party`. Note that the project-root directory is the repository `viewing-party`. It is distinct from the directory `viewing_party` that contains the source code in `party.py`. -Run all unskipped tests that exist in this project with: +To run all unskipped tests that exist in this project with: ```bash # Must be in activated virtual environment $ pytest ``` -If you want to see any `print` statements print to the console, add `-s` to the end of any `pytest` command: +To see any `print` statements print to the console, add `-s` to the end of any `pytest` command: ```bash # Must be in activated virtual environment $ pytest -s ``` -If you want to run all unskipped tests that exist in one file, use: +To run all unskipped tests that exist in one file, use: ```bash # Must be in activated virtual environment $ pytest tests/test_file_name.py ``` -If you want to run a single test by name: +... where `test_file_name.py` is relpaced with the correct test file name. + +To run a single test by name: ```bash # Must be in activated virtual environment $ pytest tests/test_file_name.py::test_name ``` -... where `test_name` is relpaced with the function name for the test. +... where `test_name.py` is relpaced with the name of the function. + +## Play Testing + +While we will mainly use a Test Driven Development (TDD) workflow for this project, it can be helpful to run code independently from running tests. To do this, a file `play_tester.py` is provided. + +To run this file, use: + +```bash +python3 play_tester.py +``` + +There is some starter code provided in `play_tester.py`. This code prints the test data that is used for many of the tests. Looking closely at this data can help us think critically about the expected output for given input for each function. Then, calling each function with this data allows us to observe the **actual** output for given input. ## Project Write-Up: How to Complete and Submit -The goal of this project is to write code in `main.py` so that as many of the tests pass as possible. +The goal of this project is to write code in `party.py` so that as many of the tests pass as possible. To complete this project, use the above workflow and follow these steps: @@ -194,22 +208,22 @@ When our test failures leave us confused and stuck, let's use the detailed proje 1. The first four tests are about a `create_movie()` function. -In `main.py`, there should be a function named `create_movie`. This function should... +In `party.py`, there should be a function named `create_movie`. This function should... - take three parameters: `title`, `genre`, `rating` -- If those there attributes are truthy, then return a dictionary. This dictionary should... +- If those three attributes are truthy, then return a dictionary. This dictionary should... - Have three key-value pairs, with specific keys - The three keys should be `"title"`, `"genre"`, and `"rating"` - The values of these key-value pairs should be appropriate values - If `title` is falsy, `genre` is falsy, or `rating` is falsy, this function should return `None` -2. The next test is about a `add_to_watched()` function. +2. The next two tests are about an `add_to_watched()` function. -In `main.py`, there should be a function named `add_to_watched`. This function should... +In `party.py`, there should be a function named `add_to_watched`. This function should... - take two parameters: `user_data`, `movie` - - the value of `user_data` will be a dictionary with a key `"watched"`, and a value `[]` - - This represents that the user has no movies in their watched list + - the value of `user_data` will be a dictionary with a key `"watched"`, and a value which is a list of dictionaries representing the movies the user has watched + - An empty list represents that the user has no movies in their watched list - the value of `movie` will be a dictionary in this format: - ```python { @@ -221,13 +235,13 @@ In `main.py`, there should be a function named `add_to_watched`. This function s - add the `movie` to the `"watched"` list inside of `user_data` - return the `user_data` -3. The next test is about a `add_to_watchlist()` function. +3. The next two tests are about an `add_to_watchlist()` function. -In `main.py`, there should be a function named `add_to_watchlist`. This function should... +In `party.py`, there should be a function named `add_to_watchlist`. This function should... - take two parameters: `user_data`, `movie` - - the value of `user_data` will be a dictionary with a key `"watchlist"`, and a value `[]` - - This represents that the user has no movies in their watchlist + - the value of `user_data` will be a dictionary with a key `"watchlist"`, and a value which is a list of dictionaries representing the movies the user wants to watch + - An empty list represents that the user has no movies in their watchlist - the value of `movie` will be a dictionary in this format: - ```python { @@ -241,7 +255,7 @@ In `main.py`, there should be a function named `add_to_watchlist`. This function 4. There are three tests about a `watch_movie()` function. -In `main.py`, there should be a function named `watch_movie`. This function should... +In `party.py`, there should be a function named `watch_movie`. This function should... - take two parameters: `user_data`, `title` - the value of `user_data` will be a dictionary with a `"watchlist"` and a `"watched"` @@ -259,7 +273,7 @@ In `main.py`, there should be a function named `watch_movie`. This function shou 1. The first two tests are about a `get_watched_avg_rating()` function. -In `main.py`, there should be a function named `get_watched_avg_rating`. This function should... +In `party.py`, there should be a function named `get_watched_avg_rating`. This function should... - take one parameter: `user_data` - the value of `user_data` will be a dictionary with a `"watched"` list of movie dictionaries @@ -268,9 +282,9 @@ In `main.py`, there should be a function named `get_watched_avg_rating`. This fu - The average rating of an empty watched list is `0.0` - return the average rating -2. The next two tests are about a `get_most_watched_genre()` function. +2. The next three tests are about a `get_most_watched_genre()` function. -In `main.py`, there should be a function named `get_watched_avg_rating`. This function should... +In `party.py`, there should be a function named `get_most_watched_genre`. This function should... - take one parameter: `user_data` - the value of `user_data` will be a dictionary with a `"watched"` list of movie dictionaries. Each movie dictionary has a key `"genre"`. @@ -283,7 +297,7 @@ In `main.py`, there should be a function named `get_watched_avg_rating`. This fu 1. The first two tests are about a `get_unique_watched()` function. -In `main.py`, there should be a function named `get_unique_watched`. This function should... +In `party.py`, there should be a function named `get_unique_watched`. This function should... - take one parameter: `user_data` - the value of `user_data` will be a dictionary with a `"watched"` list of movie dictionaries, and a `"friends"` @@ -294,9 +308,9 @@ In `main.py`, there should be a function named `get_unique_watched`. This functi - Consider the movies that the user has watched, and consider the movies that their friends have watched. Determine which movies the user has watched, but none of their friends have watched. - Return a list of dictionaries, that represents a list of movies -2. The next two tests are about a `get_friends_unique_watched()` function. +2. The next three tests are about a `get_friends_unique_watched()` function. -In `main.py`, there should be a function named `get_friends_unique_watched`. This function should... +In `party.py`, there should be a function named `get_friends_unique_watched`. This function should... - take one parameter: `user_data` - the value of `user_data` will be a dictionary with a `"watched"` list of movie dictionaries, and a `"friends"` @@ -304,19 +318,19 @@ In `main.py`, there should be a function named `get_friends_unique_watched`. Thi - The value of `"friends"` is a list - Each item in `"friends"` is a dictionary. This dictionary has a key `"watched"`, which has a list of movie dictionaries. - Each movie dictionary has a `"title"`. -- Consider the movies that the user has watched, and consider the movies that their friends have watched. Determine which movies the user's friends have watched, but the user has not watched. +- Consider the movies that the user has watched, and consider the movies that their friends have watched. Determine which movies at least one of the user's friends have watched, but the user has not watched. - Return a list of dictionaries, that represents a list of movies ### Wave 4 -1. There are two tests about a `get_available_recs` function +1. There are four tests about a `get_available_recs` function Create a function named `get_available_recs` - takes one parameter: `user_data` - `user_data` will have a field `"subscriptions"`. The value of `"subscriptions"` is a list of strings - This represents the names of streaming services that the user has access to - - each friend in `"friends"` has a watched list. Each movie in the watched list has a `"host"`, which a string that says what streaming service it's hosted on + - Each friend in `"friends"` has a watched list. Each movie in the watched list has a `"host"`, which is a string that says what streaming service it's hosted on - Determine a list of recommended movies. A movie should be added to this list if and only if: - The user has not watched it - At least one of the user's friends has watched @@ -325,7 +339,7 @@ Create a function named `get_available_recs` ### Wave 5 -1. There are five tests about a `get_new_rec_by_genre` function +1. There are four tests about a `get_new_rec_by_genre` function Create a function named `get_new_rec_by_genre` @@ -336,14 +350,14 @@ Create a function named `get_new_rec_by_genre` - The `"genre"` of the movie is the same as the user's most frequent genre - Return the list of recommended movies -1. There are three tests about a `get_rec_from_favorites` function +2. There are also two tests about a `get_rec_from_favorites` function -Create a function named `get_new_rec_by_genre` +Create a function named `get_rec_from_favorites` - takes one parameter: `user_data` - `user_data` will have a field `"favorites"`. The value of `"favorites"` is a list of movie dictionaries - This represents the user's favorite movies -- Consider the user's most frequently watched genre. Then, determine a list of recommended movies. A movie should be added to this list if and only if: +- Then, determine a list of recommended movies. A movie should be added to this list if and only if: - The movie is in the user's `"favorites"` - None of the user's friends have watched it - Return the list of recommended movies From 78fbab37c47a308f5cd02df959ba1fa040c3ee63 Mon Sep 17 00:00:00 2001 From: Becca Elenzil Date: Tue, 8 Feb 2022 09:58:41 -0800 Subject: [PATCH 30/46] Remove how to complete and submit section --- README.md | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index aa7a187ee..184a1da42 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Solving problems with... You and your friends enjoy watching things together online. Of course, everyone has seen different things, has different favorites, and different things they want to watch. -You've been using a spreadsheet to compare everyone's watched list, favorites list, and watchlist, but it's been getting too cumbersome. In order to find things you've watched and your friends haven't watched, or things that your friends have watched and yo haven't watched, you have to comb through the spreadsheet. You know that there are different ways we can get that information: we can use Python! +You've been using a spreadsheet to compare everyone's watched list, favorites list, and watchlist, but it's been getting too cumbersome. In order to find things you've watched and your friends haven't watched, or things that your friends have watched and you haven't watched, you have to comb through the spreadsheet. You know that there are different ways we can get that information: we can use Python! For this project, you will be given some data structure that represents the things you've watched, favorited, and want to watch. The directions below will lead you to create a series of functions. These functions will modify the data, and implement features like adding and removing things between different lists. Other features include creating recommendations! @@ -118,7 +118,7 @@ $ pytest tests/test_wave_01.py::test_create_successful_movie 6. Make a plan to implement code to pass the test. -7. Write code to pass the test. +7. Write code in `party.py` to pass the test. 8. Re-run the tests. @@ -136,6 +136,8 @@ $ pytest tests/test_wave_01.py::test_create_successful_movie $ deactivate ``` +Finally, at submission time, **no matter where you are**, submit the project via Learn. + ## Details About How to Run Tests All the commands described below should be run from the project-root directory `viewing-party`. Note that the project-root directory is the repository `viewing-party`. It is distinct from the directory `viewing_party` that contains the source code in `party.py`. @@ -184,20 +186,6 @@ python3 play_tester.py There is some starter code provided in `play_tester.py`. This code prints the test data that is used for many of the tests. Looking closely at this data can help us think critically about the expected output for given input for each function. Then, calling each function with this data allows us to observe the **actual** output for given input. -## Project Write-Up: How to Complete and Submit - -The goal of this project is to write code in `party.py` so that as many of the tests pass as possible. - -To complete this project, use the above workflow and follow these steps: - -1. Start with making the tests in `test_wave_01.py` pass. -1. Review your code in `main.py` and see if there are ways you can make the code more readable. -1. Then, work on making the tests in `test_wave_02.py` pass. -1. Review your code in `main.py` -1. Repeat on all test files until submission time. - -At submission time, no matter where you are, submit the project via Learn. - ## Project Directions This project is designed such that one could puzzle together how to implement this project without many directions. Being able to read tests to understand what is expected of our program is a skill that needs to be developed; programmers often take years to develop this skill competently. From 7112b6472260a10b644c9d3107b09beadc51f98c Mon Sep 17 00:00:00 2001 From: Becca Elenzil Date: Tue, 8 Feb 2022 10:13:27 -0800 Subject: [PATCH 31/46] Add pytest.mark.skip --- README.md | 12 ++++-------- tests/test_wave_01.py | 18 +++++++++--------- tests/test_wave_02.py | 7 ++++--- tests/test_wave_03.py | 10 +++++----- tests/test_wave_04.py | 4 ++-- tests/test_wave_05.py | 12 ++++++------ 6 files changed, 30 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 184a1da42..7861128fa 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ Summary of one-time project setup: ## Project Development Workflow -We will use a Test Driven Development programming workflow to work on this project. +We will use a Test Driven Development programming workflow to work on this project. Notice the Red-Green-Refactor steps in the workflow steps outlined below. 1. When you want to begin work on this project, ensure that your virtual environment is activated: @@ -91,7 +91,7 @@ $ source venv/bin/activate - In that test file, read through each test case - Remove all lines that contain `@pytest.mark.skip()` -3. Check if the test is complete or not. +3. For each test, check if the test is complete or not. - If it is incomplete, write the test. - Is this a nominal or edge case? @@ -109,12 +109,8 @@ $ source venv/bin/activate $ pytest ``` -```bash -# To run a single test by name, for example -$ pytest tests/test_wave_01.py::test_create_successful_movie -``` - -5. Focus on the top test failure. Read through the test failure, and understand why the failure is happening. Confirm your findings with a classmate. +5. Focus on the top test failure. Read through the test failure, and understand why the failure is happening. Confirm your findings with a classmate. + - If it is a test you wrote, consider whether you are actually testing what you intend to test. Does this test need modification? 6. Make a plan to implement code to pass the test. diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index 603db597d..6d573e685 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() def test_create_successful_movie(): # Arrange movie_title = MOVIE_TITLE_1 @@ -19,7 +19,7 @@ def test_create_successful_movie(): assert new_movie["genre"] is GENRE_1 assert new_movie["rating"] is RATING_1 - +@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() 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() 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() def test_adds_movie_to_user_watched(): # Arrange movie = { @@ -79,7 +79,7 @@ def test_adds_movie_to_user_watched(): assert updated_data["watched"][0]["genre"] is GENRE_1 assert updated_data["watched"][0]["rating"] is RATING_1 - +@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() def test_moves_movie_from_watchlist_to_empty_watched(): # Arrange janes_data = { @@ -122,7 +122,7 @@ def test_moves_movie_from_watchlist_to_empty_watched(): assert updated_data["watched"][0]["genre"] is GENRE_1 assert updated_data["watched"][0]["rating"] is RATING_1 - +@pytest.mark.skip() def test_moves_movie_from_watchlist_to_watched(): # Arrange movie_to_watch = HORROR_1 @@ -142,7 +142,7 @@ def test_moves_movie_from_watchlist_to_watched(): assert len(updated_data["watched"]) is 2 assert movie_to_watch in updated_data["watched"] - +@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 a8e2c047a..3fb185934 100644 --- a/tests/test_wave_02.py +++ b/tests/test_wave_02.py @@ -2,6 +2,7 @@ from viewing_party.party import * from tests.test_constants import USER_DATA_2 +@pytest.mark.skip() def test_calculates_watched_average_rating(): # Arrange janes_data = USER_DATA_2 @@ -13,7 +14,7 @@ def test_calculates_watched_average_rating(): assert average == pytest.approx(3.58333) assert janes_data is USER_DATA_2 - +@pytest.mark.skip() def test_empty_watched_average_rating_is_zero(): # Arrange janes_data = { @@ -27,7 +28,7 @@ def test_empty_watched_average_rating_is_zero(): # Assert assert average == pytest.approx(0.0) - +@pytest.mark.skip() def test_most_watched_genre(): # Arrange janes_data = USER_DATA_2 @@ -39,7 +40,7 @@ def test_most_watched_genre(): assert popular_genre is "Fantasy" assert janes_data is USER_DATA_2 - +@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 6287c0b48..6a663a426 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() def test_my_unique_movies(): # Arrange amandas_data = USER_DATA_3 @@ -16,7 +16,7 @@ def test_my_unique_movies(): assert INTRIGUE_2 in amandas_unique_movies assert amandas_data is USER_DATA_3 - +@pytest.mark.skip() def test_my_not_unique_movies(): # Arrange amandas_data = copy.deepcopy(USER_DATA_3) @@ -28,7 +28,7 @@ def test_my_not_unique_movies(): # Arrange assert len(amandas_unique_movies) is 0 -#@pytest.mark.skip(reason="no way of currently testing this") +@pytest.mark.skip() def test_friends_unique_movies(): # Arrange amandas_data = USER_DATA_3 @@ -43,7 +43,7 @@ def test_friends_unique_movies(): assert FANTASY_4 in friends_unique_movies assert amandas_data is USER_DATA_3 -#@pytest.mark.skip(reason="no way of currently testing this") +@pytest.mark.skip() def test_friends_unique_movies_not_duplicated(): # Arrange amandas_data = copy.deepcopy(USER_DATA_3) @@ -58,7 +58,7 @@ def test_friends_unique_movies_not_duplicated(): assert HORROR_1 in friends_unique_movies assert FANTASY_4 in friends_unique_movies -#@pytest.mark.skip(reason="no way of currently testing this") +@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 67ed09c0a..1b339fbea 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() def test_get_available_friend_rec(): # Arrange amandas_data = USER_DATA_4 @@ -16,7 +16,7 @@ def test_get_available_friend_rec(): assert FANTASY_4b in recommendations assert amandas_data is USER_DATA_4 - +@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 07d87f909..a68f3bffc 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() def test_new_genre_rec(): # Arrange sonyas_data = USER_DATA_5 @@ -17,7 +17,7 @@ def test_new_genre_rec(): assert FANTASY_4b in recommendations assert sonyas_data is USER_DATA_5 - +@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) is 0 - +@pytest.mark.skip() def test_new_genre_rec_from_empty_friends(): # Arrange sonyas_data = { @@ -59,7 +59,7 @@ def test_new_genre_rec_from_empty_friends(): # Assert assert len(recommendations) is 0 - +@pytest.mark.skip() def test_unique_rec_from_favorites(): # Arrange sonyas_data = USER_DATA_5 @@ -73,7 +73,7 @@ def test_unique_rec_from_favorites(): assert INTRIGUE_2b in recommendations assert sonyas_data is USER_DATA_5 - +@pytest.mark.skip() def test_unique_from_empty_favorites(): # Arrange sonyas_data = { @@ -94,7 +94,7 @@ def test_unique_from_empty_favorites(): # Assert assert len(recommendations) is 0 - +@pytest.mark.skip() def test_new_rec_from_empty_friends(): # Arrange sonyas_data = { From 21fcbbcb18e57062faecfd56dc95de6d03f1ee45 Mon Sep 17 00:00:00 2001 From: Becca Elenzil Date: Tue, 8 Feb 2022 10:32:21 -0800 Subject: [PATCH 32/46] Renumber workflow steps and remove solution --- README.md | 43 ++++++------ viewing_party/party.py | 148 +---------------------------------------- 2 files changed, 20 insertions(+), 171 deletions(-) diff --git a/README.md b/README.md index 7861128fa..b2303d279 100644 --- a/README.md +++ b/README.md @@ -87,46 +87,41 @@ $ source venv/bin/activate 2. Find the test file that contains the test you want to run. Ensure that the test(s) you want to run isn't skipped. - - Check the `tests` folder, and find the test file you want to run + - Check the `tests` folder, and find the test file you want to run - In that test file, read through each test case - - Remove all lines that contain `@pytest.mark.skip()` + - If it is incomplete, complete the test. + - *Is this a nominal or edge case?* + - *What type of input do we need to test this case?* + - *What is the expected output for the given input?* + - Remove the lines that contain `@pytest.mark.skip()` for the test(s) you want to run. -3. For each test, check if the test is complete or not. - - - If it is incomplete, write the test. - - Is this a nominal or edge case? - - What type of input do we need to test this case? - - What is the expected output for the given input? - - - If it is complete, read the test critically. - - How does this test map on to the requirement described in the project instructions? - - What is the expected output for the given input? - -4. Run the test(s)! (RED) +3. Run the test(s)! (RED) + - *See the [Details About How to Run Tests](#details-about-how-to-run-tests) section below for more information on how to run test(s).* ```bash # Must be in activated virtual environment in the project-root directory $ pytest ``` -5. Focus on the top test failure. Read through the test failure, and understand why the failure is happening. Confirm your findings with a classmate. - - If it is a test you wrote, consider whether you are actually testing what you intend to test. Does this test need modification? +4. Focus on the top test failure. Read through the test failure, and understand why the failure is happening. Confirm your findings with a classmate. + - If it is a test you wrote, consider whether you are actually testing what you intend to test. Does the test need modification? -6. Make a plan to implement code to pass the test. -7. Write code in `party.py` to pass the test. +5. Make a plan to implement code to pass the test. -8. Re-run the tests. +6. Write code in `party.py` to pass the test. -9. Repeat steps 4-8 until that test passes! (GREEN) +7. Re-run the tests. -10. Repeats steps 3-9 until you have finished all tests in the file. +8. Repeat steps 4-7 until that test passes! (GREEN) -11. Begin using the test file of the next wave! +9. Repeats steps 3-8 until you have finished all tests in the file. + +10. Consider looking for opportunities to improve your code (REFACTOR) -12. Look for opportunities to improve your code (REFACTOR) +11. Begin using the test file of the next wave! -13. When you are finished working for the day, deactivate your environment with deactivate or closing the Terminal tab/window +12. When you are finished working for the day, deactivate your environment with deactivate or closing the Terminal tab/window ```bash $ deactivate diff --git a/viewing_party/party.py b/viewing_party/party.py index fa011e3e1..3d4c08e96 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -1,169 +1,23 @@ # ------------- WAVE 1 -------------------- def create_movie(title, genre, rating): - if title and genre and rating: - movie = { - "title": title, - "genre": genre, - "rating": rating - } - return movie - -def add_to_watched(user_data, movie): - user_data["watched"].append(movie) - return user_data - -def add_to_watchlist(user_data, movie): - user_data["watchlist"].append(movie) - return user_data - -def watch_movie(user_data, title): - for movie in user_data["watchlist"]: - if movie["title"] == title: - user_data["watchlist"].remove(movie) - add_to_watched(user_data, movie) - return user_data + pass # ----------------------------------------- # ------------- WAVE 2 -------------------- # ----------------------------------------- -def get_watched_avg_rating(user_data): - total = 0 - movies = user_data["watched"] - n = len(movies) - - if n == 0: - return 0 - - for movie in movies: - total += movie["rating"] - - return total/n - -def calculate_genre_freq(user_data): - # make genre frequency hash - genre_freqs = {} - movies = user_data["watched"] - #genre_freq = defaultdict(lambda: 0) - - for movie in movies: - genre = movie['genre'] - if genre not in genre_freqs.keys(): - genre_freqs[genre] = 1 - else: - genre_freqs[genre] += 1 - - # genre = movie['genre'] - # try: - # if genre_freqs[genre] != 0: - # genre_freqs[genre] += 1 - # except: - # genre_freqs[genre] = 1 - - return genre_freqs - -def get_most_watched_genre(user_data): - - - movies = user_data["watched"] - - if movies == []: - return None - - #call helper function to get frequencies - genre_freqs = calculate_genre_freq(user_data) - print(genre_freqs) - highest_freq = 0 - - # find most frequent - for genre in genre_freqs: - freq = genre_freqs[genre] - if freq > highest_freq: - most_frequent = genre - highest_freq = freq - - return most_frequent # ----------------------------------------- # ------------- WAVE 3 -------------------- # ----------------------------------------- -def get_friends_movies(user_data): - friend_movies = [] - - #get friends movie titles - for watched_dict in user_data['friends']: - for movie in watched_dict['watched']: - if movie not in friend_movies: - friend_movies.append(movie) - - return friend_movies - -def get_unique_watched(user_data): - user_movies = user_data['watched'] - user_unique_movie_titles = [] - friend_movies = get_friends_movies(user_data) - - #check for unique titles - for movie in user_movies: - if movie not in friend_movies: - user_unique_movie_titles.append(movie) - - return user_unique_movie_titles - - -def get_friends_unique_watched(user_data): - friend_movies = get_friends_movies(user_data) - unique_friend_movies = [] - - for movie in friend_movies: - if movie not in user_data['watched']: - unique_friend_movies.append(movie) - - return unique_friend_movies - # ----------------------------------------- # ------------- WAVE 4 -------------------- # ----------------------------------------- -def get_available_recs(user_data): - - unique_friend_movies = get_friends_unique_watched(user_data) - recs = [] - - for movie in unique_friend_movies: - if movie['host'] in user_data['subscriptions']: - recs.append(movie) - - return recs - # ----------------------------------------- # ------------- WAVE 5 -------------------- # ----------------------------------------- -def get_new_rec_by_genre(user_data): - most_freq_genre = get_most_watched_genre(user_data) - unique_friend_movies = get_friends_unique_watched(user_data) - - recs = [] - - for movie in unique_friend_movies: - if movie['genre'] == most_freq_genre: - recs.append(movie) - - return recs - -def get_rec_from_favorites(user_data): - - movies = get_unique_watched(user_data) - recs = [] - - for movie in movies: - if movie in user_data['favorites']: - recs.append(movie) - - return recs - - From 3f082298a6e5a23c9f9c9caab91fc9000177da8e Mon Sep 17 00:00:00 2001 From: Becca Elenzil Date: Tue, 8 Feb 2022 10:41:23 -0800 Subject: [PATCH 33/46] Remove .vscode from github --- .gitignore | 1 + .vscode/launch.json | 16 ---------------- .vscode/settings.json | 8 -------- 3 files changed, 1 insertion(+), 24 deletions(-) delete mode 100644 .vscode/launch.json delete mode 100644 .vscode/settings.json diff --git a/.gitignore b/.gitignore index 7f7fbe45e..11387f07d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .DS_Store +.vscode # GitHub's boilerplate Python gitignore # https://github.com/github/gitignore/blob/master/Python.gitignore diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 5dba21720..000000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - - { - "name": "Python: Current File", - "type": "python", - "request": "launch", - "program": "${file}", - "console": "integratedTerminal" - } - ] -} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 60400e381..000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "python.testing.pytestArgs": [ - "tests" - ], - "python.testing.unittestEnabled": false, - "python.testing.nosetestsEnabled": false, - "python.testing.pytestEnabled": true -} \ No newline at end of file From 9f64e6e49bb5c659ddbcd75c8fe859d3b2ca4de6 Mon Sep 17 00:00:00 2001 From: Becca Elenzil Date: Fri, 11 Feb 2022 06:22:22 -0800 Subject: [PATCH 34/46] Implemete clean_data functions and update README --- README.md | 6 +++ play_tester.py | 18 +++++---- tests/test_constants.py | 16 +++++++- tests/test_wave_02.py | 86 ++++++++++++++++++++++++++++++++++++----- tests/test_wave_03.py | 22 +++++------ tests/test_wave_04.py | 8 ++-- tests/test_wave_05.py | 20 +++++----- 7 files changed, 134 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index 7861128fa..3d02467ef 100644 --- a/README.md +++ b/README.md @@ -182,6 +182,12 @@ python3 play_tester.py There is some starter code provided in `play_tester.py`. This code prints the test data that is used for many of the tests. Looking closely at this data can help us think critically about the expected output for given input for each function. Then, calling each function with this data allows us to observe the **actual** output for given input. +## Test Data + +We will note that much of the test data for this project is provided by the file `test_constants.py`. As test data gets more and more complex, it is helpful to organize this data in its own file to enhance consistency and readability. Pytest, like many testing libraries, provide a special too for test data called **fixtures**. We will learn about fixtures later in the curriculum. + +For the time being, we need to make sure that the data provided to each test is clean and free of any changes that running another test may have introduced. Recall modifying mutable objects section of the [Variables Are References](https://learn-2.galvanize.com/cohorts/2330/blocks/1829/content_files/variables-and-memory/variables-are-references.md#modifying-mutable-objects) lesson. To ensure that the data for each test is storied in a unique place in memory, there are functions implemented in `test_constants.py` that provide clean test data (i.e. `clean_wave_3_data`) by using `copy.deepcopy`. + ## Project Directions This project is designed such that one could puzzle together how to implement this project without many directions. Being able to read tests to understand what is expected of our program is a skill that needs to be developed; programmers often take years to develop this skill competently. diff --git a/play_tester.py b/play_tester.py index f201ceadc..9e2aecf48 100644 --- a/play_tester.py +++ b/play_tester.py @@ -6,20 +6,24 @@ # import "pretty-print" library import pprint - -# use library to print data structures in a nicely formatted way pp = pprint.PrettyPrinter(indent=4) -print("\n-----Wave 02 user_data-----") -pp.pprint(USER_DATA_2) +# play testing section +print("\n-----Wave 01 test data-----") +pp.pprint(HORROR_1) +pp.pprint(FANTASY_1) +pp.pprint(FANTASY_2) + +# print("\n-----Wave 02 user_data-----") +# pp.pprint(clean_wave_2_data()) #print("\n-----Wave 03 user_data-----") -#pp.pprint(USER_DATA_3) +#pp.pprint(clean_wave_3_data()) # Wave 04 user data #print("\n-----Wave 04 user_data-----") -#pp.pprint(USER_DATA_4) +#pp.pprint(clean_wave_4_data()) # Wave 05 user data #print("\n-----Wave 05 user_data-----") -#pp.pprint(USER_DATA_5) +#pp.pprint(clean_wave_5_data()) diff --git a/tests/test_constants.py b/tests/test_constants.py index 1a4963c35..2dbcad866 100644 --- a/tests/test_constants.py +++ b/tests/test_constants.py @@ -162,4 +162,18 @@ FANTASY_2b, INTRIGUE_1b, INTRIGUE_2b - ] \ No newline at end of file + ] + +#----Functions that return clean data for each test---- + +def clean_wave_2_data(): + return copy.deepcopy(USER_DATA_2) + +def clean_wave_3_data(): + return copy.deepcopy(USER_DATA_3) + +def clean_wave_4_data(): + return copy.deepcopy(USER_DATA_4) + +def clean_wave_5_data(): + return copy.deepcopy(USER_DATA_5) \ No newline at end of file diff --git a/tests/test_wave_02.py b/tests/test_wave_02.py index 3fb185934..cce32bb91 100644 --- a/tests/test_wave_02.py +++ b/tests/test_wave_02.py @@ -1,25 +1,59 @@ import pytest from viewing_party.party import * -from tests.test_constants import USER_DATA_2 +import copy @pytest.mark.skip() def test_calculates_watched_average_rating(): # Arrange - janes_data = USER_DATA_2 + janes_data = { + 'watched': [ + { + 'title': 'The Lord of the Functions: The Fellowship of the Function', + 'genre': 'Fantasy', + 'rating': 4.8 + }, + { + 'title': 'The Lord of the Functions: The Two Parameters', + 'genre': 'Fantasy', + 'rating': 4.0 + }, + { + 'title': 'The Lord of the Functions: The Return of the Value', + 'genre': 'Fantasy', + 'rating': 4.0 + }, + { + 'title': 'The JavaScript and the React', + 'genre': 'Action', + 'rating': 2.2 + }, + { + 'title': 'Recursion', + 'genre': 'Intrigue', + 'rating': 2.0 + }, + { + 'title': 'Instructor Student TA Manager', + 'genre': 'Intrigue', + 'rating': 4.5 + } + ] + } + + janes_data_before = copy.deepcopy(janes_data) # Act average = get_watched_avg_rating(janes_data) # Assert assert average == pytest.approx(3.58333) - assert janes_data is USER_DATA_2 + assert janes_data == janes_data_before @pytest.mark.skip() def test_empty_watched_average_rating_is_zero(): # Arrange janes_data = { - "watched": [ - ] + "watched": [] } # Act @@ -31,14 +65,48 @@ def test_empty_watched_average_rating_is_zero(): @pytest.mark.skip() def test_most_watched_genre(): # Arrange - janes_data = USER_DATA_2 + janes_data = { + 'watched': [ + { + 'title': 'The Lord of the Functions: The Fellowship of the Function', + 'genre': 'Fantasy', + 'rating': 4.8 + }, + { + 'title': 'The Lord of the Functions: The Two Parameters', + 'genre': 'Fantasy', + 'rating': 4.0 + }, + { + 'title': 'The Lord of the Functions: The Return of the Value', + 'genre': 'Fantasy', + 'rating': 4.0 + }, + { + 'title': 'The JavaScript and the React', + 'genre': 'Action', + 'rating': 2.2 + }, + { + 'title': 'Recursion', + 'genre': 'Intrigue', + 'rating': 2.0 + }, + { + 'title': 'Instructor Student TA Manager', + 'genre': 'Intrigue', + 'rating': 4.5 + } + ] + } + janes_data_before = copy.deepcopy(janes_data) # Act popular_genre = get_most_watched_genre(janes_data) # Assert - assert popular_genre is "Fantasy" - assert janes_data is USER_DATA_2 + assert popular_genre == "Fantasy" + assert janes_data == janes_data_before @pytest.mark.skip() def test_genre_is_None_if_empty_watched(): @@ -51,4 +119,4 @@ def test_genre_is_None_if_empty_watched(): popular_genre = get_most_watched_genre(janes_data) # Assert - assert popular_genre is None + assert popular_genre == None diff --git a/tests/test_wave_03.py b/tests/test_wave_03.py index 6a663a426..18261a58d 100644 --- a/tests/test_wave_03.py +++ b/tests/test_wave_03.py @@ -5,55 +5,55 @@ @pytest.mark.skip() def test_my_unique_movies(): # Arrange - amandas_data = USER_DATA_3 + amandas_data = clean_wave_3_data() # Act amandas_unique_movies = get_unique_watched(amandas_data) # Arrange - assert len(amandas_unique_movies) is 2 + assert len(amandas_unique_movies) == 2 assert FANTASY_2 in amandas_unique_movies assert INTRIGUE_2 in amandas_unique_movies - assert amandas_data is USER_DATA_3 + assert amandas_data == clean_wave_3_data() @pytest.mark.skip() def test_my_not_unique_movies(): # Arrange - amandas_data = copy.deepcopy(USER_DATA_3) + amandas_data = clean_wave_3_data() amandas_data["watched"] = [] # Act amandas_unique_movies = get_unique_watched(amandas_data) # Arrange - assert len(amandas_unique_movies) is 0 + assert len(amandas_unique_movies) == 0 @pytest.mark.skip() def test_friends_unique_movies(): # Arrange - amandas_data = USER_DATA_3 + amandas_data = clean_wave_3_data() # Act friends_unique_movies = get_friends_unique_watched(amandas_data) # Arrange - assert len(friends_unique_movies) is 3 + assert len(friends_unique_movies) == 3 assert INTRIGUE_3 in friends_unique_movies assert HORROR_1 in friends_unique_movies assert FANTASY_4 in friends_unique_movies - assert amandas_data is USER_DATA_3 + assert amandas_data == clean_wave_3_data() @pytest.mark.skip() def test_friends_unique_movies_not_duplicated(): # Arrange - amandas_data = copy.deepcopy(USER_DATA_3) + amandas_data = clean_wave_3_data() amandas_data["friends"][0]["watched"].append(INTRIGUE_3) # Act friends_unique_movies = get_friends_unique_watched(amandas_data) # Arrange - assert len(friends_unique_movies) is 3 + assert len(friends_unique_movies) == 3 assert INTRIGUE_3 in friends_unique_movies assert HORROR_1 in friends_unique_movies assert FANTASY_4 in friends_unique_movies @@ -84,4 +84,4 @@ def test_friends_not_unique_movies(): friends_unique_movies = get_friends_unique_watched(amandas_data) # Arrange - assert len(friends_unique_movies) is 0 + assert len(friends_unique_movies) == 0 diff --git a/tests/test_wave_04.py b/tests/test_wave_04.py index 1b339fbea..72888410f 100644 --- a/tests/test_wave_04.py +++ b/tests/test_wave_04.py @@ -5,16 +5,16 @@ @pytest.mark.skip() def test_get_available_friend_rec(): # Arrange - amandas_data = USER_DATA_4 + amandas_data = clean_wave_4_data() # Act recommendations = get_available_recs(amandas_data) # Arrange - assert len(recommendations) is 2 + assert len(recommendations) == 2 assert HORROR_1b in recommendations assert FANTASY_4b in recommendations - assert amandas_data is USER_DATA_4 + assert amandas_data == clean_wave_4_data() @pytest.mark.skip() def test_no_available_friend_recs(): @@ -36,4 +36,4 @@ def test_no_available_friend_recs(): recommendations = get_available_recs(amandas_data) # Arrange - assert len(recommendations) is 0 + assert len(recommendations) == 0 diff --git a/tests/test_wave_05.py b/tests/test_wave_05.py index a68f3bffc..fd228eb11 100644 --- a/tests/test_wave_05.py +++ b/tests/test_wave_05.py @@ -5,7 +5,7 @@ @pytest.mark.skip() def test_new_genre_rec(): # Arrange - sonyas_data = USER_DATA_5 + sonyas_data = clean_wave_5_data() # Act recommendations = get_new_rec_by_genre(sonyas_data) @@ -13,9 +13,9 @@ def test_new_genre_rec(): # Assert for rec in recommendations: assert rec not in sonyas_data["watched"] - assert len(recommendations) is 1 + assert len(recommendations) == 1 assert FANTASY_4b in recommendations - assert sonyas_data is USER_DATA_5 + assert sonyas_data == clean_wave_5_data() @pytest.mark.skip() def test_new_genre_rec_from_empty_watched(): @@ -36,7 +36,7 @@ def test_new_genre_rec_from_empty_watched(): recommendations = get_new_rec_by_genre(sonyas_data) # Assert - assert len(recommendations) is 0 + assert len(recommendations) == 0 @pytest.mark.skip() def test_new_genre_rec_from_empty_friends(): @@ -57,21 +57,21 @@ def test_new_genre_rec_from_empty_friends(): recommendations = get_new_rec_by_genre(sonyas_data) # Assert - assert len(recommendations) is 0 + assert len(recommendations) == 0 @pytest.mark.skip() def test_unique_rec_from_favorites(): # Arrange - sonyas_data = USER_DATA_5 + sonyas_data = clean_wave_5_data() # Act recommendations = get_rec_from_favorites(sonyas_data) # Assert - assert len(recommendations) is 2 + assert len(recommendations) == 2 assert FANTASY_2b in recommendations assert INTRIGUE_2b in recommendations - assert sonyas_data is USER_DATA_5 + assert sonyas_data == clean_wave_5_data() @pytest.mark.skip() def test_unique_from_empty_favorites(): @@ -92,7 +92,7 @@ def test_unique_from_empty_favorites(): recommendations = get_new_rec_by_genre(sonyas_data) # Assert - assert len(recommendations) is 0 + assert len(recommendations) == 0 @pytest.mark.skip() def test_new_rec_from_empty_friends(): @@ -113,4 +113,4 @@ def test_new_rec_from_empty_friends(): recommendations = get_new_rec_by_genre(sonyas_data) # Assert - assert len(recommendations) is 0 + assert len(recommendations) == 0 From a7b16e17fdb4668b12f4a1c94ba12185ed61ff41 Mon Sep 17 00:00:00 2001 From: Becca Elenzil Date: Fri, 11 Feb 2022 06:23:26 -0800 Subject: [PATCH 35/46] Remove solution --- viewing_party/party.py | 169 ----------------------------------------- 1 file changed, 169 deletions(-) diff --git a/viewing_party/party.py b/viewing_party/party.py index fa011e3e1..e69de29bb 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -1,169 +0,0 @@ -# ------------- WAVE 1 -------------------- - -def create_movie(title, genre, rating): - if title and genre and rating: - movie = { - "title": title, - "genre": genre, - "rating": rating - } - return movie - -def add_to_watched(user_data, movie): - user_data["watched"].append(movie) - return user_data - -def add_to_watchlist(user_data, movie): - user_data["watchlist"].append(movie) - return user_data - -def watch_movie(user_data, title): - for movie in user_data["watchlist"]: - if movie["title"] == title: - user_data["watchlist"].remove(movie) - add_to_watched(user_data, movie) - return user_data - -# ----------------------------------------- -# ------------- WAVE 2 -------------------- -# ----------------------------------------- - -def get_watched_avg_rating(user_data): - total = 0 - movies = user_data["watched"] - n = len(movies) - - if n == 0: - return 0 - - for movie in movies: - total += movie["rating"] - - return total/n - -def calculate_genre_freq(user_data): - # make genre frequency hash - genre_freqs = {} - movies = user_data["watched"] - #genre_freq = defaultdict(lambda: 0) - - for movie in movies: - genre = movie['genre'] - if genre not in genre_freqs.keys(): - genre_freqs[genre] = 1 - else: - genre_freqs[genre] += 1 - - # genre = movie['genre'] - # try: - # if genre_freqs[genre] != 0: - # genre_freqs[genre] += 1 - # except: - # genre_freqs[genre] = 1 - - return genre_freqs - -def get_most_watched_genre(user_data): - - - movies = user_data["watched"] - - if movies == []: - return None - - #call helper function to get frequencies - genre_freqs = calculate_genre_freq(user_data) - print(genre_freqs) - highest_freq = 0 - - # find most frequent - for genre in genre_freqs: - freq = genre_freqs[genre] - if freq > highest_freq: - most_frequent = genre - highest_freq = freq - - return most_frequent - -# ----------------------------------------- -# ------------- WAVE 3 -------------------- -# ----------------------------------------- - -def get_friends_movies(user_data): - friend_movies = [] - - #get friends movie titles - for watched_dict in user_data['friends']: - for movie in watched_dict['watched']: - if movie not in friend_movies: - friend_movies.append(movie) - - return friend_movies - -def get_unique_watched(user_data): - user_movies = user_data['watched'] - user_unique_movie_titles = [] - friend_movies = get_friends_movies(user_data) - - #check for unique titles - for movie in user_movies: - if movie not in friend_movies: - user_unique_movie_titles.append(movie) - - return user_unique_movie_titles - - -def get_friends_unique_watched(user_data): - friend_movies = get_friends_movies(user_data) - unique_friend_movies = [] - - for movie in friend_movies: - if movie not in user_data['watched']: - unique_friend_movies.append(movie) - - return unique_friend_movies - - -# ----------------------------------------- -# ------------- WAVE 4 -------------------- -# ----------------------------------------- - -def get_available_recs(user_data): - - unique_friend_movies = get_friends_unique_watched(user_data) - recs = [] - - for movie in unique_friend_movies: - if movie['host'] in user_data['subscriptions']: - recs.append(movie) - - return recs - -# ----------------------------------------- -# ------------- WAVE 5 -------------------- -# ----------------------------------------- - -def get_new_rec_by_genre(user_data): - most_freq_genre = get_most_watched_genre(user_data) - unique_friend_movies = get_friends_unique_watched(user_data) - - recs = [] - - for movie in unique_friend_movies: - if movie['genre'] == most_freq_genre: - recs.append(movie) - - return recs - -def get_rec_from_favorites(user_data): - - movies = get_unique_watched(user_data) - recs = [] - - for movie in movies: - if movie in user_data['favorites']: - recs.append(movie) - - return recs - - From c05023ec66c7f398053cfe39c2cb3ef0f52e9926 Mon Sep 17 00:00:00 2001 From: Becca Elenzil Date: Fri, 11 Feb 2022 06:27:57 -0800 Subject: [PATCH 36/46] Add note to not modify the data --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 3d02467ef..c73c33981 100644 --- a/README.md +++ b/README.md @@ -259,6 +259,8 @@ In `party.py`, there should be a function named `watch_movie`. This function sho - If the title is not a movie in the user's watchlist: - return the `user_data` +Note: For Waves 2, 3, 4, and 5, your implementation of each of the functions should not modify `user_data`. + ### Wave 2 1. The first two tests are about a `get_watched_avg_rating()` function. From 6d67319c7c3385bc7f3e32a4f0efd067c95c3f59 Mon Sep 17 00:00:00 2001 From: Becca Elenzil Date: Fri, 11 Feb 2022 11:13:36 -0800 Subject: [PATCH 37/46] Add None requirement in readme and approx for rating --- README.md | 1 + tests/test_wave_01.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b2303d279..54cb02335 100644 --- a/README.md +++ b/README.md @@ -271,6 +271,7 @@ In `party.py`, there should be a function named `get_most_watched_genre`. This f - The values of `"genre"` is a string. - Determine which genre is most frequently occurring in the watched list - return the genre that is the most frequently watched +- If the value of "watched" is an empty list, `get_most_watched_genre` should return `None`. ### Wave 3 diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index 6d573e685..e1e246401 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -17,7 +17,7 @@ def test_create_successful_movie(): # Assert assert new_movie["title"] is MOVIE_TITLE_1 assert new_movie["genre"] is GENRE_1 - assert new_movie["rating"] is RATING_1 + assert new_movie["rating"] == pytest.approx(RATING_1) @pytest.mark.skip() def test_create_no_title_movie(): From 75de1ccbb90df8a5074d32bec0595f37d7a36557 Mon Sep 17 00:00:00 2001 From: Becca Date: Fri, 11 Feb 2022 11:20:59 -0800 Subject: [PATCH 38/46] Apply suggestions from code review Co-authored-by: Kaida Masaki --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 54cb02335..57ccc271a 100644 --- a/README.md +++ b/README.md @@ -129,6 +129,8 @@ $ deactivate Finally, at submission time, **no matter where you are**, submit the project via Learn. +This will let us give feedback on what you've finished so that you can be better prepared for the next project. + ## Details About How to Run Tests All the commands described below should be run from the project-root directory `viewing-party`. Note that the project-root directory is the repository `viewing-party`. It is distinct from the directory `viewing_party` that contains the source code in `party.py`. @@ -196,7 +198,7 @@ In `party.py`, there should be a function named `create_movie`. This function sh - The values of these key-value pairs should be appropriate values - If `title` is falsy, `genre` is falsy, or `rating` is falsy, this function should return `None` -2. The next two tests are about an `add_to_watched()` function. +2. The next two tests are about the `add_to_watched()` function. In `party.py`, there should be a function named `add_to_watched`. This function should... From f99e69d0ffa3f6b5a91a3e4fa830be1083ab7775 Mon Sep 17 00:00:00 2001 From: Becca Elenzil Date: Fri, 11 Feb 2022 11:24:31 -0800 Subject: [PATCH 39/46] Add comment not to modify test_constants --- tests/test_constants.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_constants.py b/tests/test_constants.py index 2dbcad866..55d4dceb5 100644 --- a/tests/test_constants.py +++ b/tests/test_constants.py @@ -1,5 +1,9 @@ import copy +# ******************************** +# *** Do Not Modify This File **** +# ******************************** + # Data for Unit Tests #----------WAVE01------------- From 56321f0c8741d2ea918f10019fda9c11e962373b Mon Sep 17 00:00:00 2001 From: Becca Elenzil Date: Fri, 11 Feb 2022 11:28:44 -0800 Subject: [PATCH 40/46] Use clean_wave_2_data instead of hardcoded --- tests/test_wave_02.py | 80 ++++--------------------------------------- 1 file changed, 6 insertions(+), 74 deletions(-) diff --git a/tests/test_wave_02.py b/tests/test_wave_02.py index cce32bb91..c557cf13e 100644 --- a/tests/test_wave_02.py +++ b/tests/test_wave_02.py @@ -1,53 +1,19 @@ import pytest from viewing_party.party import * -import copy +from tests.test_constants import * + @pytest.mark.skip() def test_calculates_watched_average_rating(): # Arrange - janes_data = { - 'watched': [ - { - 'title': 'The Lord of the Functions: The Fellowship of the Function', - 'genre': 'Fantasy', - 'rating': 4.8 - }, - { - 'title': 'The Lord of the Functions: The Two Parameters', - 'genre': 'Fantasy', - 'rating': 4.0 - }, - { - 'title': 'The Lord of the Functions: The Return of the Value', - 'genre': 'Fantasy', - 'rating': 4.0 - }, - { - 'title': 'The JavaScript and the React', - 'genre': 'Action', - 'rating': 2.2 - }, - { - 'title': 'Recursion', - 'genre': 'Intrigue', - 'rating': 2.0 - }, - { - 'title': 'Instructor Student TA Manager', - 'genre': 'Intrigue', - 'rating': 4.5 - } - ] - } - - janes_data_before = copy.deepcopy(janes_data) + janes_data = clean_wave_2_data() # Act average = get_watched_avg_rating(janes_data) # Assert assert average == pytest.approx(3.58333) - assert janes_data == janes_data_before + assert janes_data == clean_wave_2_data() @pytest.mark.skip() def test_empty_watched_average_rating_is_zero(): @@ -65,48 +31,14 @@ def test_empty_watched_average_rating_is_zero(): @pytest.mark.skip() def test_most_watched_genre(): # Arrange - janes_data = { - 'watched': [ - { - 'title': 'The Lord of the Functions: The Fellowship of the Function', - 'genre': 'Fantasy', - 'rating': 4.8 - }, - { - 'title': 'The Lord of the Functions: The Two Parameters', - 'genre': 'Fantasy', - 'rating': 4.0 - }, - { - 'title': 'The Lord of the Functions: The Return of the Value', - 'genre': 'Fantasy', - 'rating': 4.0 - }, - { - 'title': 'The JavaScript and the React', - 'genre': 'Action', - 'rating': 2.2 - }, - { - 'title': 'Recursion', - 'genre': 'Intrigue', - 'rating': 2.0 - }, - { - 'title': 'Instructor Student TA Manager', - 'genre': 'Intrigue', - 'rating': 4.5 - } - ] - } - janes_data_before = copy.deepcopy(janes_data) + janes_data = clean_wave_2_data() # Act popular_genre = get_most_watched_genre(janes_data) # Assert assert popular_genre == "Fantasy" - assert janes_data == janes_data_before + assert janes_data == clean_wave_2_data() @pytest.mark.skip() def test_genre_is_None_if_empty_watched(): From fefb225664b662e570aac190c6662cc6b000f0c1 Mon Sep 17 00:00:00 2001 From: Becca Elenzil Date: Fri, 11 Feb 2022 11:39:26 -0800 Subject: [PATCH 41/46] Remove lesson link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5ff1049fe..189ad584b 100644 --- a/README.md +++ b/README.md @@ -181,7 +181,7 @@ There is some starter code provided in `play_tester.py`. This code prints the te We will note that much of the test data for this project is provided by the file `test_constants.py`. As test data gets more and more complex, it is helpful to organize this data in its own file to enhance consistency and readability. Pytest, like many testing libraries, provide a special too for test data called **fixtures**. We will learn about fixtures later in the curriculum. -For the time being, we need to make sure that the data provided to each test is clean and free of any changes that running another test may have introduced. Recall modifying mutable objects section of the [Variables Are References](https://learn-2.galvanize.com/cohorts/2330/blocks/1829/content_files/variables-and-memory/variables-are-references.md#modifying-mutable-objects) lesson. To ensure that the data for each test is storied in a unique place in memory, there are functions implemented in `test_constants.py` that provide clean test data (i.e. `clean_wave_3_data`) by using `copy.deepcopy`. +For the time being, we need to make sure that the data provided to each test is clean and free of any changes that running another test may have introduced. Recall the *Modifying Mutable Objects* section of the *Variables Are References lesson.* To ensure that the data for each test is storied in a unique place in memory, there are functions implemented in `test_constants.py` that provide clean test data (i.e. `clean_wave_3_data`) by using `copy.deepcopy`. ## Project Directions From 739708c6be79db6fe2fabbaac0e6117a6c430199 Mon Sep 17 00:00:00 2001 From: Becca Elenzil Date: Fri, 11 Feb 2022 12:07:08 -0800 Subject: [PATCH 42/46] Remove overwriting student tests in dockerfile --- Dockerfile | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 02a7ff75c..ed1b1ff9a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,9 +27,5 @@ RUN pip install -r /app/requirements.txt ARG SUBMISSION_SUBFOLDER ADD $SUBMISSION_SUBFOLDER /app -# Overwrite files in student fork with upstream files -ADD test.sh /app -ADD tests /app/tests - # User defined requirements # RUN make init From 4d1476e162002a9496ca9180797591f6befbb3b0 Mon Sep 17 00:00:00 2001 From: Becca Elenzil Date: Fri, 11 Feb 2022 12:07:39 -0800 Subject: [PATCH 43/46] Add test.sh back to dockerfile --- Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Dockerfile b/Dockerfile index ed1b1ff9a..dd825a717 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,5 +27,8 @@ RUN pip install -r /app/requirements.txt ARG SUBMISSION_SUBFOLDER ADD $SUBMISSION_SUBFOLDER /app +# Overwrite files in student fork with upstream files +ADD test.sh /app + # User defined requirements # RUN make init From 8547d411848d80d69c2d59a5b00897a7e64107d0 Mon Sep 17 00:00:00 2001 From: Becca Elenzil Date: Fri, 11 Feb 2022 12:10:34 -0800 Subject: [PATCH 44/46] Scaffold 2 tests in wave 01 tests --- tests/test_wave_01.py | 12 ++++++++---- tests/test_wave_02.py | 1 - 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index e1e246401..b14fd1992 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -118,9 +118,10 @@ def test_moves_movie_from_watchlist_to_empty_watched(): # Assert assert len(updated_data["watchlist"]) is 0 assert len(updated_data["watched"]) is 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 + + # ******************************************************************************************* + # ****** Add assertions here to test that the correct movie was added to "watched" ********** + # ******************************************************************************************* @pytest.mark.skip() def test_moves_movie_from_watchlist_to_watched(): @@ -140,7 +141,10 @@ def test_moves_movie_from_watchlist_to_watched(): # Assert assert len(updated_data["watchlist"]) is 1 assert len(updated_data["watched"]) is 2 - assert movie_to_watch in updated_data["watched"] + + # ******************************************************************************************* + # ****** 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_02.py b/tests/test_wave_02.py index c557cf13e..3a588299e 100644 --- a/tests/test_wave_02.py +++ b/tests/test_wave_02.py @@ -2,7 +2,6 @@ from viewing_party.party import * from tests.test_constants import * - @pytest.mark.skip() def test_calculates_watched_average_rating(): # Arrange From bb5399852443caefee44935d4847dc2da3ab8b24 Mon Sep 17 00:00:00 2001 From: Becca Elenzil Date: Fri, 11 Feb 2022 12:14:27 -0800 Subject: [PATCH 45/46] Scaffold test for wave 3 and 5 --- tests/test_wave_03.py | 7 ++++--- tests/test_wave_05.py | 8 +++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/tests/test_wave_03.py b/tests/test_wave_03.py index 18261a58d..7c42a63c4 100644 --- a/tests/test_wave_03.py +++ b/tests/test_wave_03.py @@ -54,9 +54,10 @@ def test_friends_unique_movies_not_duplicated(): # Arrange assert len(friends_unique_movies) == 3 - assert INTRIGUE_3 in friends_unique_movies - assert HORROR_1 in friends_unique_movies - assert FANTASY_4 in friends_unique_movies + + # ************************************************************************************************* + # ****** Add assertions here to test that the correct movies are in friends_unique_movies ********** + # ************************************************************************************************** @pytest.mark.skip() def test_friends_not_unique_movies(): diff --git a/tests/test_wave_05.py b/tests/test_wave_05.py index fd228eb11..8ce5b57db 100644 --- a/tests/test_wave_05.py +++ b/tests/test_wave_05.py @@ -53,11 +53,9 @@ def test_new_genre_rec_from_empty_friends(): ] } - # Act - recommendations = get_new_rec_by_genre(sonyas_data) - - # Assert - assert len(recommendations) == 0 + # ********************************************************************* + # ****** Complete the Act and Assert Portions of theis tests ********** + # ********************************************************************* @pytest.mark.skip() def test_unique_rec_from_favorites(): From f142aeb6602c0d89c6b30d82c3452a406366a2b4 Mon Sep 17 00:00:00 2001 From: Becca Date: Mon, 14 Feb 2022 12:16:14 -0800 Subject: [PATCH 46/46] Add note about venv --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a680a6da2..16920c2de 100644 --- a/README.md +++ b/README.md @@ -174,6 +174,7 @@ While we will mainly use a Test Driven Development (TDD) workflow for this proje To run this file, use: ```bash +# Must be in activated virtual environment in the project root-directory python3 play_tester.py ```