test_account_model.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. from django.test import TestCase
  2. from apps.account.models import LoonUser, LoonDept, LoonRole
  3. class TestLoonAccountModel(TestCase):
  4. fixtures = ['accounts.json']
  5. def test_loon_user_get_dict(self):
  6. """
  7. 测试获取字典格式用户信息
  8. :return:
  9. """
  10. test_user1 = LoonUser.objects.get(username='guiji')
  11. assert isinstance(test_user1.get_dict(), dict)
  12. def test_loon_user_is_staff(self):
  13. """
  14. 测试用户staff判断
  15. :return:
  16. """
  17. test_user1 = LoonUser.objects.get(username='guiji')
  18. assert isinstance(test_user1.is_staff, bool)
  19. def test_loon_user_get_short_name(self):
  20. """
  21. 测试获取short_name
  22. :return:
  23. """
  24. test_user1 = LoonUser.objects.get(username='guiji')
  25. self.assertEqual(test_user1.get_short_name(), 'guiji')
  26. def test_loon_user_get_alias_name(self):
  27. """
  28. 测试获取用户昵称
  29. :return:
  30. """
  31. test_user1 = LoonUser.objects.get(username='guiji')
  32. self.assertEqual(test_user1.get_alias_name(), '轨迹')
  33. def test_loon_user_dept_name(self):
  34. """
  35. 测试获取用户部门名称
  36. :return:
  37. """
  38. test_user1 = LoonUser.objects.get(username='admin')
  39. self.assertEqual(test_user1.dept_name, '总部,技术部')
  40. def test_loon_user_get_json(self):
  41. """
  42. 测试获取用户json格式信息
  43. :return:
  44. """
  45. test_user1 = LoonUser.objects.get(username='guiji')
  46. assert isinstance(test_user1.get_json(), str)
  47. def test_role_get_dict(self):
  48. """
  49. 测试获取角色字典信息格式
  50. :return:
  51. """
  52. role = LoonRole.objects.get(name='VPN管理员')
  53. assert isinstance(role.get_dict(), dict)
  54. def test_dept_get_dict(self):
  55. """
  56. 测试获取部门字典信息格式
  57. :return:
  58. """
  59. dept = LoonDept.objects.get(id=1)
  60. assert isinstance(dept.get_dict(), dict)