from django.test import TestCase
from ..services.user_service import UserService
from ..utils.j_ulid_field import JULIDField
import datetime
from ulid import ULID


class TestUser(TestCase):
    def setUp(self):
        # 初始化测试数据
        self.test_params = {
            "account": "testuser",
            "password": "testpassword",
            "fullname": "Test User",
            "nickname": "testnick",
            "user_type": "PERSON",
            "phone": "1234567890",
            "email": "23944@qq.com"
        }

    __right = {
        "account": 'u001',
    }

    def test_add(self):
        result, err = UserService.user_add(self.__right)
        print("> UserBaseTest: test_add:", result, err)
        self.assertEqual(err, None)

    def test_detail(self):
        UserService.user_add(self.__right)
        exist, err = UserService.check_account('u001')
        print("> UserBaseTest: test_detail:", exist, err)
        self.assertEqual(err, None)

    def test_edit(self):
        UserService.user_add(self.__right)
        exist, err = UserService.check_account(self.__right['account'])
        print("> UserBaseTest: test_edit: 1 exist:", exist)
        exist['fullname'] = '路乙'
        result, err = UserService.user_edit(exist, user_id=exist['user_id'])
        print("> UserBaseTest: test_edit: 2 result:", result)
        self.assertEqual(err, None)

    def test_delete(self):
        UserService.user_add(self.__right)
        exist, err = UserService.check_account(self.__right['account'])
        print("> UserBaseTest: test_delete: 1 exist:", exist)

        result, err = UserService.user_delete(exist['user_id'])
        print("> ThreadClassifyTest::test_delete:", result)
        self.assertEqual(err, None)

    def test_uuid_delete(self):
        UserService.user_add(self.__right)
        exist, err = UserService.check_account(self.__right['account'])

        print("> UserBaseTest: test_delete: 1 exist:", exist)

        result, err = UserService.user_delete(user_uuid=exist['user_uuid'])
        print("> ThreadClassifyTest::test_delete:", result)
        self.assertEqual(err, None)