예제 #1
0
 def liking_Post(self):
     u1 = User(name='djibril',
               email='*****@*****.**',
               unhashpassword='******')
     u2 = User(name='ladji',
               email='*****@*****.**',
               unhashpassword='******')
     u3 = User(name='hussein',
               email='*****@*****.**',
               unhashpassword='******')
     u4 = User(name='rohit',
               email='*****@*****.**',
               unhashpassword='******')
     self.s.add(u1)
     self.s.add(u2)
     self.s.add(u3)
     self.s.add(u4)
     utcnow = datetime.utcnow()
     p1 = Post(body="post from djibril",
               author=u1,
               timestamp=utcnow + timedelta(seconds=1))
     p2 = Post(body="post from ladji",
               author=u2,
               timestamp=utcnow + timedelta(seconds=2))
     p3 = Post(body="post from hussein",
               author=u3,
               timestamp=utcnow + timedelta(seconds=3))
     p4 = Post(body="post from rohit",
               author=u4,
               timestamp=utcnow + timedelta(seconds=4))
     self.s.add(p1)
     self.s.add(p2)
     self.s.add(p3)
     self.s.add(p4)
     self.s.commit()
     u1like = UserPostLike()
     u1like.like(u1, p2, self.s)
     u1like.like(u2, p2, self.s)
     u1like.like(u3, p2, self.s)
     self.s.add(u1like)
     self.s.add(p2)
     self.s.commit()
     assert p2.like_count == 3
예제 #2
0
def like_post():
    data = request.get_json(force=True)
    currentUserEmail = unicodedata.normalize('NFKD',
                                             data['currentUserEmail']).encode(
                                                 'ascii', 'ignore')
    postId = unicodedata.normalize('NFKD',
                                   data['postId']).encode('ascii', 'ignore')
    try:
        like_post_session = s()
        currentUser_obj = get_user_by_email(currentUserEmail,
                                            like_post_session)
        post_obj = get_post_by_id(postId)
        userPost = UserPostLike()
        userPost.like(currentUser_obj, post_obj, session)
        session.add(userPost)
        session.add(post_obj)
        session.commit()
        response = {"id": post_obj.id, "like_count": post_obj.like_count}
        return Response(json.dumps(response))
    except exc.InvalidRequestError, e:

        Response(e)
        return None