test_api.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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, {'post': ''})
  21. self.assertContains(response, "You have to enter a message.", status_code=400)
  22. def test_invalid_post(self):
  23. """api handles invalid post type"""
  24. response = self.client.post(self.api_link, {'post': 123})
  25. self.assertContains(
  26. response,
  27. "Posted message should be at least 5 characters long (it has 3).",
  28. status_code=400
  29. )
  30. def test_valid_post(self):
  31. """api returns parsed markup for valid post"""
  32. response = self.client.post(self.api_link, {'post': 'Lorem ipsum dolor met!'})
  33. self.assertContains(response, "<p>Lorem ipsum dolor met!</p>")