test_listusedprofilefields.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  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 listusedprofilefields
  5. from misago.users.test import create_test_user
  6. class ListUsedProfileFieldsTests(TestCase):
  7. def test_no_fields_set(self):
  8. """utility has no showstoppers when no fields are set"""
  9. create_test_user("User", "user@example.com")
  10. out = StringIO()
  11. call_command(listusedprofilefields.Command(), stdout=out)
  12. command_output = out.getvalue().splitlines()[0].strip()
  13. self.assertEqual(command_output, "No profile fields are currently in use.")
  14. def test_fields_set(self):
  15. """utility lists number of users that have different fields set"""
  16. create_test_user(
  17. "User1",
  18. "user1@example.com",
  19. profile_fields={"gender": "male", "bio": "Yup!"},
  20. )
  21. create_test_user(
  22. "User2", "user2@example.com", profile_fields={"gender": "male"}
  23. )
  24. create_test_user("User3", "user3@example.com", profile_fields={"location": ""})
  25. out = StringIO()
  26. call_command(listusedprofilefields.Command(), stdout=out)
  27. command_output = [l.strip() for l in out.getvalue().strip().splitlines()]
  28. self.assertEqual(command_output, ["bio: 1", "gender: 2", "location: 1"])