55from mock import patch , call , Mock
66from psutil import Process
77
8+ from pact .broker import Broker
89from pact .consumer import Consumer , Provider
910from pact .matchers import Term
1011from pact .constants import MOCK_SERVICE_PATH
@@ -294,6 +295,8 @@ def setUp(self):
294295 pact .Pact , '_wait_for_server_start' , autospec = True ).start ()
295296 self .mock_Pid_exists = patch .object (
296297 pact .psutil , 'pid_exists' , autospec = True ).start ()
298+ self .mock_publish = patch .object (
299+ Broker , 'publish' , autospec = True ).start ()
297300
298301 def test_start_fails (self ):
299302 self .mock_Popen .return_value .returncode = 1
@@ -352,21 +355,23 @@ def test_start_with_ssl(self):
352355 '--sslkey' , '/ssl.key' ])
353356
354357 def test_stop_posix (self ):
358+ self .mock_publish .return_value .returncode = 0
355359 self .mock_platform .return_value = 'Linux'
356360 pact = Pact (Consumer ('consumer' ), Provider ('provider' ))
357361 pact ._process = Mock (spec = Popen , pid = 999 , returncode = 0 )
358362 pact .stop_service ()
359363
360364 pact ._process .terminate .assert_called_once_with ()
361365 pact ._process .communicate .assert_called_once_with ()
366+ self .mock_publish .assert_not_called ()
362367 self .assertFalse (self .mock_Process .called )
363368
364369 def test_stop_windows (self ):
365370 self .mock_platform .return_value = 'Windows'
366371 ruby_exe = Mock (spec = Process )
367372 self .mock_Process .return_value .children .return_value = [ruby_exe ]
368373 self .mock_Pid_exists .return_value = False
369- pact = Pact (Consumer ('consumer' ), Provider ('provider' ))
374+ pact = Pact (Consumer ('consumer' ), Provider ('provider' ), publish_to_broker = True )
370375 pact ._process = Mock (spec = Popen , pid = 999 )
371376 pact .stop_service ()
372377
@@ -378,6 +383,7 @@ def test_stop_windows(self):
378383 ruby_exe .terminate .assert_called_once_with ()
379384 self .mock_Process .return_value .wait .assert_called_once_with ()
380385 self .mock_Pid_exists .assert_called_once_with (999 )
386+ self .mock_publish .assert_called_once ()
381387
382388 def test_stop_fails_posix (self ):
383389 self .mock_platform .return_value = 'Linux'
@@ -389,6 +395,7 @@ def test_stop_fails_posix(self):
389395
390396 pact ._process .terminate .assert_called_once_with ()
391397 pact ._process .communicate .assert_called_once_with ()
398+ self .mock_publish .assert_not_called ()
392399
393400 def test_stop_fails_windows (self ):
394401 self .mock_platform .return_value = 'Windows'
@@ -407,6 +414,7 @@ def test_stop_fails_windows(self):
407414 recursive = True )
408415 self .mock_Process .return_value .wait .assert_called_once_with ()
409416 self .mock_Pid_exists .assert_called_once_with (999 )
417+ self .mock_publish .assert_not_called ()
410418
411419
412420class PactWaitForServerStartTestCase (TestCase ):
0 commit comments