Skip to content

Commit 660f164

Browse files
Fix unittests on connection and message service
1 parent 5303106 commit 660f164

6 files changed

Lines changed: 37 additions & 37 deletions

File tree

symphony/bdk/core/service/connection/connection_service.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import List
2+
13
from symphony.bdk.core.auth.auth_session import AuthSession
24
from symphony.bdk.core.config.model.bdk_retry_config import BdkRetryConfig
35
from symphony.bdk.core.retry import retry
@@ -42,8 +44,8 @@ async def get_connection(self, user_id: int) -> UserConnection:
4244

4345
@retry
4446
async def list_connections(
45-
self, status: ConnectionStatus = ConnectionStatus.ALL, user_ids: [int] = None
46-
) -> [UserConnection]:
47+
self, status: ConnectionStatus = ConnectionStatus.ALL, user_ids: List[int] = None
48+
) -> List[UserConnection]:
4749
"""
4850
List all connection statuses of the requesting user with external or specified users.
4951
See: `List Connections <https://developers.symphony.com/restapi/reference/list-connections>`_
@@ -64,7 +66,7 @@ async def list_connections(
6466
params["user_ids"] = ",".join(map(str, user_ids))
6567

6668
user_connection_list = await self._connection_api.v1_connection_list_get(**params)
67-
return user_connection_list.value
69+
return user_connection_list
6870

6971
@retry
7072
async def create_connection(self, user_id: int) -> UserConnection:

symphony/bdk/core/service/message/message_service.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from symphony.bdk.gen.agent_model.v4_message_blast_response import (
1717
V4MessageBlastResponse,
1818
)
19-
from symphony.bdk.gen.agent_model.v4_message_import_list import V4MessageImportList
2019
from symphony.bdk.gen.pod_api.default_api import DefaultApi
2120
from symphony.bdk.gen.pod_api.message_api import MessageApi
2221
from symphony.bdk.gen.pod_api.message_suppression_api import MessageSuppressionApi
@@ -201,7 +200,7 @@ async def get_attachment_types(self) -> List[str]:
201200
"""
202201
params = {"session_token": await self._auth_session.session_token}
203202
type_list = await self._pod_api.v1_files_allowed_types_get(**params)
204-
return type_list.value
203+
return type_list
205204

206205
async def blast_message(
207206
self,
@@ -307,8 +306,8 @@ def __init__(
307306
@retry
308307
async def list_messages(
309308
self, stream_id: str, since: int = 0, skip: int = 0, limit: int = 50
310-
) -> [V4Message]:
311-
"""Get messages from an existing stream. Additionally returns any attachments associated with the message.
309+
) -> List[V4Message]:
310+
"""Get messages from an existing stream. Additionally, returns any attachments associated with the message.
312311
See: `Messages <https://developers.symphony.com/restapi/reference/messages-v4>`_
313312
314313
:param stream_id: The stream where to look for messages
@@ -328,10 +327,10 @@ async def list_messages(
328327
"limit": limit,
329328
}
330329
message_list = await self._messages_api.v4_stream_sid_message_get(**params)
331-
return message_list.value
330+
return message_list
332331

333332
@retry
334-
async def import_messages(self, messages: List[V4ImportedMessage]) -> [V4ImportResponse]:
333+
async def import_messages(self, messages: List[V4ImportedMessage]) -> List[V4ImportResponse]:
335334
"""Imports a list of messages to Symphony.
336335
See: `Import Message <https://developers.symphony.com/restapi/reference/import-message-v4>`_
337336
@@ -341,12 +340,12 @@ async def import_messages(self, messages: List[V4ImportedMessage]) -> [V4ImportR
341340
342341
"""
343342
params = {
344-
"message_list": V4MessageImportList(value=messages),
343+
"message_list": messages,
345344
"session_token": await self._auth_session.session_token,
346345
"key_manager_token": await self._auth_session.key_manager_token,
347346
}
348347
import_response_list = await self._messages_api.v4_message_import_post(**params)
349-
return import_response_list.value
348+
return import_response_list
350349

351350
async def get_attachment(self, stream_id: str, message_id: str, attachment_id: str) -> str:
352351
"""Downloads the attachment body by the stream ID, message ID and attachment ID.
@@ -434,7 +433,7 @@ async def list_attachments(
434433
if to is not None:
435434
params["to"] = to
436435
attachment_list = await self._streams_api.v1_streams_sid_attachments_get(**params)
437-
return attachment_list.value
436+
return attachment_list
438437

439438
@retry
440439
async def list_message_receipts(self, message_id: str) -> MessageReceiptDetailResponse:
@@ -501,7 +500,7 @@ async def search_messages(
501500
"limit": limit,
502501
}
503502
message_list = await self._messages_api.v1_message_search_post(**params)
504-
return message_list.value # endpoint returns empty list when no values found
503+
return message_list
505504

506505
async def search_all_messages(
507506
self,

tests/bdk/gen/rest_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ async def test_system_certs_are_loaded():
88
rest_client = rest.RESTClientObject(Configuration())
99

1010
# Calling an URL with a valid HTTPS cert
11-
response = await rest_client.GET("https://google.fr")
11+
response = await rest_client.request("GET", "https://google.fr")
1212

1313
assert response.status == 200

tests/core/service/connection/connection_service_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from typing import List
12
from unittest.mock import AsyncMock, MagicMock
23

34
import pytest
@@ -7,7 +8,6 @@
78
from symphony.bdk.core.service.connection.model.connection_status import ConnectionStatus
89
from symphony.bdk.gen.pod_api.connection_api import ConnectionApi
910
from symphony.bdk.gen.pod_model.user_connection import UserConnection
10-
from symphony.bdk.gen.pod_model.user_connection_list import UserConnectionList
1111
from symphony.bdk.gen.pod_model.user_connection_request import UserConnectionRequest
1212
from tests.core.config import minimal_retry_config
1313
from tests.utils.resource_utils import deserialize_object
@@ -52,7 +52,7 @@ async def test_get_connection(connection_api, connection_service):
5252
async def test_list_connections(connection_api, connection_service):
5353
connection_api.v1_connection_list_get = AsyncMock()
5454
connection_api.v1_connection_list_get.return_value = deserialize_object(
55-
UserConnectionList,
55+
List[UserConnection],
5656
"["
5757
" {"
5858
' "userId": 7078106126503,'

tests/core/service/message/message_service_test.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
from typing import List
23
from unittest.mock import AsyncMock, MagicMock
34

45
import pytest
@@ -11,11 +12,10 @@
1112
)
1213
from symphony.bdk.gen.agent_api.attachments_api import AttachmentsApi
1314
from symphony.bdk.gen.agent_model.message_search_query import MessageSearchQuery
14-
from symphony.bdk.gen.agent_model.v4_import_response_list import V4ImportResponseList
15+
from symphony.bdk.gen.agent_model.v4_import_response import V4ImportResponse
1516
from symphony.bdk.gen.agent_model.v4_imported_message import V4ImportedMessage
1617
from symphony.bdk.gen.agent_model.v4_message import V4Message
1718
from symphony.bdk.gen.agent_model.v4_message_blast_response import V4MessageBlastResponse
18-
from symphony.bdk.gen.agent_model.v4_message_list import V4MessageList
1919
from symphony.bdk.gen.api_client import ApiClient, Configuration
2020
from symphony.bdk.gen.pod_api.default_api import DefaultApi
2121
from symphony.bdk.gen.pod_api.message_api import MessageApi
@@ -26,8 +26,7 @@
2626
from symphony.bdk.gen.pod_model.message_receipt_detail_response import MessageReceiptDetailResponse
2727
from symphony.bdk.gen.pod_model.message_status import MessageStatus
2828
from symphony.bdk.gen.pod_model.message_suppression_response import MessageSuppressionResponse
29-
from symphony.bdk.gen.pod_model.stream_attachment_response import StreamAttachmentResponse
30-
from symphony.bdk.gen.pod_model.string_list import StringList
29+
from symphony.bdk.gen.pod_model.stream_attachment_item import StreamAttachmentItem
3130
from tests.core.config import minimal_retry_config
3231
from tests.utils.resource_utils import deserialize_object, get_deserialized_object_from_resource
3332

@@ -67,7 +66,7 @@ def fixture_message_service(mocked_api_client, auth_session):
6766
@pytest.mark.asyncio
6867
async def test_list_messages(mocked_api_client, message_service):
6968
mocked_api_client.call_api.return_value = get_deserialized_object_from_resource(
70-
V4MessageList, "message_response/list_messages.json"
69+
List[V4Message], "message_response/list_messages.json"
7170
)
7271
messages_list = await message_service.list_messages("stream_id")
7372

@@ -247,7 +246,7 @@ async def test_blast_complex_message(message_service):
247246
@pytest.mark.asyncio
248247
async def test_import_message(mocked_api_client, message_service):
249248
mocked_api_client.call_api.return_value = deserialize_object(
250-
V4ImportResponseList,
249+
List[V4ImportResponse],
251250
"["
252251
" {"
253252
' "messageId": "FjSY1y3L", '
@@ -310,7 +309,7 @@ async def test_get_message_status(mocked_api_client, message_service):
310309
@pytest.mark.asyncio
311310
async def test_get_attachment_types(mocked_api_client, message_service):
312311
mocked_api_client.call_api.return_value = deserialize_object(
313-
StringList, '[ ".bmp", ".doc", ".png", ".mpeg"]'
312+
List[str], '[ ".bmp", ".doc", ".png", ".mpeg"]'
314313
)
315314

316315
attachment_types = await message_service.get_attachment_types()
@@ -335,7 +334,7 @@ async def test_get_message(mocked_api_client, message_service):
335334
@pytest.mark.asyncio
336335
async def test_list_attachments(mocked_api_client, message_service):
337336
mocked_api_client.call_api.return_value = get_deserialized_object_from_resource(
338-
StreamAttachmentResponse, "message_response/list_attachments.json"
337+
List[StreamAttachmentItem], "message_response/list_attachments.json"
339338
)
340339

341340
attachments = await message_service.list_attachments("stream_id")
@@ -376,7 +375,7 @@ async def test_get_message_relationships(mocked_api_client, message_service):
376375
@pytest.mark.asyncio
377376
async def test_search_messages_with_hashtag(mocked_api_client, message_service):
378377
mocked_api_client.call_api.return_value = get_deserialized_object_from_resource(
379-
V4MessageList, "message_response/list_messages.json"
378+
List[V4Message], "message_response/list_messages.json"
380379
)
381380

382381
messages = await message_service.search_messages(MessageSearchQuery(hashtag="tag"))
@@ -390,7 +389,7 @@ async def test_search_messages_with_valid_stream_type(
390389
mocked_api_client, message_service, stream_type
391390
):
392391
mocked_api_client.call_api.return_value = get_deserialized_object_from_resource(
393-
V4MessageList, "message_response/list_messages.json"
392+
List[V4Message], "message_response/list_messages.json"
394393
)
395394

396395
messages = await message_service.search_messages(MessageSearchQuery(stream_type=stream_type))
@@ -401,7 +400,7 @@ async def test_search_messages_with_valid_stream_type(
401400
@pytest.mark.asyncio
402401
async def test_search_messages_with_invalid_stream_type(mocked_api_client, message_service):
403402
mocked_api_client.call_api.return_value = get_deserialized_object_from_resource(
404-
V4MessageList, "message_response/list_messages.json"
403+
List[V4Message], "message_response/list_messages.json"
405404
)
406405

407406
with pytest.raises(ValueError):
@@ -411,7 +410,7 @@ async def test_search_messages_with_invalid_stream_type(mocked_api_client, messa
411410
@pytest.mark.asyncio
412411
async def test_search_messages_with_text_and_sid(mocked_api_client, message_service):
413412
mocked_api_client.call_api.return_value = get_deserialized_object_from_resource(
414-
V4MessageList, "message_response/list_messages.json"
413+
List[V4Message], "message_response/list_messages.json"
415414
)
416415

417416
messages = await message_service.search_messages(
@@ -424,7 +423,7 @@ async def test_search_messages_with_text_and_sid(mocked_api_client, message_serv
424423
@pytest.mark.asyncio
425424
async def test_search_messages_with_text_and_no_sid(mocked_api_client, message_service):
426425
mocked_api_client.call_api.return_value = get_deserialized_object_from_resource(
427-
V4MessageList, "message_response/list_messages.json"
426+
List[V4Message], "message_response/list_messages.json"
428427
)
429428

430429
with pytest.raises(ValueError):
@@ -437,7 +436,7 @@ async def test_search_messages_with_stream_type_text_and_sid(
437436
mocked_api_client, message_service, stream_type
438437
):
439438
mocked_api_client.call_api.return_value = get_deserialized_object_from_resource(
440-
V4MessageList, "message_response/list_messages.json"
439+
List[V4Message], "message_response/list_messages.json"
441440
)
442441

443442
messages = await message_service.search_messages(
@@ -453,7 +452,7 @@ async def test_search_messages_with_stream_type_text_and_no_sid(
453452
mocked_api_client, message_service, stream_type
454453
):
455454
mocked_api_client.call_api.return_value = get_deserialized_object_from_resource(
456-
V4MessageList, "message_response/list_messages.json"
455+
List[V4Message], "message_response/list_messages.json"
457456
)
458457

459458
with pytest.raises(ValueError):
@@ -465,8 +464,8 @@ async def test_search_messages_with_stream_type_text_and_no_sid(
465464
@pytest.mark.asyncio
466465
async def test_search_all_messages(mocked_api_client, message_service):
467466
mocked_api_client.call_api.side_effect = [
468-
get_deserialized_object_from_resource(V4MessageList, "message_response/list_messages.json"),
469-
V4MessageList(value=[]),
467+
get_deserialized_object_from_resource(List[V4Message], "message_response/list_messages.json"),
468+
[],
470469
]
471470
chunk_size = 1
472471

tests/resources/session/get_session.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"id": 7696581394433,
3-
"email_address": "admin@symphony.com",
4-
"first_name": "Symphony",
5-
"last_name": "Admin",
6-
"display_name": "Symphony Admin",
3+
"emailAddress": "admin@symphony.com",
4+
"firstName": "Symphony",
5+
"lastName": "Admin",
6+
"displayName": "Symphony Admin",
77
"title": "Administrator",
88
"company": "Acme",
99
"username": "admin@symphony.com",

0 commit comments

Comments
 (0)