|
1 | | -import unittest |
| 1 | +import pytest |
2 | 2 |
|
3 | 3 | from bitrix24 import Bitrix24, BitrixError |
4 | 4 |
|
5 | 5 |
|
6 | | -class Bitrix24Test(unittest.TestCase): |
7 | | - def setUp(self): |
8 | | - self.b24 = Bitrix24("https://example.bitrix24.com/rest/1/123456789") |
| 6 | +def test_init_with_empty_domain(): |
| 7 | + with pytest.raises(BitrixError): |
| 8 | + Bitrix24("") |
9 | 9 |
|
10 | | - def test_init_with_empty_domain(self): |
11 | | - with self.assertRaises(Exception): |
12 | | - Bitrix24("") |
13 | 10 |
|
14 | | - def test_call_with_empty_method(self): |
15 | | - with self.assertRaises(BitrixError): |
16 | | - self.b24.callMethod("") |
| 11 | +def test_call_with_empty_method(b24): |
| 12 | + with pytest.raises(BitrixError): |
| 13 | + b24.callMethod("") |
17 | 14 |
|
18 | | - def test_call_non_exists_method(self): |
19 | | - with self.assertRaises(BitrixError): |
20 | | - self.b24.callMethod("hello.world") |
21 | 15 |
|
22 | | - def test_call_wrong_method(self): |
23 | | - with self.assertRaises(BitrixError): |
24 | | - self.b24.callMethod("helloworld") |
| 16 | +def test_call_non_exists_method(b24): |
| 17 | + with pytest.raises(BitrixError): |
| 18 | + b24.callMethod("hello.world") |
25 | 19 |
|
26 | 20 |
|
27 | | -class ParamsPreparationTest(unittest.TestCase): |
28 | | - def setUp(self): |
29 | | - self.b24 = Bitrix24("https://example.bitrix24.com/rest/1/123456789") |
30 | | - |
31 | | - def test_one_level(self): |
32 | | - params = {"fruit": "apple"} |
33 | | - param_string = self.b24._prepare_params(params) |
34 | | - self.assertEqual(param_string, "fruit=apple&") |
35 | | - |
36 | | - def test_one_level_several_items(self): |
37 | | - params = {"fruit": "apple", "vegetable": "broccoli"} |
38 | | - param_string = self.b24._prepare_params(params) |
39 | | - self.assertEqual(param_string, "fruit=apple&vegetable=broccoli&") |
40 | | - |
41 | | - def test_multi_level(self): |
42 | | - params = {"fruit": {"citrus": "lemon"}} |
43 | | - param_string = self.b24._prepare_params(params) |
44 | | - self.assertEqual(param_string, "fruit[citrus]=lemon&") |
45 | | - |
46 | | - def test_multi_level_deep(self): |
47 | | - params = {"root": {"level 1": {"level 2": {"level 3": "value"}}}} |
48 | | - param_string = self.b24._prepare_params(params) |
49 | | - self.assertEqual(param_string, "root[level 1][level 2][level 3]=value&") |
50 | | - |
51 | | - def test_list_dict_mixed(self): |
52 | | - params = {"root": {"level 1": [{"list_dict 1": "value 1"}, {"list_dict 2": "value 2"}]}} |
53 | | - param_string = self.b24._prepare_params(params) |
54 | | - self.assertEqual( |
55 | | - param_string, |
56 | | - "root[level 1][0][list_dict 1]=value 1&root[level 1][1][list_dict 2]=value 2&", |
57 | | - ) |
58 | | - |
59 | | - def test_multi_level_several_items(self): |
60 | | - params = {"fruit": {"citrus": "lemon", "sweet": "apple"}} |
61 | | - param_string = self.b24._prepare_params(params) |
62 | | - self.assertEqual(param_string, "fruit[citrus]=lemon&fruit[sweet]=apple&") |
63 | | - |
64 | | - def test_list(self): |
65 | | - params = {"fruit": ["lemon", "apple"]} |
66 | | - param_string = self.b24._prepare_params(params) |
67 | | - self.assertEqual(param_string, "fruit[0]=lemon&fruit[1]=apple&") |
68 | | - |
69 | | - def test_tuple(self): |
70 | | - params = {"fruit": ("lemon", "apple")} |
71 | | - param_string = self.b24._prepare_params(params) |
72 | | - self.assertEqual(param_string, "fruit[0]=lemon&fruit[1]=apple&") |
73 | | - |
74 | | - def test_string(self): |
75 | | - param_string = self.b24._prepare_params("") |
76 | | - self.assertEqual(param_string, "") |
| 21 | +def test_call_wrong_method(b24): |
| 22 | + with pytest.raises(BitrixError): |
| 23 | + b24.callMethod("helloworld") |
0 commit comments