test_listusedprofilefields.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. from io import StringIO
  2. from django.contrib.auth import get_user_model
  3. from django.core.management import call_command
  4. from django.test import TestCase
  5. from misago.users.management.commands import listusedprofilefields
  6. UserModel = get_user_model()
  7. class ListUsedProfileFieldsTests(TestCase):
  8. def test_no_fields_set(self):
  9. """utility has no showstoppers when no fields are set"""
  10. UserModel.objects.create_user('Bob', 'bob@bob.com', 'pass123')
  11. out = StringIO()
  12. call_command(listusedprofilefields.Command(), stdout=out)
  13. command_output = out.getvalue().splitlines()[0].strip()
  14. self.assertEqual(command_output, "No profile fields are currently in use.")
  15. def test_fields_set(self):
  16. """utility lists number of users that have different fields set"""
  17. user = UserModel.objects.create_user('Bob', 'bob@bob.com', 'pass123')
  18. user.profile_fields = {'gender': 'male', 'bio': "Yup!"}
  19. user.save()
  20. user = UserModel.objects.create_user('Bob2', 'bob2@bob.com', 'pass123')
  21. user.profile_fields = {'gender': 'male'}
  22. user.save()
  23. user = UserModel.objects.create_user('Bob3', 'bob3@bob.com', 'pass123')
  24. user.profile_fields = {'location': ""}
  25. user.save()
  26. out = StringIO()
  27. call_command(listusedprofilefields.Command(), stdout=out)
  28. command_output = [l.strip() for l in out.getvalue().strip().splitlines()]
  29. self.assertEqual(command_output, [
  30. "bio: 1",
  31. "gender: 2",
  32. "location: 1",
  33. ])