Ejemplo n.º 1
0
    def test_add_favorite(self):
        """
        A user should be able to favorite a sharedfile if:
         - it belongs to another user
         - it's not already favorited
         - if it's been favorited, but favorite was "deleted"

        A user shouldn't be able to favorite a sharedfile if they own it.
        """
        # Create new user with their own sharedfile.
        new_user = User(name='newuser',email='*****@*****.**', \
            verify_email_token = 'created', password='******', email_confirmed=1, is_paid=1)
        new_user.save()
        new_sharedfile = Sharedfile(source_id=self.sourcefile.id, name="my shared file", \
            user_id=new_user.id, content_type="image/png", share_key="ok")
        new_sharedfile.save()

        # One should be able to favorite another user's sharedfile
        self.assertTrue(self.user.add_favorite(new_sharedfile))
        favorites = Favorite.all("where user_id = %s and sharedfile_id = %s and deleted = 0", \
            self.user.id, new_sharedfile.id)
        self.assertEqual(1, len(favorites))

        # Can't favorite an already favorited sharedfile.
        self.assertFalse(self.user.add_favorite(new_sharedfile))
        favorites = Favorite.all("where user_id = %s and sharedfile_id = %s and deleted = 0", \
            self.user.id, new_sharedfile.id)
        self.assertEqual(1, len(favorites))

        # A favorite with "deleted" flag set, should have flag unset and
        # return True when add_favorite called
        favorite = Favorite.get("user_id = %s and sharedfile_id = %s and deleted = 0", \
            self.user.id, new_sharedfile.id)
        favorite.deleted = True
        favorite.save()
        self.assertTrue(self.user.add_favorite(new_sharedfile))
        favorites = Favorite.all("where user_id = %s and sharedfile_id = %s and deleted = 0", \
            self.user.id, new_sharedfile.id)
        self.assertEqual(1, len(favorites))

        # Can't favorite one's own sharedfile.
        self.assertTrue(self.sharedfile.user_id, self.user.id)
        self.assertFalse(self.user.add_favorite(self.sharedfile))
        favorites = Favorite.all("where user_id = %s and sharedfile_id = %s and deleted = 0", \
            self.user.id, self.sharedfile.id)
        self.assertEqual(0, len(favorites))
Ejemplo n.º 2
0
    def test_like_does_not_go_to_original_file_if_liker_is_poster(self):
        """
        This tests that if user A posts a file, user B saves it and then
        user A likes user B's file, user A does not receive a like.
        """
        sharedfile = self._create_sharedfile(self.admin)
        joe_sharedfile = sharedfile.save_to_shake(self.joe)

        self.sign_in('admin', 'asdfasdf')
        response = self.post_url('/p/%s/like?json=1' %
                                 joe_sharedfile.share_key)

        self.assertEqual(len(Favorite.all()), 1)
Ejemplo n.º 3
0
    def test_like_unlike_not_signed_in(self):
        """
        Liking or unliking something should return a 403 if user is not
        signed in.  No Favorites should be created.
        """
        sharedfile = self._create_sharedfile(self.admin)
        response = self.post_url('/p/%s/like?json=1' % sharedfile.share_key)

        self.assertEqual(response.code, 403)
        favorites = Favorite.all()
        self.assertEqual(len(favorites), 0)
        response = self.post_url('/p/%s/unlike?json=1' % sharedfile.share_key)
        self.assertEqual(response.code, 403)
Ejemplo n.º 4
0
    def test_remove_favorite(self):
        """
        User.remove_favorite should return False if the sharedfile has never been favorited or
        has been removed.

        Should return true if removing favorite succeeds
        """
        # Create new user with their own sharedfile.
        new_user = User(name='newuser',email='*****@*****.**', \
            verify_email_token = 'created', password='******', email_confirmed=1, is_paid=1)
        new_user.save()
        new_sharedfile = Sharedfile(source_id=self.sourcefile.id, name="my shared file", \
            user_id=new_user.id, content_type="image/png", share_key="ok")
        new_sharedfile.save()

        # remove_favorite should return false when sharedfile not already favorited.
        favorites = Favorite.all("where user_id = %s and sharedfile_id = %s and deleted = 0", \
            self.user.id, new_sharedfile.id)
        self.assertEqual(0, len(favorites))
        self.assertFalse(self.user.remove_favorite(new_sharedfile))

        # remove_favorite should return True when unfavoring succeeds, deleted
        # flag on Favorite should be set to 0.  Should return false on a subsequent
        # attempt on remove_favorite
        self.user.add_favorite(new_sharedfile)
        favorites = Favorite.all("where user_id = %s and sharedfile_id = %s and deleted = 0", \
            self.user.id, new_sharedfile.id)
        self.assertEqual(1, len(favorites))
        self.assertTrue(self.user.remove_favorite(new_sharedfile))
        favorites = Favorite.all("where user_id = %s and sharedfile_id = %s and deleted = 0", \
            self.user.id, new_sharedfile.id)
        self.assertEqual(0, len(favorites))

        # remove_favorite on deleted favorite should return False.
        favorites = Favorite.all("where user_id = %s and sharedfile_id = %s and deleted = 1", \
            self.user.id, new_sharedfile.id)
        self.assertEqual(1, len(favorites))
        self.assertFalse(self.user.remove_favorite(new_sharedfile))
Ejemplo n.º 5
0
    def test_like_gives_like_to_parent_and_original(self):
        """
        This tests that if user A posts a file, user B saves it and
        user C likes it, both user A and B shared file receives a like.
        """
        sharedfile = self._create_sharedfile(self.admin)
        joe_sharedfile = sharedfile.save_to_shake(self.joe)
        bill_sharedfile = joe_sharedfile.save_to_shake(self.bill)

        self.sign_in('frank', 'asdfasdf')
        response = self.post_url('/p/%s/like?json=1' %
                                 bill_sharedfile.share_key)

        self.assertEqual(len(Favorite.all()), 3)
Ejemplo n.º 6
0
    def test_like_of_shared_file_with_deleted_parents(self):
        """
        Tests that if a file is liked and its parents are deleted
        they should not get likes
        """
        sharedfile = self._create_sharedfile(self.admin)
        joe_sharedfile = sharedfile.save_to_shake(self.joe)
        bill_sharedfile = joe_sharedfile.save_to_shake(self.bill)

        sharedfile.delete()
        joe_sharedfile.delete()

        self.sign_in('frank', 'asdfasdf')
        response = self.post_url('/p/%s/like?json=1' %
                                 bill_sharedfile.share_key)

        self.assertEqual(len(Favorite.all()), 1)
Ejemplo n.º 7
0
    def test_add_favorite_deleted_sharedfile(self):
        """
        User.add_favorite should return False if sharedfile is deleted
        and no Favorite entries should be logged.
        """
        # Create new user with their own sharedfile.
        new_user = User(name='newuser',email='*****@*****.**', \
            verify_email_token = 'created', password='******', email_confirmed=1, is_paid=1)
        new_user.save()
        new_sharedfile = Sharedfile(source_id=self.sourcefile.id, name="my shared file", \
            user_id=new_user.id, content_type="image/png", share_key="ok")
        new_sharedfile.save()

        new_sharedfile.delete()
        self.assertFalse(self.user.add_favorite(new_sharedfile))
        favorites = Favorite.all("where user_id = %s and sharedfile_id = %s and deleted = 0", \
            self.user.id, new_sharedfile.id)
        self.assertEqual(0, len(favorites))
Ejemplo n.º 8
0
    def test_reliking_undeletes_parent_and_original(self):
        """
        A test that reliking a file that was previously unliked
        will undelete the likes above it.
        """
        sharedfile = self._create_sharedfile(self.admin)
        joe_sharedfile = sharedfile.save_to_shake(self.joe)
        bill_sharedfile = joe_sharedfile.save_to_shake(self.bill)

        self.sign_in('frank', 'asdfasdf')
        response = self.post_url('/p/%s/like?json=1' %
                                 bill_sharedfile.share_key)
        response = self.post_url('/p/%s/unlike?json=1' %
                                 bill_sharedfile.share_key)
        response = self.post_url('/p/%s/like?json=1' %
                                 bill_sharedfile.share_key)

        self.assertEqual(len(Favorite.all()), 3)
Ejemplo n.º 9
0
    def test_unlike_of_shared_file_with_deleted_parents(self):
        """
        This tests that if you delete the original and parents of a file
        and then unlike the file, it doesn't choke on there not being existing
        ids
        """
        sharedfile = self._create_sharedfile(self.admin)
        joe_sharedfile = sharedfile.save_to_shake(self.joe)
        bill_sharedfile = joe_sharedfile.save_to_shake(self.bill)

        self.sign_in('frank', 'asdfasdf')
        response = self.post_url('/p/%s/like?json=1' %
                                 bill_sharedfile.share_key)

        self.assertEqual(len(Favorite.all()), 3)
        sharedfile.delete()
        joe_sharedfile.delete()

        response = self.post_url('/p/%s/unlike?json=1' %
                                 bill_sharedfile.share_key)

        self.assertEqual(len(Favorite.where('deleted = 1')), 3)