refactor(backend): dify, minio等迁移到integration,清除无效文件

This commit is contained in:
sophie committed 2026-09-21 09:24:45 +08:00
1 parent 7fe7a39384
commit faa554ade4
90 files changed
+7540 -9649

No files matched your search

+211 -106
View File
@@ -1,106 +1,211 @@
"""Tests for OA userInfo_view → wecom_userid sync."""␍
␍
from unittest.mock import patch␍
␍
import pytest␍
␍
from app.models import User␍
from app.services.oa_wecom_sync import sync_wecom_userids_from_oa␍
␍
␍
@pytest.fixture␍
def oa_rows_for_local_user():␍
return [␍
{'workcode': '26030025', 'wecom_userid': '21784', 'name': 'sophie'},␍
]␍
␍
␍
def test_sync_wecom_userids_from_oa_dry_run(app, oa_rows_for_local_user):␍
with app.app_context():␍
user = User(␍
username='26030025',␍
email='26030025@test.local',␍
employee_id='26030025',␍
real_name='sophie',␍
role='user',␍
status='active',␍
)␍
user.set_password('test123')␍
from app import db␍
␍
db.session.add(user)␍
db.session.commit()␍
␍
with patch(␍
'app.services.oa_wecom_sync.fetch_oa_wecom_bindings_for_workcodes',␍
return_value=oa_rows_for_local_user,␍
) as fetch_mock:␍
summary = sync_wecom_userids_from_oa(apply=False)␍
␍
fetch_mock.assert_called_once_with(['26030025'])␍
assert summary['local_candidates'] == 1␍
assert summary['wecom_users'] == 1␍
assert summary['local_matched'] == 1␍
assert summary['would_update'] == 1␍
assert summary['local_missing'] == 0␍
assert summary['pending_updates'][0]['wecom_userid'] == '21784'␍
␍
db.session.refresh(user)␍
assert user.wecom_userid is None␍
␍
␍
def test_sync_wecom_userids_from_oa_apply(app, oa_rows_for_local_user):␍
with app.app_context():␍
user = User(␍
username='26030025',␍
email='26030025@test.local',␍
employee_id='26030025',␍
real_name='sophie',␍
role='user',␍
status='active',␍
)␍
user.set_password('test123')␍
from app import db␍
␍
db.session.add(user)␍
db.session.commit()␍
␍
with patch(␍
'app.services.oa_wecom_sync.fetch_oa_wecom_bindings_for_workcodes',␍
return_value=oa_rows_for_local_user,␍
):␍
summary = sync_wecom_userids_from_oa(apply=True)␍
␍
assert summary['updated'] == 1␍
db.session.refresh(user)␍
assert user.wecom_userid == '21784'␍
␍
␍
def test_sync_wecom_userids_from_oa_local_not_in_oa(app):␍
with app.app_context():␍
user = User(␍
username='missing_oa',␍
email='missing_oa@test.local',␍
employee_id='99999999',␍
real_name='missing',␍
role='user',␍
status='active',␍
)␍
user.set_password('test123')␍
from app import db␍
␍
db.session.add(user)␍
db.session.commit()␍
␍
with patch(␍
'app.services.oa_wecom_sync.fetch_oa_wecom_bindings_for_workcodes',␍
return_value=[],␍
) as fetch_mock:␍
summary = sync_wecom_userids_from_oa(apply=False)␍
␍
fetch_mock.assert_called_once_with(['99999999'])␍
assert summary['local_candidates'] == 1␍
assert summary['wecom_users'] == 0␍
assert summary['local_matched'] == 0␍
assert summary['local_missing'] == 1␍
␍
"""Tests for OA userInfo_view → wecom_userid sync."""
from unittest.mock import patch
import pytest
from app.models import User
from app.services.integrations.oa.wecom_sync import sync_wecom_userids_from_oa
@pytest.fixture
def oa_rows_for_local_user():
return [
{'workcode': '26030025', 'wecom_userid': '21784', 'name': 'sophie'},
]
def test_sync_wecom_userids_from_oa_dry_run(app, oa_rows_for_local_user):
with app.app_context():
user = User(
username='26030025',
email='26030025@test.local',
employee_id='26030025',
real_name='sophie',
role='user',
status='active',
)
user.set_password('test123')
from app import db
db.session.add(user)
db.session.commit()
with patch(
'app.services.integrations.oa.wecom_sync.fetch_oa_wecom_bindings_for_workcodes',
return_value=oa_rows_for_local_user,
) as fetch_mock:
summary = sync_wecom_userids_from_oa(apply=False)
fetch_mock.assert_called_once_with(['26030025'])
assert summary['local_candidates'] == 1
assert summary['wecom_users'] == 1
assert summary['local_matched'] == 1
assert summary['would_update'] == 1
assert summary['local_missing'] == 0
assert summary['pending_updates'][0]['wecom_userid'] == '21784'
db.session.refresh(user)
assert user.wecom_userid is None
def test_sync_wecom_userids_from_oa_apply(app, oa_rows_for_local_user):
with app.app_context():
user = User(
username='26030025',
email='26030025@test.local',
employee_id='26030025',
real_name='sophie',
role='user',
status='active',
)
user.set_password('test123')
from app import db
db.session.add(user)
db.session.commit()
with patch(
'app.services.integrations.oa.wecom_sync.fetch_oa_wecom_bindings_for_workcodes',
return_value=oa_rows_for_local_user,
):
summary = sync_wecom_userids_from_oa(apply=True)
assert summary['updated'] == 1
db.session.refresh(user)
assert user.wecom_userid == '21784'
def test_sync_wecom_userids_from_oa_local_not_in_oa(app):
with app.app_context():
user = User(
username='missing_oa',
email='missing_oa@test.local',
employee_id='99999999',
real_name='missing',
role='user',
status='active',
)
user.set_password('test123')
from app import db
db.session.add(user)
db.session.commit()
with patch(
'app.services.integrations.oa.wecom_sync.fetch_oa_wecom_bindings_for_workcodes',
return_value=[],
) as fetch_mock:
summary = sync_wecom_userids_from_oa(apply=False)
fetch_mock.assert_called_once_with(['99999999'])
assert summary['local_candidates'] == 1
assert summary['wecom_users'] == 0
assert summary['local_matched'] == 0
assert summary['local_missing'] == 1