예제 #1
0
def create_favor(user=None, post=None, post_type=PostTypeChoiceEnum.POST):
    user = user or create_user()
    post = post or create_post(author=user)

    return Favor.objects.create(user_id=user.id,
                                post_id=post.id,
                                post_type=post_type)
예제 #2
0
    def test_del_post_tag(self):
        """
        测试取消添加标签
        python manage.py test tag.TagTest.test_del_post_tag
        """
        client, user = create_login_user()
        post = create_post(author=user, content='这是我的帖子')
        tag = mock.create_tag(user=user, content=u'第一个帖子')

        post_tag = mock.create_post_tag(tag=tag, post=post)

        result = PostTag.objects.filter(id=post_tag.id,
                                        is_deleted=False).exists()
        self.assertEqual(result, True)

        result = client.json_post(
            '/tag/post/delete/', {
                'tag_id': tag.id,
                'post_id': post.id,
                'post_type': PostTypeChoiceEnum.POST
            })
        self.assertEqual(result['error'], 0)
        self.assertEqual(result['error_msg'], u'')

        result = PostTag.objects.filter(id=post_tag.id,
                                        is_deleted=False).exists()
        self.assertEqual(result, False)
예제 #3
0
 def test_hot_view(self):
     """
     测试热门
     python manage.py test chat.ChatTest.test_hot_view
     """
     post = create_post(content='这是我的帖子')
     client = CustomClient()
     result = client.json_get("/chat/hot/list/")
     self.assertEqual(result["posts"][0]['content'], post.content)
예제 #4
0
def create_post_tag(post=None, tag=None, post_type=PostTypeChoiceEnum.POST):
    if not post:
        post = create_post()
    if not tag:
        tag = create_tag()

    return PostTag.objects.create(post_id=post.id,
                                  tag=tag,
                                  post_type=post_type)
예제 #5
0
 def test_favor(self):
     """
     测试收藏
     python manage.py test favor.FavorTest.test_favor
     """
     client, user = create_login_user()
     post = create_post(author=user, content='这是我的帖子')
     result = client.json_post('/favor/add/', {'post_id': post.id, 'post_type': PostTypeChoiceEnum.POST})
     self.assertEqual(result['error'], 0)
     self.assertEqual(result['error_msg'], u'')
예제 #6
0
    def test_del_post_view(self):
        """
        测试删除post
        python manage.py test chat.ChatTest.test_del_post_view
        """
        client, user = create_login_user()
        post = create_post(author=user, content='这是我的帖子')

        result = client.json_post('/chat/delete/', {'post_id': post.id})
        self.assertEqual(result['error'], 0)
        self.assertEqual(result['error_msg'], u'')
예제 #7
0
    def test_get_post_view(self):
        """
        测试获取post
        python manage.py test chat.ChatTest.test_get_post_view
        """
        client, user = create_login_user()
        post = create_post(content='这是我的帖子')

        result = client.json_get('/chat/%s/detail/' % post.id)
        self.assertEqual(result['id'], post.id)
        self.assertEqual(result['content'], post.content)
예제 #8
0
 def test_create_post_tag(self):
     """
     测试添加标签
     python manage.py test tag.TagTest.test_create_post_tag
     """
     client, user = create_login_user()
     post = create_post(author=user, content=u'这是我的帖子')
     tag = mock.create_tag(user=user, content=u'第一个帖子')
     result = client.json_post(
         '/tag/post/add/', {
             'tag_id': tag.id,
             'post_id': post.id,
             'post_type': PostTypeChoiceEnum.POST
         })
     self.assertEqual(result['error'], 0)
     self.assertEqual(result['error_msg'], u'')
예제 #9
0
    def test_un_favor(self):
        """
        测试取消收藏
        python manage.py test favor.FavorTest.test_un_favor
        """
        client, user = create_login_user()
        post = create_post(author=user, content='这是我的帖子')
        favor = mock.create_favor(user=user, post=post)

        result = Favor.objects.filter(id=favor.id, is_deleted=False).exists()
        self.assertEqual(result, True)

        result = client.json_post('/favor/delete/', {'post_id': post.id, 'post_type': PostTypeChoiceEnum.POST})
        self.assertEqual(result['error'], 0)
        self.assertEqual(result['error_msg'], u'')

        result = Favor.objects.filter(id=favor.id, is_deleted=False).exists()
        self.assertEqual(result, False)
예제 #10
0
def create_comment(user=None, post=None, post_type=PostTypeChoiceEnum.POST):
    user = user or create_user()
    post = post or create_post(author=user)

    return Comment.objects.create(author_id=user.id, post_id=post.id, post_type=post_type)