Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/adipai/PopcornPicks into ui
Browse files Browse the repository at this point in the history
  • Loading branch information
ananya173147 committed Oct 17, 2023
2 parents 5fce475 + 1fa2a45 commit 7fb1e55
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 81 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Unittest

on: [push]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint
pip install pandas
pip install -U Flask
pip install -U flask-cors
- name: Running test cases for predicting
run: python test/tests.py
- name: Running test cases for searching
run: python test/test_search.py

31 changes: 0 additions & 31 deletions src/recommenderapp/constants.py

This file was deleted.

34 changes: 31 additions & 3 deletions src/recommenderapp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from email.mime.multipart import MIMEMultipart

import pandas as pd
import constants as c

def create_colored_tags(genres):
"""
Expand Down Expand Up @@ -83,19 +82,48 @@ 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 = """
<html>
<head></head>
<body>
<h1 style="color: #333333;">Movie Recommendations from PopcornPicks</h1>
<p style="color: #555555;">Dear Movie Enthusiast,</p>
<p style="color: #555555;">We hope you're having a fantastic day!</p>
<div style="padding: 10px; border: 1px solid #cccccc; border-radius: 5px; background-color: #f9f9f9;">
<h2>Your Movie Recommendations:</h2>
<h3>Movies Liked:</h3>
<ul style="color: #555555;">
{}
</ul>
<h3>Movies Disliked:</h3>
<ul style="color: #555555;">
{}
</ul>
<h3>Movies Yet to Watch:</h3>
<ul style="color: #555555;">
{}
</ul>
</div>
<p style="color: #555555;">Enjoy your movie time with PopcornPicks!</p>
<p style="color: #555555;">Best regards,<br>PopcornPicks Team 🍿</p>
</body>
</html>
"""

# Email configuration
smtp_server = 'smtp.gmail.com'
# Port for TLS
smtp_port = 587
sender_email = '[email protected]'

# 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
Expand All @@ -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'<li>{movie} \
{create_colored_tags(movie_to_genres.get(movie, ["Unknown Genre"]))}</li><br>' \
for movie in categorized_data['Liked']),
Expand Down
1 change: 0 additions & 1 deletion test/README.md

This file was deleted.

Empty file added test/__init__.py
Empty file.
19 changes: 10 additions & 9 deletions test/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import sys
import unittest
import warnings
sys.path.append("../")
from pathlib import Path
sys.path.append(str(Path(__file__).resolve().parents[1]))
#pylint: disable=wrong-import-position
from src.recommenderapp.search import Search
#pylint: enable=wrong-import-position
Expand All @@ -28,14 +29,15 @@ def test_search_toy(self):
"Toy Story (1995)",
"Toys (1992)",
"Toy Story 2 (1999)",
"Toy, The (1982)",
"Toy Soldiers (1991)",
"Toy Story 3 (2010)",
"Babes in Toyland (1961)",
"Babes in Toyland (1934)",
"Toys in the Attic (1963)",
"Toy Story of Terror! (2013)",
"Toy Story That Time Forgot (2014)",
"Toys in the Attic (2009)",
"Toy Soldiers (1984)"
]
self.assertTrue(filtered_dict == expected_resp)

def test_search_love(self):
"""
Test case 2
Expand All @@ -47,16 +49,15 @@ def test_search_love(self):
"Love & Human Remains (1993)",
"Love Affair (1994)",
"Love and a .45 (1994)",
"Lover's Knot (1996)",
"Love in the Afternoon (1957)",
"Love Bug, The (1969)",
"Love Is All There Is (1996)",
"Love Jones (1997)",
"Love and Other Catastrophes (1996)",
"Love! Valour! Compassion! (1997)",
"Love Serenade (1996)",
"Love and Death on Long Island (1997)",
"Love Is the Devil (1998)",
]
self.assertTrue(filtered_dict == expected_resp)

def test_search_gibberish(self):
"""
Test case 3
Expand Down
63 changes: 63 additions & 0 deletions test/test_util.py
Original file line number Diff line number Diff line change
@@ -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 = '<span style="background-color: #FF1493; color: #FFFFFF; padding: 5px; border-radius: 5px;">Musical</span>'
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()
Loading

0 comments on commit 7fb1e55

Please sign in to comment.