def test_search_users(self): Profile.create_new_user('uniquetestuser', '*****@*****.**', 'password1', date.today()) found = Profile.search('uniquetest') #for profile in found: # user = profile.user self.assertTrue(len(found) > 0)
def test_search_for_profile_0_chars(self): Profile.create_new_user('uniquetestuser', '*****@*****.**', 'password1', date.today()) with self.assertRaises( InvalidSearchException ): # Verify that exception is raised, as it should be Profile.search( '') # A search with 0 characters should throw an exception
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_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 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_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_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_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_find_user_when_does_not_exist(self): profile = Profile.create_new_user('testuser1', '*****@*****.**', 'password1', date.today()) profile_found = Profile.find('auserthatdoesntexist') self.assertTrue(profile_found is None)
def test_find_user_when_exists(self): profile = Profile.create_new_user('testuser1', '*****@*****.**', 'password1', date.today()) profile_found = Profile.find('testuser1') self.assertTrue(profile_found == profile)
def test_search_for_profile_0_chars(self): Profile.create_new_user('uniquetestuser', '*****@*****.**', 'password1', date.today()) with self.assertRaises(InvalidSearchException): # Verify that exception is raised, as it should be Profile.search('') # A search with 0 characters should throw an exception
def test_search_for_profile_9999999_chars(self): Profile.create_new_user('uniquetestuser', '*****@*****.**', 'password1', date.today()) with self.assertRaises(InvalidSearchException): Profile.search('t' * 9999999)
def test_search_for_profile_2000_chars(self): Profile.create_new_user('uniquetestuser', '*****@*****.**', 'password1', date.today()) profile = Profile.search('t' * 2000) self.assertTrue(len(profile) == 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()