Skip to content

Commit a265fa0

Browse files
author
Alexandre Vincent
committed
[change] Use PropertyMock for stdout.channel.exit_status on exec_command
1 parent 8c5a06e commit a265fa0

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

openwisp_controller/connection/tests/test_models.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from unittest.mock import PropertyMock
2+
13
import socket
24
from unittest import mock
35

@@ -46,7 +48,7 @@ def _exec_command_return_value(
4648
stderr_ = mock.Mock()
4749
stdin_.read().decode.return_value = stdin
4850
stdout_.read().decode.return_value = stdout
49-
stdout_.channel.exit_status = exit_code
51+
type(stdout_.channel).exit_status = PropertyMock(return_value=exit_code)
5052
stderr_.read().decode.return_value = stderr
5153
return (stdin_, stdout_, stderr_)
5254

@@ -1009,7 +1011,7 @@ def _assert_applying_conf_test_command(mocked_exec):
10091011
# 1. Checking openwisp_config returns with 0
10101012
# 2. Testing presence of /tmp/openwisp/applying_conf returns with 1
10111013
# 3. Restarting openwisp_config returns with 0 exit code
1012-
stdout.channel.recv_exit_status.side_effect = [0, 1, 1]
1014+
type(stdout.channel).exit_status = PropertyMock(side_effect = [0, 1, 1])
10131015
mocked_exec_command.return_value = (stdin, stdout, stderr)
10141016
conf.save()
10151017
self.assertEqual(mocked_exec_command.call_count, 3)

0 commit comments

Comments
 (0)