diff --git a/src/bk-user/tests/biz/test_data_source.py b/src/bk-user/tests/biz/test_data_source.py index de872431e..bcf3d9f3e 100644 --- a/src/bk-user/tests/biz/test_data_source.py +++ b/src/bk-user/tests/biz/test_data_source.py @@ -66,11 +66,11 @@ def test_get_user_department_ids_map( for user_id in user_ids: department_ids = user_department_relationship_map.get(user_id) assert department_ids - assert list(department_ids) == list( - DataSourceDepartmentUserRelation.objects.filter(user_id=user_id).values_list( - "department_id", flat=True - ) + real_department_ids = DataSourceDepartmentUserRelation.objects.filter(user_id=user_id).values_list( + "department_id", flat=True ) + for department_id in department_ids: + assert department_id in real_department_ids @pytest.mark.parametrize( "not_exist_data_source_user_ids", @@ -92,13 +92,14 @@ def test_get_user_leader_ids_map(self, local_data_source_users: List[DataSourceU leader_ids_map = DataSourceUserHandler.get_user_leader_ids_map(data_source_user_ids) for user_id in data_source_user_ids: - leader_ids = leader_ids_map.get(user_id) + leader_ids = leader_ids_map.get(user_id) or [] if not DataSourceUserLeaderRelation.objects.filter(user_id=user_id): assert not leader_ids else: - assert leader_ids == list( - DataSourceUserLeaderRelation.objects.filter(user_id=user_id).values_list("leader_id", flat=True) - ) + for leader_id in leader_ids: + assert leader_id in DataSourceUserLeaderRelation.objects.filter(user_id=user_id).values_list( + "leader_id", flat=True + ) @pytest.mark.parametrize( "not_exist_data_source_user_ids", diff --git a/src/bk-user/tests/biz/test_tenant.py b/src/bk-user/tests/biz/test_tenant.py index 1b7f164d6..eb1a955d9 100644 --- a/src/bk-user/tests/biz/test_tenant.py +++ b/src/bk-user/tests/biz/test_tenant.py @@ -37,7 +37,8 @@ def test_get_tenant_user_leaders_map_by_id(self, default_tenant_users: List[Tena tenant_users = TenantUser.objects.filter(data_source_user_id__in=data_source_leader_ids) assert len(tenant_user_leader_ids) == tenant_users.count() - assert not set(tenant_user_leader_ids) - set(tenant_users.values_list("id", flat=True)) + for tenant_leader_id in tenant_user_leader_ids: + assert tenant_leader_id in tenant_users.values_list("id", flat=True) def test_get_tenant_user_departments_map_by_id( self,