コード例 #1
0
    def test_favorites_for_user(self):
        """
        Returns favorites for user, sorted in reverse order of when they were added.

        TODO: test the before_id & after_id parameters.
        """
        new_user = User(name='new_user',
                        email='*****@*****.**',
                        verify_email_token='created',
                        email_confirmed=0,
                        is_paid=1)
        new_user.save()
        another_sharedfile = Sharedfile(source_id=self.sourcefile.id, name="my shared file",user_id=self.user.id, \
            content_type="image/png", share_key="ok", description="some\ndescription\nhere", source_url="https://www.mltshp.com/?hi")
        another_sharedfile.save()

        #one favorite shared file
        new_user.add_favorite(self.sharedfile)
        new_user.add_favorite(another_sharedfile)

        #this should only return one, since we don't dupe source_ids
        sfs = Sharedfile.favorites_for_user(new_user.id)
        self.assertEqual(sfs[0].id, self.sharedfile.id)

        #but really, underneath we should have two favorites
        fs = Favorite.where('user_id = %s', new_user.id)

        self.assertEqual(2, len(fs))
コード例 #2
0
    def test_unlike_removes_likes_from_parent_and_original(self):
        """
        A test of unliking a file and the likes being removed
        from parent and original.
        """
        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)

        un_favorites = Favorite.where('deleted=1')
        self.assertEqual(len(un_favorites), 3)
コード例 #3
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)