Esempio n. 1
0
def submit_review(request):
    if request.method == 'POST':
        current_date = datetime.today()
        body = request.POST['review_body']
        title = request.POST['review_title']
        current_user = Profile.objects.filter(user=request.user)[0]
        current_movie = Movie.objects.filter(
            m_id=int(request.POST['movie_id']))[0]

        already_exists = Review.objects.filter(
            movie=current_movie, user=current_user).filter(deleted=False)

        if not len(already_exists):
            new_review = Review(review_title=title,
                                date_created=current_date,
                                date_edited=None,
                                review_body=body,
                                user=current_user,
                                movie=current_movie)
            new_review.save()

            for cleanup in Review.objects.filter(user=current_user).filter(
                    deleted=True):
                super(Review, cleanup).delete()

    return HttpResponseRedirect(request.META['HTTP_REFERER'])
Esempio n. 2
0
 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)
Esempio n. 3
0
 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)
Esempio n. 4
0
 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)
Esempio n. 5
0
 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)
Esempio n. 6
0
def submit_review(request):
    if request.method == 'POST':
        current_date = datetime.today()
        body = request.POST['review_body']
        title = request.POST['review_title']
        current_user = Profile.objects.filter(user=request.user)[0]
        current_movie = Movie.objects.filter(m_id=int(request.POST['movie_id']))[0]

        already_exists = Review.objects.filter(movie=current_movie, user=current_user).filter(deleted=False)

        if not len(already_exists):
            new_review = Review(review_title=title,
                                date_created=current_date,
                                date_edited=None,
                                review_body=body,
                                user=current_user,
                                movie=current_movie)
            new_review.save()

            for cleanup in Review.objects.filter(user=current_user).filter(deleted=True):
                super(Review, cleanup).delete()

    return HttpResponseRedirect(request.META['HTTP_REFERER'])
Esempio n. 7
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()
Esempio n. 8
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()