from django.test import TestCase
from ..services.user_list_service import UserListService

class TestUserList(TestCase):
    def setUp(self):
        # 初始化测试数据
        self.test_params = {
            "page": 1,
            "size": 10,
            "sort": "-id",
            "username": "testuser",
            "email": "test@example.com",
            "phone": "1234567890",
            "nickname": "testnick",
            "fullname": "Test User",
            "is_using": True,
            "user_level": 1
        }

    def test_user_list_with_params(self):
        # 测试带参数的 user_list 方法
        result, err = UserListService.user_list(params=self.test_params)
        print("> TestUserList: test_user_list_with_params:", result, err)
        self.assertEqual(err, None)
        self.assertIn('list', result)
        self.assertIn('count', result)
        self.assertIn('size', result)
        self.assertIn('page', result)

    def test_user_list_without_params(self):
        # 测试不带参数的 user_list 方法
        result, err = UserListService.user_list()
        print("> TestUserList: test_user_list_without_params:", result, err)
        self.assertEqual(err, None)
        self.assertIn('list', result)
        self.assertIn('count', result)
        self.assertIn('size', result)
        self.assertIn('page', result)

    def test_user_list_with_invalid_sort(self):
        # 测试带无效排序参数的 user_list 方法
        invalid_params = self.test_params.copy()
        invalid_params["sort"] = "invalid_sort"
        result, err = UserListService.user_list(params=invalid_params)
        print("> TestUserList: test_user_list_with_invalid_sort:", result, err)
        self.assertEqual(err, None)
        self.assertIn('list', result)
        self.assertIn('count', result)
        self.assertIn('size', result)
        self.assertIn('page', result)

    def test_user_list_with_empty_search(self):
        # 测试带空搜索参数的 user_list 方法
        empty_search_params = {
            "page": 1,
            "size": 10,
            "sort": "-id"
        }
        result, err = UserListService.user_list(params=empty_search_params)
        print("> TestUserList: test_user_list_with_empty_search:", result, err)
        self.assertEqual(err, None)
        self.assertIn('list', result)
        self.assertIn('count', result)
        self.assertIn('size', result)
        self.assertIn('page', result)