@@ -27,7 +27,7 @@ class TestFarmbot(unittest.TestCase):
27
27
def setUp (self ):
28
28
'''Set up method called before each test case'''
29
29
self .fb = Farmbot ()
30
- self .fb .state . token = MOCK_TOKEN
30
+ self .fb .set_token ( MOCK_TOKEN )
31
31
self .fb .set_verbosity (0 )
32
32
self .fb .state .test_env = True
33
33
self .fb .state .broker_listen_duration = 0.3
@@ -41,7 +41,7 @@ def test_get_token_default_server(self, mock_post):
41
41
mock_response .status_code = 200
42
42
mock_response .text = 'text'
43
43
mock_post .return_value = mock_response
44
- self .fb .state . token = None
44
+ self .fb .set_token ( None )
45
45
# Call with default server
46
46
self .
fb .
get_token (
'[email protected] ' ,
'test_pass_123' )
47
47
mock_post .assert_called_once_with (
@@ -61,7 +61,7 @@ def test_get_token_custom_server(self, mock_post):
61
61
mock_response .status_code = 200
62
62
mock_response .text = 'text'
63
63
mock_post .return_value = mock_response
64
- self .fb .state . token = None
64
+ self .fb .set_token ( None )
65
65
# Call with custom server
66
66
self .
fb .
get_token (
'[email protected] ' ,
'test_pass_123' ,
67
67
'https://staging.farm.bot' )
@@ -82,7 +82,7 @@ def helper_get_token_errors(self, *args, **kwargs):
82
82
mock_response = Mock ()
83
83
mock_response .status_code = status_code
84
84
mock_post .return_value = mock_response
85
- self .fb .state . token = None
85
+ self .fb .set_token ( None )
86
86
self .
fb .
get_token (
'[email protected] ' ,
'test_pass_123' )
87
87
mock_post .assert_called_once_with (
88
88
'https://my.farm.bot/api/tokens' ,
@@ -121,7 +121,7 @@ def helper_get_token_exceptions(self, *args, **kwargs):
121
121
exception = kwargs ['exception' ]
122
122
error_msg = kwargs ['error_msg' ]
123
123
mock_post .side_effect = exception
124
- self .fb .state . token = None
124
+ self .fb .set_token ( None )
125
125
self .
fb .
get_token (
'[email protected] ' ,
'test_pass_123' )
126
126
mock_post .assert_called_once_with (
127
127
'https://my.farm.bot/api/tokens' ,
@@ -288,7 +288,7 @@ def test_api_get_with_id(self, mock_request):
288
288
@patch ('requests.request' )
289
289
def test_check_token_api_request (self , mock_request ):
290
290
'''Test check_token: API request'''
291
- self .fb .state . token = None
291
+ self .fb .set_token ( None )
292
292
with self .assertRaises (ValueError ) as cm :
293
293
self .fb .api_get ('points' )
294
294
self .assertEqual (cm .exception .args [0 ], self .fb .state .NO_TOKEN_ERROR )
@@ -301,7 +301,7 @@ def test_check_token_broker(self, mock_request, mock_mqtt):
301
301
'''Test check_token: broker'''
302
302
mock_client = Mock ()
303
303
mock_mqtt .return_value = mock_client
304
- self .fb .state . token = None
304
+ self .fb .set_token ( None )
305
305
with self .assertRaises (ValueError ) as cm :
306
306
self .fb .on (123 )
307
307
self .assertEqual (cm .exception .args [0 ], self .fb .state .NO_TOKEN_ERROR )
@@ -1774,6 +1774,3 @@ def test_print_status(self, mock_print):
1774
1774
call_strings = [s .split ('(' )[0 ].strip ('`' ) for s in call_strings ]
1775
1775
self .assertIn ('[\n "testing"\n ]' , call_strings )
1776
1776
self .assertIn ('test_print_status' , call_strings )
1777
-
1778
- if __name__ == '__main__' :
1779
- unittest .main ()
0 commit comments