fix: sync Huihui app user homepage profile
This commit was merged in pull request #1.
This commit is contained in:
@@ -32,11 +32,16 @@ class _Client:
|
||||
self.__class__.calls.append(("PATCH", url, kwargs))
|
||||
return self.__class__.responses.pop(0)
|
||||
|
||||
async def get(self, url, **kwargs):
|
||||
self.__class__.calls.append(("GET", url, kwargs))
|
||||
return self.__class__.responses.pop(0)
|
||||
|
||||
|
||||
class HuihuiProfileSyncTests(unittest.IsolatedAsyncioTestCase):
|
||||
async def asyncSetUp(self):
|
||||
self.service = NewsPlatformService()
|
||||
self.service._auth_url = AsyncMock(return_value="https://99hui.com/api/usercenter")
|
||||
self.service._biz_url = AsyncMock(return_value="https://99hui.com/api/huihuibusiness")
|
||||
self.service._client = AsyncMock(return_value={
|
||||
"appId": "app", "accessId": "access", "accessSecret": "secret",
|
||||
"clientCode": "", "orgId": "",
|
||||
@@ -48,12 +53,20 @@ class HuihuiProfileSyncTests(unittest.IsolatedAsyncioTestCase):
|
||||
)
|
||||
_Client.calls = []
|
||||
|
||||
async def test_updates_current_profile_and_public_page(self):
|
||||
async def test_updates_all_profiles_and_verifies_app_home(self):
|
||||
_Client.responses = [
|
||||
_Response({"code": 0, "data": True}),
|
||||
_Response({"code": 0, "data": True}),
|
||||
_Response({"code": 0, "data": {
|
||||
"id": "extend-51", "userId": "platform-51", "name": "", "avatar": "",
|
||||
}}),
|
||||
_Response({"code": 0, "data": None}),
|
||||
_Response({"code": 0, "data": {
|
||||
"id": "extend-51", "userId": "platform-51", "name": "黎佳怡",
|
||||
"avatar": "https://img/avatar.jpg",
|
||||
}}),
|
||||
]
|
||||
session = {"token": "token", "platform_uid": "platform-51"}
|
||||
session = {"token": "token", "platform_uid": "platform-51", "org_id": "org-1"}
|
||||
with patch("app.services.news_service.get_session", AsyncMock(return_value=session)), \
|
||||
patch("app.services.news_service.httpx.AsyncClient", _Client):
|
||||
ok, err = await self.service.update_user_profile(
|
||||
@@ -68,6 +81,20 @@ class HuihuiProfileSyncTests(unittest.IsolatedAsyncioTestCase):
|
||||
public_params = _Client.calls[1][2]["params"]
|
||||
self.assertEqual(public_params["nickName"], "黎佳怡")
|
||||
self.assertEqual(public_params["icon"], "https://img/avatar.jpg")
|
||||
self.assertEqual(_Client.calls[2][0], "GET")
|
||||
self.assertEqual(
|
||||
_Client.calls[2][1],
|
||||
"https://99hui.com/api/huihuiuserextend/user/home/platform-51",
|
||||
)
|
||||
self.assertEqual(_Client.calls[3][0], "PATCH")
|
||||
self.assertEqual(
|
||||
_Client.calls[3][1],
|
||||
"https://99hui.com/api/huihuiuserextend/user",
|
||||
)
|
||||
self.assertEqual(_Client.calls[3][2]["json"]["id"], "extend-51")
|
||||
self.assertEqual(_Client.calls[3][2]["json"]["name"], "黎佳怡")
|
||||
self.assertEqual(_Client.calls[3][2]["json"]["avatar"], "https://img/avatar.jpg")
|
||||
self.assertEqual(_Client.calls[4][0], "GET")
|
||||
self.db.commit.assert_awaited_once()
|
||||
|
||||
async def test_public_page_failure_is_not_reported_as_success(self):
|
||||
@@ -87,6 +114,30 @@ class HuihuiProfileSyncTests(unittest.IsolatedAsyncioTestCase):
|
||||
self.assertIn("TA的主页同步失败", err)
|
||||
self.db.commit.assert_not_awaited()
|
||||
|
||||
async def test_app_home_mismatch_is_not_reported_as_success(self):
|
||||
_Client.responses = [
|
||||
_Response({"code": 0, "data": True}),
|
||||
_Response({"code": 0, "data": True}),
|
||||
_Response({"code": 0, "data": {
|
||||
"id": "extend-51", "userId": "platform-51", "name": "", "avatar": "",
|
||||
}}),
|
||||
_Response({"code": 0, "data": None}),
|
||||
_Response({"code": 0, "data": {
|
||||
"id": "extend-51", "userId": "platform-51", "name": "", "avatar": "",
|
||||
}}),
|
||||
]
|
||||
session = {"token": "token", "platform_uid": "platform-51", "org_id": "org-1"}
|
||||
with patch("app.services.news_service.get_session", AsyncMock(return_value=session)), \
|
||||
patch("app.services.news_service.httpx.AsyncClient", _Client):
|
||||
ok, err = await self.service.update_user_profile(
|
||||
self.db, self.user,
|
||||
nick_name="黎佳怡", avatar="https://img/avatar.jpg",
|
||||
)
|
||||
|
||||
self.assertFalse(ok)
|
||||
self.assertIn("App用户主页同步失败", err)
|
||||
self.db.commit.assert_not_awaited()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user