66class 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
3027class 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