test_validate_post.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3. from django.urls import reverse
  4. from misago.categories.models import Category
  5. from misago.users.testutils import AuthenticatedUserTestCase
  6. class ValidatePostTests(AuthenticatedUserTestCase):
  7. def setUp(self):
  8. super(ValidatePostTests, self).setUp()
  9. self.category = Category.objects.get(slug='first-category')
  10. self.api_link = reverse('misago:api:thread-list')
  11. def test_title_validation(self):
  12. """validate_post tests title"""
  13. response = self.client.post(self.api_link, data={
  14. 'category': self.category.pk,
  15. 'title': 'Check our l33t CaSiNo!',
  16. 'post': 'Lorem ipsum dolor met!',
  17. })
  18. self.assertContains(response, "Don't discuss gambling!", status_code=400)
  19. # clean title passes validation
  20. response = self.client.post(self.api_link, data={
  21. 'category': self.category.pk,
  22. 'title': 'Check our l33t place!',
  23. 'post': 'Lorem ipsum dolor met!',
  24. })
  25. self.assertEqual(response.status_code, 200)
  26. def test_post_validation(self):
  27. """validate_post tests post content"""
  28. response = self.client.post(self.api_link, data={
  29. 'category': self.category.pk,
  30. 'title': 'Lorem ipsum dolor met!',
  31. 'post': 'Check our l33t CaSiNo!',
  32. })
  33. self.assertContains(response, "Don't discuss gambling!", status_code=400)
  34. # clean post passes validation
  35. response = self.client.post(self.api_link, data={
  36. 'category': self.category.pk,
  37. 'title': 'Lorem ipsum dolor met!',
  38. 'post': 'Check our l33t place!',
  39. })
  40. self.assertEqual(response.status_code, 200)
  41. def test_empty_input(self):
  42. """validate_post handles empty input"""
  43. response = self.client.post(self.api_link, data={
  44. 'category': self.category.pk,
  45. })
  46. self.assertEqual(response.status_code, 400)
  47. response = self.client.post(self.api_link, data={
  48. 'category': self.category.pk,
  49. 'title': '',
  50. 'post': '',
  51. })
  52. self.assertEqual(response.status_code, 400)