Skip to content

Commit 4d8e442

Browse files
Update version to 1.8.7 and enhance ServerResponseParser to return full dictionary for single-element results. Add test for batch response handling in lists.element.add.
Fixes #264
1 parent 5d8e1f4 commit 4d8e442

File tree

4 files changed

+81
-5
lines changed

4 files changed

+81
-5
lines changed

fast_bitrix24/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.8.6"
1+
__version__ = "1.8.7"

fast_bitrix24/server_response.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,10 @@ def extract_from_batch_response(self, result) -> list:
102102

103103
first_item = next(iter(result.values()))
104104

105-
# Если первый элемент - простое значение (не словарь/список),
106-
# возвращаем само значение
105+
# Если первый элемент - простое значение (не словарь/список)
107106
if not isinstance(first_item, (dict, list)):
108-
return first_item
109-
107+
# Если в словаре только один элемент, возвращаем его значение
108+
return first_item if len(result) == 1 else result
110109
# если внутри - списки, то вернуть их в одном плоском списке
111110
if self.is_nested(first_item) or isinstance(first_item, list):
112111
result_list = [
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Реальный ответ сервера для batch запроса lists.element.add
2+
response = {
3+
'result': {
4+
'result': {
5+
'order0000000000': 53,
6+
'order0000000001': 55
7+
},
8+
'result_error': [],
9+
'result_total': [],
10+
'result_next': [],
11+
'result_time': {
12+
'order0000000000': {
13+
'start': 1753131158.036666,
14+
'finish': 1753131158.062972,
15+
'duration': 0.02630615234375,
16+
'processing': 0.02588796615600586,
17+
'date_start': '2025-07-21T23:52:38+03:00',
18+
'date_finish': '2025-07-21T23:52:38+03:00',
19+
'operating_reset_at': 1753131758,
20+
'operating': 0
21+
},
22+
'order0000000001': {
23+
'start': 1753131158.063716,
24+
'finish': 1753131158.071189,
25+
'duration': 0.007472991943359375,
26+
'processing': 0.007107973098754883,
27+
'date_start': '2025-07-21T23:52:38+03:00',
28+
'date_finish': '2025-07-21T23:52:38+03:00',
29+
'operating_reset_at': 1753131758,
30+
'operating': 0
31+
}
32+
}
33+
},
34+
'time': {
35+
'start': 1753131158.015463,
36+
'finish': 1753131158.071819,
37+
'duration': 0.056355953216552734,
38+
'processing': 0.03529095649719238,
39+
'date_start': '2025-07-21T23:52:38+03:00',
40+
'date_finish': '2025-07-21T23:52:38+03:00',
41+
'operating_reset_at': 1753131758,
42+
'operating': 0
43+
}
44+
}

tests/test_server_responses.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,3 +440,36 @@ def test_task_elapseditem_getlist_mixed_types(bx_dummy):
440440
assert isinstance(results["132990"], list)
441441
assert len(results["132990"]) == 1
442442
assert results["132990"][0]["ID"] == "112237"
443+
444+
445+
def test_lists_element_add_batch(bx_dummy):
446+
"""Тест для проверки правильного возвращения списка простых значений в batch ответе.
447+
448+
Проверяет, что при batch-вызове lists.element.add возвращается список всех ID,
449+
а не только первый ID.
450+
"""
451+
from tests.real_responses.lists_element_add_batch import response
452+
453+
bx_dummy.srh = MockSRH(response)
454+
results = bx_dummy.call(
455+
"lists.element.add",
456+
[
457+
{
458+
"IBLOCK_TYPE_ID": "lists",
459+
"IBLOCK_ID": 33,
460+
"ELEMENT_CODE": "1",
461+
"FIELDS": {"NAME": "Тест 1", "PROPERTY_117": "1"}
462+
},
463+
{
464+
"IBLOCK_TYPE_ID": "lists",
465+
"IBLOCK_ID": 33,
466+
"ELEMENT_CODE": "2",
467+
"FIELDS": {"NAME": "Тест 2", "PROPERTY_117": "2"}
468+
}
469+
]
470+
)
471+
472+
# Ожидаем получить кортеж из двух значений (53, 55)
473+
assert isinstance(results, tuple)
474+
assert len(results) == 2
475+
assert results == (53, 55)

0 commit comments

Comments
 (0)