From 16ec5898abee26a68ba42e035936f9fc98b84732 Mon Sep 17 00:00:00 2001 From: ShiYue Date: Tue, 5 Nov 2019 11:24:03 +0800 Subject: [PATCH] =?UTF-8?q?fix(userdetail):=20=E4=BF=AE=E6=94=B9=E4=B8=8D?= =?UTF-8?q?=E8=83=BD=E6=94=B9=E5=90=8D=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migrations/0063_auto_20191104_1454.py | 23 ++++++++++++++++ oneid_meta/models/user.py | 4 +-- siteapi/v1/tests/test_ding.py | 27 +++++++++++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 oneid_meta/migrations/0063_auto_20191104_1454.py diff --git a/oneid_meta/migrations/0063_auto_20191104_1454.py b/oneid_meta/migrations/0063_auto_20191104_1454.py new file mode 100644 index 000000000..2ab1e1c7e --- /dev/null +++ b/oneid_meta/migrations/0063_auto_20191104_1454.py @@ -0,0 +1,23 @@ +# Generated by Django 2.0.13 on 2019-11-04 06:54 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('oneid_meta', '0062_auto_20191102_1745'), + ] + + operations = [ + migrations.AlterField( + model_name='dinguser', + name='account', + field=models.CharField(blank=True, max_length=64, verbose_name='钉钉账号(手机)'), + ), + migrations.AlterField( + model_name='dinguser', + name='uid', + field=models.CharField(blank=True, max_length=255, verbose_name='员工在企业内的唯一标识'), + ), + ] diff --git a/oneid_meta/models/user.py b/oneid_meta/models/user.py index 7c0437bd5..4ea114208 100644 --- a/oneid_meta/models/user.py +++ b/oneid_meta/models/user.py @@ -506,8 +506,8 @@ class DingUser(BaseModel): 钉钉用户 ''' user = models.OneToOneField(User, verbose_name='用户', related_name='ding_user', on_delete=models.PROTECT) - account = models.CharField(max_length=64, blank=False, verbose_name='钉钉账号(手机)') - uid = models.CharField(max_length=255, blank=False, verbose_name='员工在企业内的唯一标识') + account = models.CharField(max_length=64, blank=True, verbose_name='钉钉账号(手机)') + uid = models.CharField(max_length=255, blank=True, verbose_name='员工在企业内的唯一标识') data = models.TextField(blank=True, default='{}', verbose_name='钉钉员工详细数据(JSON)') ding_id = models.TextField(max_length=255, blank=True, verbose_name='钉钉ID') open_id = models.TextField(max_length=255, blank=True, verbose_name='用户在当前开放应用内的唯一标识') diff --git a/siteapi/v1/tests/test_ding.py b/siteapi/v1/tests/test_ding.py index ffa9ff07b..809e0fea1 100644 --- a/siteapi/v1/tests/test_ding.py +++ b/siteapi/v1/tests/test_ding.py @@ -115,6 +115,33 @@ def test_ding_register_bind(self, mock_clear_sms_token, mock_check_sms_token): self.assertEqual(res.status_code, 201) self.assertIn('token', res.json()) + @mock.patch('siteapi.v1.serializers.ucenter.SMSClaimSerializer.check_sms_token') + @mock.patch('siteapi.v1.serializers.ucenter.SMSClaimSerializer.clear_sms_token') + def test_patch_name(self, mock_clear_sms_token, mock_check_sms_token): + client = self.client + mock_clear_sms_token.return_value = True + mock_check_sms_token.side_effect = [{'mobile': '18812341234'}] + res = client.post(reverse('siteapi:ding_register_bind'), + data={ + 'username': 'username', + 'password': 'password', + 'sms_token': 'test_sms_token', + 'user_id': 'test_ding_id' + }) + patch_data = { + 'username': 'username', + 'name': 'new_name', + 'ding_usre': { + 'account': "", + 'uid': "", + 'data': "{}" + }, + } + res = client.json_patch(reverse('siteapi:user_detail', args=('username', )), patch_data) + self.assertEqual(res.status_code, 200) + res = res.json()['user'] + self.assertIn('new_name', res['name']) + def test_ding_qr_register_forbidden(self): client = self.client account_config = AccountConfig.get_current()