@@ -943,8 +943,10 @@ def test_069_on_qdb_change_removed_attached(self):
943
943
('device-removed:block' , frozenset ({('port' , exp_dev .port )}))],
944
944
1 )
945
945
946
- @unittest .mock .patch ('subprocess.Popen' )
947
- def test_070_on_qdb_change_two_fronts_failed (self , mock_confirm ):
946
+ # with `new_callable=Mock` we override async function with synchronous Mock
947
+ @unittest .mock .patch (
948
+ 'qubes.ext.utils.confirm_device_attachment' , new_callable = Mock )
949
+ def test_070_on_qdb_change_two_fronts_failed (self , _mock_confirm ):
948
950
back , front = self .added_assign_setup ()
949
951
950
952
exp_dev = qubes .ext .block .BlockDevice (back , 'sda' )
@@ -954,18 +956,20 @@ def test_070_on_qdb_change_two_fronts_failed(self, mock_confirm):
954
956
back .devices ['block' ]._assigned .append (assign )
955
957
back .devices ['block' ]._exposed .append (exp_dev )
956
958
957
- proc = Mock ()
958
- proc .communicate = Mock ()
959
- proc .communicate .return_value = (b'nonsense' , b'' )
960
- mock_confirm .return_value = proc
961
959
self .ext .attach_and_notify = Mock ()
962
- with mock .patch ('asyncio.ensure_future' ):
960
+
961
+ with mock .patch ('qubes.ext.utils.asyncio.ensure_future' ) as future :
962
+ future .return_value = Mock ()
963
+ future .return_value .result = Mock ()
964
+ future .return_value .result .return_value = "nonsense"
963
965
self .ext .on_qdb_change (back , None , None )
964
- proc . communicate . assert_called_once ()
966
+
965
967
self .ext .attach_and_notify .assert_not_called ()
966
968
967
- @unittest .mock .patch ('subprocess.Popen' )
968
- def test_071_on_qdb_change_two_fronts (self , mock_confirm ):
969
+ # with `new_callable=Mock` we override async function with synchronous Mock
970
+ @unittest .mock .patch (
971
+ 'qubes.ext.utils.confirm_device_attachment' , new_callable = Mock )
972
+ def test_071_on_qdb_change_two_fronts (self , _mock_confirm ):
969
973
back , front = self .added_assign_setup ()
970
974
971
975
exp_dev = qubes .ext .block .BlockDevice (back , 'sda' )
@@ -975,16 +979,15 @@ def test_071_on_qdb_change_two_fronts(self, mock_confirm):
975
979
back .devices ['block' ]._assigned .append (assign )
976
980
back .devices ['block' ]._exposed .append (exp_dev )
977
981
978
- proc = Mock ()
979
- proc .communicate = Mock ()
980
- proc .communicate .return_value = (b'front-vm' , b'' )
981
- mock_confirm .return_value = proc
982
982
self .ext .attach_and_notify = Mock ()
983
- with mock .patch ('asyncio.ensure_future' ):
983
+
984
+ with mock .patch ('asyncio.ensure_future' ) as future :
985
+ future .return_value = Mock ()
986
+ future .return_value .result = Mock ()
987
+ future .return_value .result .return_value = "front-vm"
984
988
self .ext .on_qdb_change (back , None , None )
985
- proc .communicate .assert_called_once ()
986
- self .ext .attach_and_notify .assert_called_once_with (
987
- front , assign )
989
+
990
+ self .ext .attach_and_notify .assert_called_once_with (front , assign )
988
991
# don't ask again
989
992
self .assertEqual (self .ext .attach_and_notify .call_args [0 ][1 ].mode .value ,
990
993
'auto-attach' )
0 commit comments