Skip to content

Commit 624394b

Browse files
Fix tests
1 parent 3f38d40 commit 624394b

File tree

5 files changed

+30
-73
lines changed

5 files changed

+30
-73
lines changed

tests/fixtures.py renamed to tests/conftest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55
from fast_bitrix24 import Bitrix, BitrixAsync
66

77

8+
@pytest.fixture(scope='session')
9+
def bx_dummy_async():
10+
return BitrixAsync("https://google.com/path")
11+
12+
13+
@pytest.fixture(scope='session')
14+
def bx_dummy():
15+
return Bitrix("https://google.com/path")
16+
17+
818
@pytest.fixture(scope='session')
919
def get_test():
1020
test_webhook = os.getenv('FAST_BITRIX24_TEST_WEBHOOK')

tests/test_async.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,6 @@
88
from fast_bitrix24 import BitrixAsync
99
from fast_bitrix24.srh import BITRIX_POOL_SIZE, BITRIX_RPS, ServerRequestHandler
1010

11-
from .fixtures import (
12-
create_100_leads,
13-
create_100_leads_async,
14-
create_a_lead,
15-
get_test,
16-
get_test_async,
17-
)
18-
1911

2012
@pytest.mark.skipif(
2113
not os.getenv("FAST_BITRIX24_TEST_WEBHOOK"),

tests/test_helpers.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,6 @@
1-
from fast_bitrix24.server_response import ServerResponseParser
21
from fast_bitrix24.utils import http_build_query
32

43

5-
def test_server_response():
6-
RAW = {
7-
"result": 25,
8-
"time": {
9-
"start": 1649929692.302662,
10-
"finish": 1649929692.547846,
11-
"duration": 0.24518418312072754,
12-
"processing": 0.14425015449523926,
13-
"date_start": "2022-04-14T12:48:12+03:00",
14-
"date_finish": "2022-04-14T12:48:12+03:00",
15-
},
16-
}
17-
assert ServerResponseParser(RAW).result == 25
18-
19-
204
class TestHttpBuildQuery:
215
def test_original(self):
226
assert http_build_query({"alpha": "bravo"}) == "alpha=bravo&"

tests/test_server_responses.py

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,13 @@
22

33
import pytest
44
from beartype.typing import Dict, List, Union
5-
from fast_bitrix24.bitrix import BitrixAsync
65
from fast_bitrix24.logger import logger
76
from fast_bitrix24.server_response import ServerResponseParser
87
from fast_bitrix24.srh import ServerRequestHandler
98

109
logger.addHandler(logging.StreamHandler())
1110

1211

13-
@pytest.fixture
14-
def bitrix():
15-
return BitrixAsync("https://google.com/path")
16-
17-
1812
class MockSRH(ServerRequestHandler):
1913
def __init__(self, response: Union[Dict, List[Dict]]):
2014
self.response = response if isinstance(response, list) else [response]
@@ -39,43 +33,35 @@ def test_single_success():
3933
assert isinstance(results, list)
4034

4135

42-
@pytest.mark.asyncio
43-
async def test_batch_success(bitrix):
44-
from tests.real_responses.crm_lead_list_several_pages_success import \
45-
response
36+
def test_batch_success(bx_dummy):
37+
from tests.real_responses.crm_lead_list_several_pages_success import response
4638

47-
bitrix.srh = MockSRH(response)
48-
results = await bitrix.get_all("crm.lead.list")
39+
bx_dummy.srh = MockSRH(response)
40+
results = bx_dummy.get_all("crm.lead.list")
4941
assert isinstance(results, list)
5042

5143

52-
@pytest.mark.asyncio
53-
async def test_batch_single_page_error(bitrix):
54-
from tests.real_responses.crm_get_batch_mix_success_and_errors import \
55-
response
44+
def test_batch_single_page_error(bx_dummy):
45+
from tests.real_responses.crm_get_batch_mix_success_and_errors import response
5646

57-
bitrix.srh = MockSRH(response)
47+
bx_dummy.srh = MockSRH(response)
5848
with pytest.raises(RuntimeError):
59-
await bitrix.get_by_ID("crm.lead.get", [0, 1, 35943])
49+
bx_dummy.get_by_ID("crm.lead.get", [0, 1, 35943])
6050

6151

62-
@pytest.mark.asyncio
63-
async def test_call_single_success(bitrix):
52+
def test_call_single_success(bx_dummy):
6453
from tests.real_responses.call_single_success import response
6554

66-
bitrix.srh = MockSRH(response)
67-
results = await bitrix.call("crm.lead.get", {"ID": 35943})
55+
bx_dummy.srh = MockSRH(response)
56+
results = bx_dummy.call("crm.lead.get", {"ID": 35943})
6857
assert isinstance(results, dict)
6958

7059

71-
@pytest.mark.asyncio
72-
async def test_call_several_success(bitrix):
60+
def test_call_several_success(bx_dummy):
7361
from tests.real_responses.call_several_success import response
7462

75-
bitrix.srh = MockSRH(response)
76-
results = await bitrix.call(
77-
"crm.lead.get", [{"ID": 35943}, {"ID": 161}, {"ID": 171}]
78-
)
63+
bx_dummy.srh = MockSRH(response)
64+
results = bx_dummy.call("crm.lead.get", [{"ID": 35943}, {"ID": 161}, {"ID": 171}])
7965
assert isinstance(results, tuple)
8066
assert len(results) == 3
8167
assert isinstance(results[0], dict)

tests/test_sync.py

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,7 @@
11
import os
22

3-
from icontract import ViolationError
43
import pytest
54

6-
from .fixtures import (
7-
create_100_leads,
8-
create_100_leads_async,
9-
create_a_lead,
10-
get_test,
11-
get_test_async,
12-
create_a_deal,
13-
create_100_tasks,
14-
)
15-
16-
from fast_bitrix24 import Bitrix
17-
from fast_bitrix24.server_response import ServerResponseParser
18-
19-
205
@pytest.mark.skipif(
216
not os.getenv("FAST_BITRIX24_TEST_WEBHOOK"),
227
reason="Нет аккаунта, на котором можно проверить",
@@ -159,8 +144,8 @@ def test_case(self, get_test):
159144

160145

161146
class TestErrors:
162-
def test_get_all(self, get_test):
163-
b = get_test
147+
def test_get_all(self, bx_dummy):
148+
b = bx_dummy
164149

165150
with pytest.raises(Exception):
166151
b.get_all("")
@@ -174,17 +159,17 @@ def test_get_all(self, get_test):
174159
with pytest.raises(Exception):
175160
b.get_all("some_method", {"filter": 3})
176161

177-
def test_get_by_ID(self, get_test):
178-
b = get_test
162+
def test_get_by_ID(self, bx_dummy):
163+
b = bx_dummy
179164

180165
with pytest.raises(Exception):
181166
b.get_by_ID("_", 123)
182167

183168
with pytest.raises(Exception):
184169
b.get_by_ID("_", [["a"]])
185170

186-
def test_call(self, get_test, monkeypatch):
187-
b = get_test
171+
def test_call(self, bx_dummy, monkeypatch):
172+
b = bx_dummy
188173

189174
async def stub(*args, **kwargs):
190175
return {"result": "ok"}

0 commit comments

Comments
 (0)