Skip to content

Commit f225b9c

Browse files
Akop KesheshyanAkop Kesheshyan
authored andcommitted
Integration tests are excluded
1 parent 1eb34c8 commit f225b9c

File tree

3 files changed

+48
-34
lines changed

3 files changed

+48
-34
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ except BitrixError as message:
5656
List methods return all available items at once. For large collections
5757
of data use limits.
5858

59+
## Tests
60+
61+
```
62+
python -m unittest discover
63+
```
64+
5965
## Author
6066

6167
Akop Kesheshyan - <akop.kesheshyan@icloud.com>

bitrix24/bitrix24.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,19 @@ class Bitrix24(object):
2828
"""
2929

3030
def __init__(self, domain, timeout=60):
31+
"""Create Bitrix24 API object
32+
:param domain: str Bitrix24 webhook domain
33+
:param timeout: int Timeout for API request in seconds
34+
"""
3135
self.domain = self._prepare_domain(domain)
3236
self.timeout = timeout
3337

34-
def _prepare_domain(self, string):
38+
def _prepare_domain(self, domain):
3539
"""Normalize user passed domain to a valid one."""
36-
o = urlparse(string)
40+
if domain == '' or not isinstance(domain, str):
41+
raise Exception('Empty domain')
42+
43+
o = urlparse(domain)
3744
user_id, code = o.path.split('/')[2:4]
3845
return "{0}://{1}/rest/{2}/{3}".format(o.scheme, o.netloc, user_id, code)
3946

tests/test_bitrix24.py

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,11 @@
66
class Bitrix24Test(unittest.TestCase):
77

88
def setUp(self):
9-
self.b24 = Bitrix24(os.environ.get('TEST_DOMAIN'))
9+
self.b24 = Bitrix24('https://example.bitrix24.com/rest/1/123456789')
1010

11-
def test_call_post_method(self):
12-
r = self.b24.callMethod('crm.deal.add', fields={
13-
'TITLE': 'Hello World'})
14-
self.assertIs(type(r), int)
15-
16-
def test_call_get_method(self):
17-
r = self.b24.callMethod('crm.deal.list', filter={
18-
'TITLE': 'Hello World'})
19-
self.assertIs(type(r), list)
11+
def test_init_with_empty_domain(self):
12+
with self.assertRaises(Exception):
13+
Bitrix24('')
2014

2115
def test_call_with_empty_method(self):
2216
with self.assertRaises(BitrixError):
@@ -26,54 +20,61 @@ def test_call_non_exists_method(self):
2620
with self.assertRaises(BitrixError):
2721
self.b24.callMethod('hello.world')
2822

23+
def test_call_wrong_method(self):
24+
with self.assertRaises(BitrixError):
25+
self.b24.callMethod('helloworld')
2926

3027
class ParamsPreparationTest(unittest.TestCase):
3128

3229
def setUp(self):
33-
self.b24 = Bitrix24('http://example.bitrix24.com/rest/1/123456789')
30+
self.b24 = Bitrix24('https://example.bitrix24.com/rest/1/123456789')
3431

3532
def test_one_level(self):
3633
params = {"fruit": "apple"}
37-
param_string = self.b24._prepare_params(params)
34+
param_string = self.b24._prepare_params(params)
3835
self.assertEqual(param_string, "fruit=apple&")
3936

4037
def test_one_level_several_items(self):
41-
params = {"fruit": "apple", "vegetable":"broccoli"}
42-
param_string = self.b24._prepare_params(params)
38+
params = {"fruit": "apple", "vegetable": "broccoli"}
39+
param_string = self.b24._prepare_params(params)
4340
self.assertEqual(param_string, "fruit=apple&vegetable=broccoli&")
4441

4542
def test_multi_level(self):
46-
params = {"fruit": {"citrus":"lemon"}}
47-
param_string = self.b24._prepare_params(params)
43+
params = {"fruit": {"citrus": "lemon"}}
44+
param_string = self.b24._prepare_params(params)
4845
self.assertEqual(param_string, "fruit[citrus]=lemon&")
49-
46+
5047
def test_multi_level_deep(self):
51-
params = {"root": {"level 1":{"level 2":{"level 3":"value"}}}}
52-
param_string = self.b24._prepare_params(params)
53-
self.assertEqual(param_string, "root[level 1][level 2][level 3]=value&")
54-
48+
params = {"root": {"level 1": {"level 2": {"level 3": "value"}}}}
49+
param_string = self.b24._prepare_params(params)
50+
self.assertEqual(
51+
param_string, "root[level 1][level 2][level 3]=value&")
52+
5553
def test_list_dict_mixed(self):
56-
params = {"root":{"level 1":[{"list_dict 1": "value 1"}, {"list_dict 2": "value 2"}]}}
57-
param_string = self.b24._prepare_params(params)
58-
self.assertEqual(param_string, "root[level 1][0][list_dict 1]=value 1&root[level 1][1][list_dict 2]=value 2&")
59-
54+
params = {"root": {"level 1": [
55+
{"list_dict 1": "value 1"}, {"list_dict 2": "value 2"}]}}
56+
param_string = self.b24._prepare_params(params)
57+
self.assertEqual(
58+
param_string, "root[level 1][0][list_dict 1]=value 1&root[level 1][1][list_dict 2]=value 2&")
59+
6060
def test_multi_level_several_items(self):
61-
params = {"fruit": {"citrus":"lemon", "sweet": "apple"}}
62-
param_string = self.b24._prepare_params(params)
63-
self.assertEqual(param_string, "fruit[citrus]=lemon&fruit[sweet]=apple&")
61+
params = {"fruit": {"citrus": "lemon", "sweet": "apple"}}
62+
param_string = self.b24._prepare_params(params)
63+
self.assertEqual(
64+
param_string, "fruit[citrus]=lemon&fruit[sweet]=apple&")
6465

6566
def test_list(self):
6667
params = {"fruit": ["lemon", "apple"]}
67-
param_string = self.b24._prepare_params(params)
68+
param_string = self.b24._prepare_params(params)
6869
self.assertEqual(param_string, "fruit[0]=lemon&fruit[1]=apple&")
6970

7071
def test_tuple(self):
7172
params = {"fruit": ("lemon", "apple")}
72-
param_string = self.b24._prepare_params(params)
73+
param_string = self.b24._prepare_params(params)
7374
self.assertEqual(param_string, "fruit[0]=lemon&fruit[1]=apple&")
74-
75+
7576
def test_string(self):
76-
param_string = self.b24._prepare_params('')
77+
param_string = self.b24._prepare_params('')
7778
self.assertEqual(param_string, "")
7879

7980

0 commit comments

Comments
 (0)