test_users_api.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. from django.contrib.auth import get_user_model
  2. from misago.conf import settings
  3. from misago.users.testutils import AuthenticatedUserTestCase
  4. class UserForumOptionsTests(AuthenticatedUserTestCase):
  5. """
  6. tests for user forum options RPC (POST to /api/users/1/forum-options/)
  7. """
  8. def setUp(self):
  9. super(UserForumOptionsTests, self).setUp()
  10. self.link = '/api/users/%s/forum-options/' % self.user.pk
  11. def test_empty_request(self):
  12. """empty request is handled"""
  13. response = self.client.post(self.link)
  14. self.assertEqual(response.status_code, 400)
  15. fields = (
  16. 'limits_private_thread_invites_to',
  17. 'subscribe_to_started_threads',
  18. 'subscribe_to_replied_threads'
  19. )
  20. for field in fields:
  21. self.assertIn('"%s"' % field, response.content)
  22. def test_change_forum_options(self):
  23. """forum options are changed"""
  24. response = self.client.post(self.link, data={
  25. 'limits_private_thread_invites_to': 1,
  26. 'subscribe_to_started_threads': 2,
  27. 'subscribe_to_replied_threads': 1
  28. })
  29. self.assertEqual(response.status_code, 200)
  30. self.reload_user();
  31. self.assertFalse(self.user.is_hiding_presence)
  32. self.assertEqual(self.user.limits_private_thread_invites_to, 1)
  33. self.assertEqual(self.user.subscribe_to_started_threads, 2)
  34. self.assertEqual(self.user.subscribe_to_replied_threads, 1)