test_deleteprofilefield.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. from io import StringIO
  2. from django.core.management import call_command
  3. from django.test import TestCase
  4. from misago.users.management.commands import deleteprofilefield
  5. from misago.users.testutils import create_test_user
  6. class DeleteProfileFieldTests(TestCase):
  7. def test_no_fieldname(self):
  8. """utility has no showstoppers when no fieldname is given"""
  9. out = StringIO()
  10. call_command(deleteprofilefield.Command(), stderr=out)
  11. command_output = out.getvalue().splitlines()[0].strip()
  12. self.assertEqual(command_output, "Specify fieldname to delete.")
  13. def test_no_fields_set(self):
  14. """utility has no showstoppers when no fields are set"""
  15. out = StringIO()
  16. call_command(deleteprofilefield.Command(), "gender", stdout=out)
  17. command_output = out.getvalue().splitlines()[0].strip()
  18. self.assertEqual(
  19. command_output, '"gender" profile field has been deleted from 0 users.'
  20. )
  21. def test_delete_fields(self):
  22. """utility has no showstoppers when no fields are set"""
  23. user = create_test_user(
  24. "User", "user@example.com", profile_fields={"gender": "male", "bio": "Yup!"}
  25. )
  26. out = StringIO()
  27. call_command(deleteprofilefield.Command(), "gender", stdout=out)
  28. command_output = out.getvalue().splitlines()[0].strip()
  29. self.assertEqual(
  30. command_output, '"gender" profile field has been deleted from 1 users.'
  31. )
  32. user.refresh_from_db()
  33. self.assertEqual(user.profile_fields, {"bio": "Yup!"})