Example #1
0
    def test_comment_api(self):
        Auuid = uuid.uuid4()
        post_uuid = uuid.uuid4()

        user = User.objects.create_user("test", "*****@*****.**",
                                        "testpassword")
        author = Author(user=user, uuid=Auuid)
        author.save()

        post = Post(uuid=post_uuid,
                    author=author,
                    title="test post",
                    content="this is a test")
        post.save()

        comment = Comment(author=author, post=post, content="Test Comment")
        comment.save()

        self.client.login(username=user.username, password="******")
        ApiUrl = reverse("api:post_comments", args=[post_uuid])

        #Test GET method. The GET method returns a list of comments on a specific post
        GetResponse = self.client.get(ApiUrl)
        self.assertEqual(GetResponse.status_code, status.HTTP_200_OK)
        self.assertEqual(GetResponse.data.get("count"), 1)
        self.assertEqual(
            GetResponse.data.get("comments")[0].get("comment"), "Test Comment")
def new_comment(request):
    if request.method == 'POST':
        content = request.POST.get('content')
        post_uuid = request.POST.get('post')
        comment = Comment(author=Author.objects.get(user=request.user), content=content, post=Post.objects.get(uuid=post_uuid))
        comment.save()
        return HttpResponseRedirect(reverse('socialp2p:main'))
def new_comment(request):
    if request.method == 'POST':
        content = request.POST.get('content')
        post_uuid = request.POST.get('post')
        comment = Comment(author=Author.objects.get(user=request.user),
                          content=content,
                          post=Post.objects.get(uuid=post_uuid))
        comment.save()
        return HttpResponseRedirect(reverse('socialp2p:main'))
    def test_comment(self):

	Commentuuid = uuid.uuid4()

        user = User.objects.create_user("test", "*****@*****.**", "testpassword")
	author = Author(user=user)
	author.save()

	posts = Post(author=author, title="test post", content="this is a test", visibility="PUBLIC")
	posts.save()

	comment = Comment(author=author, post=posts, uuid=Commentuuid)
	comment.save()

	self.assertEqual(Comment.objects.count(), 1)
	self.assertEqual(comment.uuid, Commentuuid)
Example #5
0
    def test_comment(self):

        Commentuuid = uuid.uuid4()

        user = User.objects.create_user("test", "*****@*****.**",
                                        "testpassword")
        author = Author(user=user)
        author.save()

        posts = Post(author=author,
                     title="test post",
                     content="this is a test",
                     visibility="PUBLIC")
        posts.save()

        comment = Comment(author=author, post=posts, uuid=Commentuuid)
        comment.save()

        self.assertEqual(Comment.objects.count(), 1)
        self.assertEqual(comment.uuid, Commentuuid)
    def test_comment_api(self):
        Auuid = uuid.uuid4()
	post_uuid = uuid.uuid4()
	
	user = User.objects.create_user("test", "*****@*****.**", "testpassword")
	author = Author(user=user, uuid=Auuid)
	author.save()

	post = Post(uuid=post_uuid, author=author, title="test post", content="this is a test")
	post.save()

	comment = Comment(author=author, post=post, content="Test Comment")
	comment.save()

	self.client.login(username=user.username, password="******")
	ApiUrl = reverse("api:post_comments", args=[post_uuid])

	#Test GET method. The GET method returns a list of comments on a specific post
	GetResponse = self.client.get(ApiUrl)
	self.assertEqual(GetResponse.status_code, status.HTTP_200_OK)
	self.assertEqual(GetResponse.data.get("count"), 1)
	self.assertEqual(GetResponse.data.get("comments")[0].get("comment"), "Test Comment")