6
6
class Bitrix24Test (unittest .TestCase ):
7
7
8
8
def setUp (self ):
9
- self .b24 = Bitrix24 (os . environ . get ( 'TEST_DOMAIN' ) )
9
+ self .b24 = Bitrix24 ('https://example.bitrix24.com/rest/1/123456789' )
10
10
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 ('' )
20
14
21
15
def test_call_with_empty_method (self ):
22
16
with self .assertRaises (BitrixError ):
@@ -26,54 +20,61 @@ def test_call_non_exists_method(self):
26
20
with self .assertRaises (BitrixError ):
27
21
self .b24 .callMethod ('hello.world' )
28
22
23
+ def test_call_wrong_method (self ):
24
+ with self .assertRaises (BitrixError ):
25
+ self .b24 .callMethod ('helloworld' )
29
26
30
27
class ParamsPreparationTest (unittest .TestCase ):
31
28
32
29
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' )
34
31
35
32
def test_one_level (self ):
36
33
params = {"fruit" : "apple" }
37
- param_string = self .b24 ._prepare_params (params )
34
+ param_string = self .b24 ._prepare_params (params )
38
35
self .assertEqual (param_string , "fruit=apple&" )
39
36
40
37
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 )
43
40
self .assertEqual (param_string , "fruit=apple&vegetable=broccoli&" )
44
41
45
42
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 )
48
45
self .assertEqual (param_string , "fruit[citrus]=lemon&" )
49
-
46
+
50
47
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
+
55
53
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
+
60
60
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&" )
64
65
65
66
def test_list (self ):
66
67
params = {"fruit" : ["lemon" , "apple" ]}
67
- param_string = self .b24 ._prepare_params (params )
68
+ param_string = self .b24 ._prepare_params (params )
68
69
self .assertEqual (param_string , "fruit[0]=lemon&fruit[1]=apple&" )
69
70
70
71
def test_tuple (self ):
71
72
params = {"fruit" : ("lemon" , "apple" )}
72
- param_string = self .b24 ._prepare_params (params )
73
+ param_string = self .b24 ._prepare_params (params )
73
74
self .assertEqual (param_string , "fruit[0]=lemon&fruit[1]=apple&" )
74
-
75
+
75
76
def test_string (self ):
76
- param_string = self .b24 ._prepare_params ('' )
77
+ param_string = self .b24 ._prepare_params ('' )
77
78
self .assertEqual (param_string , "" )
78
79
79
80
0 commit comments