123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- from django.shortcuts import reverse
- from model_bakery import baker
- from glitchtip.test_utils.test_case import GlitchTipTestCase
- # Create your tests here.
- class CommentsApiTestCase(GlitchTipTestCase):
- def setUp(self):
- self.create_user_and_project()
- self.issue = baker.make("issue_events.Issue", project=self.project)
- self.url = reverse("api:list_comments", kwargs={"issue_id": self.issue.id})
- def test_comment_creation(self):
- data = {"data": {"text": "Test"}}
- not_my_issue = baker.make("issue_events.Issue")
- res = self.client.post(self.url, data, format="json")
- self.assertEqual(res.status_code, 201)
- self.assertEqual(res.json()["data"]["text"], "Test")
- url = reverse(
- "api:list_comments",
- kwargs={"issue_id": not_my_issue.id},
- )
- res = self.client.post(url, data, format="json")
- self.assertEqual(res.status_code, 400)
- def test_comments_list(self):
- comments = baker.make(
- "issue_events.Comment",
- issue=self.issue,
- user=self.user,
- _fill_optional=["text"],
- _quantity=3,
- )
- not_my_issue = baker.make("issue_events.Issue")
- baker.make(
- "issue_events.Comment", issue=not_my_issue, _fill_optional=["text"]
- )
- res = self.client.get(self.url)
- self.assertContains(res, comments[2].text)
- url = reverse("api:list_comments", kwargs={"issue_id": not_my_issue.id})
- res = self.client.get(url)
- self.assertEqual(len(res.json()), 0)
- def test_comment_update(self):
- comment = baker.make(
- "issue_events.Comment",
- issue=self.issue,
- user=self.user,
- _fill_optional=["text"],
- )
- url = reverse(
- "api:update_comment",
- kwargs={"issue_id": self.issue.id, "comment_id": comment.id},
- )
- data = {"data": {"text": "Test"}}
- res = self.client.put(url, data, format="json")
- self.assertEqual(res.json()["data"]["text"], "Test")
- def test_comment_delete(self):
- comment = baker.make(
- "issue_events.Comment",
- issue=self.issue,
- user=self.user,
- _fill_optional=["text"],
- )
- url = reverse(
- "api:delete_comment",
- kwargs={"issue_id": self.issue.id, "comment_id": comment.id},
- )
- self.client.delete(url)
- res = self.client.get(self.url)
- self.assertEqual(len(res.json()), 0)
|