2018-11-27 12:26:36 -08:00
|
|
|
import json
|
|
|
|
from mock import patch
|
|
|
|
|
|
|
|
from grant.proposal.models import Proposal, db
|
|
|
|
from ..config import BaseUserConfig
|
|
|
|
from ..test_data import test_comment, test_reply
|
|
|
|
|
|
|
|
|
2018-12-17 10:33:33 -08:00
|
|
|
class TestProposalCommentAPI(BaseUserConfig):
|
2019-01-04 11:03:37 -08:00
|
|
|
def test_unauthorized_create_new_proposal_comment(self):
|
|
|
|
# no login
|
|
|
|
proposal = Proposal(
|
|
|
|
status="LIVE"
|
|
|
|
)
|
|
|
|
db.session.add(proposal)
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
comment_res = self.app.post(
|
|
|
|
"/api/v1/proposals/{}/comments".format(proposal.id),
|
|
|
|
data=json.dumps(test_comment),
|
|
|
|
content_type='application/json'
|
|
|
|
)
|
|
|
|
self.assertStatus(comment_res, 401)
|
|
|
|
|
2018-11-27 12:26:36 -08:00
|
|
|
def test_create_new_proposal_comment(self):
|
2018-12-17 10:33:33 -08:00
|
|
|
self.login_default_user()
|
2018-11-27 12:26:36 -08:00
|
|
|
proposal = Proposal(
|
|
|
|
status="LIVE"
|
|
|
|
)
|
|
|
|
db.session.add(proposal)
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
comment_res = self.app.post(
|
|
|
|
"/api/v1/proposals/{}/comments".format(proposal.id),
|
|
|
|
data=json.dumps(test_comment),
|
|
|
|
content_type='application/json'
|
|
|
|
)
|
|
|
|
self.assertStatus(comment_res, 201)
|
2018-11-27 12:29:41 -08:00
|
|
|
|
|
|
|
def test_invalid_proposal_id_create_comment(self):
|
2018-12-17 10:33:33 -08:00
|
|
|
self.login_default_user()
|
2018-11-27 12:29:41 -08:00
|
|
|
comment_res = self.app.post(
|
|
|
|
"/api/v1/proposals/12345/comments",
|
|
|
|
data=json.dumps(test_comment),
|
|
|
|
content_type='application/json'
|
|
|
|
)
|
|
|
|
self.assertStatus(comment_res, 404)
|
|
|
|
|
2018-11-27 12:26:36 -08:00
|
|
|
def test_create_new_proposal_comment_reply(self):
|
2018-12-17 10:33:33 -08:00
|
|
|
self.login_default_user()
|
2018-11-27 12:26:36 -08:00
|
|
|
proposal = Proposal(
|
|
|
|
status="LIVE"
|
|
|
|
)
|
|
|
|
db.session.add(proposal)
|
|
|
|
db.session.commit()
|
|
|
|
proposal_id = proposal.id
|
|
|
|
|
|
|
|
comment_res = self.app.post(
|
|
|
|
"/api/v1/proposals/{}/comments".format(proposal_id),
|
|
|
|
data=json.dumps(test_comment),
|
|
|
|
content_type='application/json'
|
|
|
|
)
|
|
|
|
self.assertStatus(comment_res, 201)
|
|
|
|
|
|
|
|
test_reply_copy = test_reply.copy()
|
|
|
|
test_reply_copy["parentCommentId"] = comment_res.json["id"]
|
|
|
|
reply_res = self.app.post(
|
|
|
|
"/api/v1/proposals/{}/comments".format(proposal_id),
|
|
|
|
data=json.dumps(test_reply_copy),
|
|
|
|
content_type='application/json'
|
|
|
|
)
|
|
|
|
self.assertStatus(reply_res, 201)
|
|
|
|
self.assertEqual(
|
|
|
|
reply_res.json["parentCommentId"],
|
|
|
|
comment_res.json["id"]
|
|
|
|
)
|
2018-12-17 10:33:33 -08:00
|
|
|
|
2018-11-27 12:29:41 -08:00
|
|
|
def test_invalid_parent_comment_id_create_reply(self):
|
2018-12-17 10:33:33 -08:00
|
|
|
self.login_default_user()
|
2018-11-27 12:29:41 -08:00
|
|
|
proposal = Proposal(
|
|
|
|
status="LIVE"
|
|
|
|
)
|
|
|
|
db.session.add(proposal)
|
|
|
|
db.session.commit()
|
|
|
|
proposal_id = proposal.id
|
|
|
|
|
|
|
|
comment_res = self.app.post(
|
|
|
|
"/api/v1/proposals/{}/comments".format(proposal_id),
|
|
|
|
data=json.dumps(test_comment),
|
|
|
|
content_type='application/json'
|
|
|
|
)
|
|
|
|
self.assertStatus(comment_res, 201)
|
|
|
|
|
|
|
|
test_reply_copy = test_reply.copy()
|
|
|
|
test_reply_copy["parentCommentId"] = comment_res.json["id"] + 1
|
|
|
|
reply_res = self.app.post(
|
|
|
|
"/api/v1/proposals/{}/comments".format(proposal_id),
|
|
|
|
data=json.dumps(test_reply_copy),
|
|
|
|
content_type='application/json'
|
|
|
|
)
|
|
|
|
self.assertStatus(reply_res, 400)
|