def test_get_movie_details(self): ret = tmdb.get_details_from_tmdb(513) with patch.object(tmdb, "get_details_from_tmdb", return_value=ret) as m_method: Movie.get_details(513) # this should get it from TMDB api m_method.assert_called_with(513) m_method.reset_mock() Movie.get_details(513) # this should get it from the SQL database self.assertFalse(m_method.called)
def test_get_overall_most_popular(self): profile = Profile.create_new_user('testing5', '*****@*****.**', 'testing5', date.today()) movie = Movie.get_details(11) Rating.set_rating_for_user(movie,4,profile) movie = Movie.get_details(12) Rating.set_rating_for_user(movie,5,profile) movie = Movie.get_details(13) Rating.set_rating_for_user(movie,2,profile) results = Movie.get_popular(min_rating=3) self.assertTrue(results['total_items'] == 2)
def test_get_overall_most_popular(self): profile = Profile.create_new_user('testing5', '*****@*****.**', 'testing5', date.today()) movie = Movie.get_details(11) Rating.set_rating_for_user(movie, 4, profile) movie = Movie.get_details(12) Rating.set_rating_for_user(movie, 5, profile) movie = Movie.get_details(13) Rating.set_rating_for_user(movie, 2, profile) results = Movie.get_popular(min_rating=3) self.assertTrue(results['total_items'] == 2)
def get_browse_filters(): logger.info('Retrieving Browse Filters') # A list of attributes by which the user can filter the displayed movies browse_filters = [] # Create the Genre filter genre_filter = BrowseFilter('genre') # Add default option. Not filtered by Genre default_option = FilterElement('', 'All') genre_filter.option_list.append(default_option) # Retrieve list of genres from API logger.info('Retrieving Genre List') retrieved_genres = Movie.get_genres() # Add retrieved genres to list as Genre objects for id_, name in retrieved_genres: genre = FilterElement(id_, name) genre_filter.option_list.append(genre) if not retrieved_genres: logger.warning('No Genres Retrieved') browse_filters.append(genre_filter) logger.info('Finished Retrieving Browse Filters') return browse_filters
def test_delete_review_user_is_writer_of_review(self): profile = Profile.create_new_user('test11', '*****@*****.**', 'test11', date.today()) movie = Movie.get_details(5) new_review = Review() new_review.review_title = 'Test review' new_review.review_body = 'body' new_review.date_created = date.today() new_review.user = profile new_review.movie = movie new_review.save() new_review.delete(profile.user)
def test_delete_review_user_is_not_admin(self): profile_author = Profile.create_new_user('test11', '*****@*****.**', 'test11', date.today()) profile_nonauthor = Profile.create_new_user('test22', '*****@*****.**', 'test22', date.today()) movie = Movie.get_details(5) new_review = Review() new_review.review_title = 'Test review' new_review.review_body = 'body' new_review.date_created = date.today() new_review.user = profile_author new_review.movie = movie new_review.save() with self.assertRaises(Exception): # Verify that error is raised when trying to do this since user is not admin new_review.delete(profile_nonauthor.user)
def test_delete_review_user_is_not_admin(self): profile_author = Profile.create_new_user('test11', '*****@*****.**', 'test11', date.today()) profile_nonauthor = Profile.create_new_user('test22', '*****@*****.**', 'test22', date.today()) movie = Movie.get_details(5) new_review = Review() new_review.review_title = 'Test review' new_review.review_body = 'body' new_review.date_created = date.today() new_review.user = profile_author new_review.movie = movie new_review.save() with self.assertRaises( Exception ): # Verify that error is raised when trying to do this since user is not admin new_review.delete(profile_nonauthor.user)
def test_get_popular_movies_min_5_stars(self): profile = Profile.create_new_user('testing1', '*****@*****.**', 'testing1', date.today()) movie = Movie.get_details(11) Rating.set_rating_for_user(movie, 1, profile) movie = Movie.get_details(12) Rating.set_rating_for_user(movie, 2, profile) movie = Movie.get_details(13) Rating.set_rating_for_user(movie, 3, profile) movie = Movie.get_details(513) Rating.set_rating_for_user(movie, 4, profile) movie = Movie.get_details(5) Rating.set_rating_for_user(movie, 5, profile) # There should only be one result when getting movies with rating 5 or higher self.assertTrue(Movie.get_popular(min_rating=5)['total_items'] == 1)
def test_get_popular_movies_min_1_star(self): profile = Profile.create_new_user('testing1', '*****@*****.**', 'testing1', date.today()) movie = Movie.get_details(11) Rating.set_rating_for_user(movie, 1, profile) movie = Movie.get_details(12) Rating.set_rating_for_user(movie, 2, profile) movie = Movie.get_details(13) Rating.set_rating_for_user(movie, 3, profile) movie = Movie.get_details(513) Rating.set_rating_for_user(movie, 4, profile) movie = Movie.get_details(5) Rating.set_rating_for_user(movie, 5, profile) # All 5 movies should show up as results when the minimum rating required for a movie to be 'popular' is a 1 self.assertTrue(Movie.get_popular(min_rating=1)['total_items'] == 5)
def test_get_similar_movies(self): movies = Movie.get_similar(11) self.assertTrue(movies)
def test_get_movies_for_genre_discover(self): movies = Movie.get_movies_for_genre(0, 1) self.assertTrue(movies['total_items'] > 1000)
def test_get_movies_for_genre(self): genres = Movie.get_genres() movies = Movie.get_movies_for_genre(genres[0][0], 1) self.assertTrue(movies)
def test_get_genres(self): genres = Movie.get_genres() self.assertTrue(genres)
def test_search_for_movies_1_word_search_phrase(self): total_items = Movie.search(search_term='juno')['total_items'] self.assertTrue(total_items > 0)
def test_search_for_movies_8_word_search_phrase(self): total_items = Movie.search( search_term='The Legend of Hell' 's Gate An American Conspiracy')['total_items'] self.assertTrue(total_items > 0)
def test_search_for_movies_8_word_search_phrase(self): total_items = Movie.search(search_term='The Legend of Hell''s Gate An American Conspiracy')['total_items'] self.assertTrue(total_items > 0)
def test_search_for_movies_12_char_search_term(self): total_items = Movie.search(search_term='guadalquivir')['total_items'] self.assertTrue(total_items > 0)
def test_delete_review_no_user_passed_in(self): profile = Profile.create_new_user('test11', '*****@*****.**', 'test11', date.today()) movie = Movie.get_details(5) new_review = Review() new_review.review_title = 'Test review' new_review.review_body = 'body' new_review.date_created = date.today() new_review.user = profile new_review.movie = movie new_review.save() with self.assertRaises(Exception): # Verify that error is raised when trying to do this since user is not admin new_review.delete() # class BrowserTests(TestCase): # """ # Tests urls and views code. # """ # @classmethod # def setUpClass(cls): # cls.browser = webdriver.Chrome() # cls.uname = uuid1().hex[:30] # @classmethod # def tearDownClass(cls): # cls.browser.close() # # Check the spotlight redirects to the appropriate movie detail page # def spotlight(self): # self.browser.get("http://127.0.0.1:8000/") # self.browser.find_element_by_id("movie-spotlight").find_element_by_tag_name("img").click() # self.assertEqual(self.browser.current_url, "http://127.0.0.1:8000/movie/detail/5/") # # Metamorphic Property: if the user is not logged in, he should not be able to rate movies # def rating_absence(self): # self.browser.get("http://127.0.0.1:8000/movie/detail/5/") # self.assertFalse(self.browser.find_elements_by_id("rating-stars")) # # Tests properties that must be done independent of login # def test_misc(self): # self.spotlight() # self.rating_absence() # # Metamorphic Property: if the user is not logged in, he should not be able to rate movies # def signup(self): # self.browser.get("http://127.0.0.1:8000") # self.browser.find_element_by_class_name("signup-link").click() # form = self.browser.find_element_by_id("signupForm") # form.find_element_by_id("id_email_address").send_keys("foo@foo") # form.find_element_by_id("id_username").send_keys(self.uname) # form.find_element_by_id("id_password1").send_keys("foofoo") # form.find_element_by_id("id_password2").send_keys("foofoo") # form.submit() # sleep(1) # self.browser.find_element_by_id("header-buttons").find_elements_by_class_name("header-button")[1].click() # expected_url = u"http://127.0.0.1:8000/profile/%s/" % self.uname # self.assertEqual(self.browser.current_url, expected_url) # # Metamorphic Property: if the user is not logged in, the middle button in the header should # # be the Log In button # def logout(self): # self.browser.get("http://127.0.0.1:8000/") # sleep(1) # self.browser.find_element_by_id("header-buttons").find_elements_by_class_name("header-button")[2].click() # sleep(1) # mid_button = self.browser.find_element_by_id("header-buttons").find_elements_by_class_name("header-button")[1] # self.assertTrue(mid_button.text, "Log In") # # Metamorphic Property: if the user is not logged in, the middle button in the header should # # be the Profile button # def login(self): # self.browser.get("http://127.0.0.1:8000") # self.browser.find_element_by_id("header-buttons").find_elements_by_class_name("header-button")[1].click() # form = self.browser.find_element_by_id("loginForm") # form.find_element_by_id("id_username").send_keys(self.uname) # form.find_element_by_id("id_password").send_keys("foofoo") # form.submit() # sleep(1) # mid_button = self.browser.find_element_by_id("header-buttons").find_elements_by_class_name("header-button")[1] # self.assertTrue(mid_button.text, "Profile") # # Tests user creation as well as login/logout # def test_user(self): # self.signup() # self.logout() # self.login() # self.logout()
def test_delete_review_no_user_passed_in(self): profile = Profile.create_new_user('test11', '*****@*****.**', 'test11', date.today()) movie = Movie.get_details(5) new_review = Review() new_review.review_title = 'Test review' new_review.review_body = 'body' new_review.date_created = date.today() new_review.user = profile new_review.movie = movie new_review.save() with self.assertRaises( Exception ): # Verify that error is raised when trying to do this since user is not admin new_review.delete() # class BrowserTests(TestCase): # """ # Tests urls and views code. # """ # @classmethod # def setUpClass(cls): # cls.browser = webdriver.Chrome() # cls.uname = uuid1().hex[:30] # @classmethod # def tearDownClass(cls): # cls.browser.close() # # Check the spotlight redirects to the appropriate movie detail page # def spotlight(self): # self.browser.get("http://127.0.0.1:8000/") # self.browser.find_element_by_id("movie-spotlight").find_element_by_tag_name("img").click() # self.assertEqual(self.browser.current_url, "http://127.0.0.1:8000/movie/detail/5/") # # Metamorphic Property: if the user is not logged in, he should not be able to rate movies # def rating_absence(self): # self.browser.get("http://127.0.0.1:8000/movie/detail/5/") # self.assertFalse(self.browser.find_elements_by_id("rating-stars")) # # Tests properties that must be done independent of login # def test_misc(self): # self.spotlight() # self.rating_absence() # # Metamorphic Property: if the user is not logged in, he should not be able to rate movies # def signup(self): # self.browser.get("http://127.0.0.1:8000") # self.browser.find_element_by_class_name("signup-link").click() # form = self.browser.find_element_by_id("signupForm") # form.find_element_by_id("id_email_address").send_keys("foo@foo") # form.find_element_by_id("id_username").send_keys(self.uname) # form.find_element_by_id("id_password1").send_keys("foofoo") # form.find_element_by_id("id_password2").send_keys("foofoo") # form.submit() # sleep(1) # self.browser.find_element_by_id("header-buttons").find_elements_by_class_name("header-button")[1].click() # expected_url = u"http://127.0.0.1:8000/profile/%s/" % self.uname # self.assertEqual(self.browser.current_url, expected_url) # # Metamorphic Property: if the user is not logged in, the middle button in the header should # # be the Log In button # def logout(self): # self.browser.get("http://127.0.0.1:8000/") # sleep(1) # self.browser.find_element_by_id("header-buttons").find_elements_by_class_name("header-button")[2].click() # sleep(1) # mid_button = self.browser.find_element_by_id("header-buttons").find_elements_by_class_name("header-button")[1] # self.assertTrue(mid_button.text, "Log In") # # Metamorphic Property: if the user is not logged in, the middle button in the header should # # be the Profile button # def login(self): # self.browser.get("http://127.0.0.1:8000") # self.browser.find_element_by_id("header-buttons").find_elements_by_class_name("header-button")[1].click() # form = self.browser.find_element_by_id("loginForm") # form.find_element_by_id("id_username").send_keys(self.uname) # form.find_element_by_id("id_password").send_keys("foofoo") # form.submit() # sleep(1) # mid_button = self.browser.find_element_by_id("header-buttons").find_elements_by_class_name("header-button")[1] # self.assertTrue(mid_button.text, "Profile") # # Tests user creation as well as login/logout # def test_user(self): # self.signup() # self.logout() # self.login() # self.logout()
def index(request): return render(request, 'main/index.html', { 'popular_movie_list': Movie.get_popular()['items'][:6], })