diff --git a/src/recommenderapp/constants.py b/src/recommenderapp/constants.py deleted file mode 100644 index 31a92b464..000000000 --- a/src/recommenderapp/constants.py +++ /dev/null @@ -1,31 +0,0 @@ -""" -This module contains all the constants -""" - -EMAIL_HTML_CONTENT = """ - - - -

Movie Recommendations from PopcornPicks

-

Dear Movie Enthusiast,

-

We hope you're having a fantastic day!

-
-

Your Movie Recommendations:

-

Movies Liked:

- -

Movies Disliked:

- -

Movies Yet to Watch:

- -
-

Enjoy your movie time with PopcornPicks!

-

Best regards,
PopcornPicks Team 🍿

- - - """ diff --git a/src/recommenderapp/utils.py b/src/recommenderapp/utils.py index 088ba6450..088777c8a 100644 --- a/src/recommenderapp/utils.py +++ b/src/recommenderapp/utils.py @@ -7,7 +7,6 @@ from email.mime.multipart import MIMEMultipart import pandas as pd -import constants as c def create_colored_tags(genres): """ @@ -83,11 +82,40 @@ def create_movie_genres(movie_genre_df): genres = row[1]['genres'].split('|') movie_to_genres[movie] = genres return movie_to_genres + def send_email_to_user(recipient_email, categorized_data): """ Utility function to send movie recommendations to user over email """ + email_html_content = """ + + + +

Movie Recommendations from PopcornPicks

+

Dear Movie Enthusiast,

+

We hope you're having a fantastic day!

+
+

Your Movie Recommendations:

+

Movies Liked:

+ +

Movies Disliked:

+ +

Movies Yet to Watch:

+ +
+

Enjoy your movie time with PopcornPicks!

+

Best regards,
PopcornPicks Team 🍿

+ + + """ + # Email configuration smtp_server = 'smtp.gmail.com' # Port for TLS @@ -95,7 +123,7 @@ def send_email_to_user(recipient_email, categorized_data): sender_email = 'popcornpicks504@gmail.com' # Use an app password since 2-factor authentication is enabled - sender_password = '' + sender_password = 'uxnd shis sazo mstj' subject = 'Your movie recommendation from PopcornPicks' # Create the email message @@ -108,7 +136,7 @@ def send_email_to_user(recipient_email, categorized_data): # Creating movie-genres map movie_to_genres = create_movie_genres(movie_genre_df) # Create the email message with HTML content - html_content = c.EMAIL_HTML_CONTENT.format( + html_content = email_html_content.format( '\n'.join(f'
  • {movie} \ {create_colored_tags(movie_to_genres.get(movie, ["Unknown Genre"]))}

  • ' \ for movie in categorized_data['Liked']), diff --git a/test/test_util.py b/test/test_util.py new file mode 100644 index 000000000..32e8ceac4 --- /dev/null +++ b/test/test_util.py @@ -0,0 +1,63 @@ +""" +Test suit for search feature +""" + +import sys +import unittest +import warnings +import pandas as pd +sys.path.append("../") +#pylint: disable=wrong-import-position +from src.recommenderapp.utils import create_colored_tags, beautify_feedback_data, create_movie_genres, send_email_to_user +#pylint: enable=wrong-import-position + +warnings.filterwarnings("ignore") + + +class Tests(unittest.TestCase): + """ + Test cases for utility functions + """ + + def test_beautify_feedback_data(self): + """ + Test case 1 + """ + data = {'Movie 1': 'Yet to watch', + 'Movie 2': 'Like', 'Movie 3': 'Dislike'} + result = beautify_feedback_data(data) + expected_result = {"Liked": ['Movie 2'], "Disliked": [ + 'Movie 3'], "Yet to Watch": ['Movie 1']} + + self.assertTrue(result == expected_result) + + def test_create_colored_tags(self): + """ + Test case 2 + """ + expected_result = 'Musical' + result = create_colored_tags(['Musical']) + self.assertTrue(result == expected_result) + + def test_create_movie_genres(self): + """ + Test case 3 + """ + expected_result = {'Toy Story (1995)': ['Animation', 'Comedy', 'Family'], 'Jumanji (1995)': [ + 'Adventure', 'Fantasy', 'Family']} + movie_genre_df = pd.read_csv('../data/movies.csv').head(n=2) + result = create_movie_genres(movie_genre_df) + self.assertTrue(result == expected_result) + + def test_send_email_to_user(self): + """ + Test case 4 + """ + data = {"Liked": ['Toy Story (1995)'], "Disliked": [ + 'Cutthroat Island (1995)'], "Yet to Watch": ['Assassins (1995)']} + with self.assertRaises(Exception): + send_email_to_user("wrong_email", beautify_feedback_data(data)) + + +if __name__ == "__main__": + unittest.main()