test_api.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3. from django.urls import reverse
  4. from misago.users.testutils import AuthenticatedUserTestCase
  5. class ParseMarkupApiTests(AuthenticatedUserTestCase):
  6. def setUp(self):
  7. super(ParseMarkupApiTests, self).setUp()
  8. self.api_link = reverse('misago:api:parse-markup')
  9. def test_is_anonymous(self):
  10. """api requires authentication"""
  11. self.logout_user();
  12. response = self.client.post(self.api_link)
  13. self.assertContains(response, "This action is not available to guests.", status_code=403)
  14. def test_no_data(self):
  15. """api handles no data"""
  16. response = self.client.post(self.api_link)
  17. self.assertContains(response, "You have to enter a message.", status_code=400)
  18. def test_empty_post(self):
  19. """api handles empty post"""
  20. response = self.client.post(self.api_link, {
  21. 'post': ''
  22. })
  23. self.assertContains(response, "You have to enter a message.", status_code=400)
  24. def test_invalid_post(self):
  25. """api handles invalid post type"""
  26. response = self.client.post(self.api_link, {
  27. 'post': 123
  28. })
  29. self.assertContains(
  30. response, "Posted message should be at least 5 characters long (it has 3).",
  31. status_code=400)
  32. def test_valid_post(self):
  33. """api returns parsed markup for valid post"""
  34. response = self.client.post(self.api_link, {
  35. 'post': 'Lorem ipsum dolor met!'
  36. })
  37. self.assertContains(response, "<p>Lorem ipsum dolor met!</p>")