-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add DataSourceDepartmentSyncer unittest
- Loading branch information
Showing
10 changed files
with
348 additions
and
51 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
src/bk-user/bkuser/apps/sync/migrations/0003_auto_20230917_2026.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Generated by Django 3.2.20 on 2023-09-17 12:26 | ||
|
||
import datetime | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('sync', '0002_auto_20230913_1626'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='datasourcesynctask', | ||
name='duration', | ||
field=models.DurationField(default=datetime.timedelta(0), verbose_name='任务持续时间'), | ||
), | ||
migrations.AlterField( | ||
model_name='datasourcesynctask', | ||
name='start_time', | ||
field=models.DateTimeField(auto_now_add=True, verbose_name='任务开始时间'), | ||
), | ||
migrations.AlterField( | ||
model_name='tenantsynctask', | ||
name='duration', | ||
field=models.DurationField(default=datetime.timedelta(0), verbose_name='任务持续时间'), | ||
), | ||
migrations.AlterField( | ||
model_name='tenantsynctask', | ||
name='start_time', | ||
field=models.DateTimeField(auto_now_add=True, verbose_name='任务开始时间'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,221 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-用户管理(Bk-User) available. | ||
Copyright (C) 2017-2021 THL A29 Limited, a Tencent company. All rights reserved. | ||
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at http://opensource.org/licenses/MIT | ||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations under the License. | ||
""" | ||
from typing import List | ||
|
||
import pytest | ||
from bkuser.apps.sync.constants import SyncTaskStatus, SyncTaskTrigger | ||
from bkuser.apps.sync.models import DataSourceSyncTask, TenantSyncTask | ||
from bkuser.plugins.models import RawDataSourceDepartment, RawDataSourceUser | ||
from django.utils import timezone | ||
|
||
|
||
@pytest.fixture() | ||
def data_source_sync_task(bare_local_data_source) -> DataSourceSyncTask: | ||
"""数据源同步任务""" | ||
return DataSourceSyncTask.objects.create( | ||
data_source_id=bare_local_data_source.id, | ||
status=SyncTaskStatus.PENDING, | ||
trigger=SyncTaskTrigger.MANUAL, | ||
operator="admin", | ||
start_time=timezone.now(), | ||
extra={"overwrite": True, "async_run": False}, | ||
) | ||
|
||
|
||
@pytest.fixture() | ||
def tenant_sync_task(bare_local_data_source, default_tenant) -> TenantSyncTask: | ||
"""租户数据同步任务""" | ||
return TenantSyncTask( | ||
tenant_id=default_tenant.id, | ||
data_source_id=bare_local_data_source.id, | ||
status=SyncTaskStatus.PENDING, | ||
trigger=SyncTaskTrigger.MANUAL, | ||
operator="admin", | ||
start_time=timezone.now(), | ||
extra={"async_run": False}, | ||
) | ||
|
||
|
||
@pytest.fixture() | ||
def raw_departments() -> List[RawDataSourceDepartment]: | ||
"""数据源插件提供的原始部门信息""" | ||
return [ | ||
RawDataSourceDepartment(code="company", name="公司", parent=None), | ||
RawDataSourceDepartment(code="dept_a", name="部门A", parent="company"), | ||
RawDataSourceDepartment(code="dept_b", name="部门B", parent="company"), | ||
RawDataSourceDepartment(code="center_aa", name="中心AA", parent="dept_a"), | ||
RawDataSourceDepartment(code="center_ab", name="中心AB", parent="dept_a"), | ||
RawDataSourceDepartment(code="center_ba", name="中心BA", parent="dept_b"), | ||
RawDataSourceDepartment(code="group_aaa", name="小组AAA", parent="center_aa"), | ||
RawDataSourceDepartment(code="group_aba", name="小组ABA", parent="center_ab"), | ||
RawDataSourceDepartment(code="group_baa", name="小组BAA", parent="center_ba"), | ||
RawDataSourceDepartment(code="v", name="V", parent=None), | ||
] | ||
|
||
|
||
def raw_users() -> List[RawDataSourceUser]: | ||
"""数据源插件提供的原始用户信息""" | ||
return [ | ||
RawDataSourceUser( | ||
code="Employee-3", | ||
properties={ | ||
"username": "zhangsan", | ||
"full_name": "张三", | ||
"email": "[email protected]", | ||
"phone": "13512345671", | ||
"age": "18", | ||
"gender": "male", | ||
"region": "beijing", | ||
}, | ||
leaders=[], | ||
departments=["company"], | ||
), | ||
RawDataSourceUser( | ||
code="Employee-4", | ||
properties={ | ||
"username": "lisi", | ||
"full_name": "李四", | ||
"email": "[email protected]", | ||
"phone": "13512345672", | ||
"age": "28", | ||
"gender": "female", | ||
"region": "shanghai", | ||
}, | ||
leaders=["zhangsan"], | ||
departments=["dept_a", "center_aa"], | ||
), | ||
RawDataSourceUser( | ||
code="Employee-5", | ||
properties={ | ||
"username": "wangwu", | ||
"full_name": "王五", | ||
"email": "[email protected]", | ||
"phone": "13512345673", | ||
"age": "38", | ||
"gender": "male", | ||
"region": "shenzhen", | ||
}, | ||
leaders=["zhangsan"], | ||
departments=["dept_a", "dept_b"], | ||
), | ||
RawDataSourceUser( | ||
code="Employee-6", | ||
properties={ | ||
"username": "zhaoliu", | ||
"full_name": "赵六", | ||
"email": "[email protected]", | ||
"phone": "13512345674", | ||
"age": "33", | ||
"gender": "female", | ||
"region": "tianjin", | ||
}, | ||
leaders=["lisi"], | ||
departments=["center_aa"], | ||
), | ||
RawDataSourceUser( | ||
code="Employee-7", | ||
properties={ | ||
"username": "liuqi", | ||
"full_name": "柳七", | ||
"email": "[email protected]", | ||
"phone": "13512345675", | ||
"age": "25", | ||
"gender": "female", | ||
"region": "jiangxi", | ||
}, | ||
leaders=["zhaoliu"], | ||
departments=["group_aaa"], | ||
), | ||
RawDataSourceUser( | ||
code="Employee-8", | ||
properties={ | ||
"username": "maiba", | ||
"full_name": "麦八", | ||
"email": "[email protected]", | ||
"phone": "13512345676", | ||
"age": "35", | ||
"gender": "male", | ||
"region": "xinjiang", | ||
}, | ||
leaders=["lisi", "wangwu"], | ||
departments=["center_ab"], | ||
), | ||
RawDataSourceUser( | ||
code="Employee-9", | ||
properties={ | ||
"username": "yangjiu", | ||
"full_name": "杨九", | ||
"email": "[email protected]", | ||
"phone": "13512345677", | ||
"age": "40", | ||
"gender": "male", | ||
"region": "guangdong", | ||
}, | ||
leaders=["wangwu"], | ||
departments=["center_ab"], | ||
), | ||
RawDataSourceUser( | ||
code="Employee-10", | ||
properties={ | ||
"username": "lushi", | ||
"full_name": "鲁十", | ||
"email": "[email protected]", | ||
"phone": "13512345678", | ||
"age": "50", | ||
"gender": "male", | ||
"region": "jiangsu", | ||
}, | ||
leaders=["maiba", "wangwu"], | ||
departments=["group_aba", "center_ba"], | ||
), | ||
RawDataSourceUser( | ||
code="Employee-11", | ||
properties={ | ||
"username": "linshiyi", | ||
"full_name": "林十一", | ||
"email": "[email protected]", | ||
"phone": "13512345679", | ||
"age": "31", | ||
"gender": "male", | ||
"region": "hunan", | ||
}, | ||
leaders=["lushi"], | ||
departments=["group_aba"], | ||
), | ||
RawDataSourceUser( | ||
code="Employee-12", | ||
properties={ | ||
"username": "baishier", | ||
"full_name": "白十二", | ||
"email": "[email protected]", | ||
"phone": "13512345670", | ||
"age": "30", | ||
"gender": "female", | ||
"region": "guangdong", | ||
}, | ||
leaders=["lushi"], | ||
departments=["group_baa"], | ||
), | ||
RawDataSourceUser( | ||
code="Employee-666", | ||
properties={ | ||
"username": "freedom", | ||
"full_name": "自由人", | ||
"email": "[email protected]", | ||
"phone": "1351234567X", | ||
"age": "999", | ||
"gender": "other", | ||
"region": "solar system", | ||
}, | ||
leaders=[], | ||
departments=[], | ||
), | ||
] |
Oops, something went wrong.