Esempio n. 1
0
    def test_stop_windows(self):
        self.mock_platform.return_value = 'Windows'
        ruby_exe = Mock(spec=Process)
        self.mock_Process.return_value.children.return_value = [ruby_exe]
        self.mock_Pid_exists.return_value = False
        pact = Pact(Consumer('consumer', version='abc'),
                    Provider('provider'),
                    publish_to_broker=True,
                    pact_dir='some_dir')
        pact._process = Mock(spec=Popen, pid=999)
        pact.stop_service()

        self.assertFalse(pact._process.terminate.called)
        self.assertFalse(pact._process.communicate.called)
        self.mock_Process.assert_called_once_with(999)
        self.mock_Process.return_value.children.assert_called_once_with(
            recursive=True)
        ruby_exe.terminate.assert_called_once_with()
        self.mock_Process.return_value.wait.assert_called_once_with()
        self.mock_Pid_exists.assert_called_once_with(999)
        self.mock_publish.assert_called_once_with(pact,
                                                  'consumer',
                                                  'abc',
                                                  consumer_tags=None,
                                                  tag_with_git_branch=False,
                                                  pact_dir='some_dir')
Esempio n. 2
0
    def test_stop_posix(self):
        self.mock_platform.return_value = 'Linux'
        pact = Pact(Consumer('consumer'), Provider('provider'))
        pact._process = Mock(spec=Popen, pid=999, returncode=0)
        pact.stop_service()

        pact._process.terminate.assert_called_once_with()
        pact._process.communicate.assert_called_once_with()
        self.assertFalse(self.mock_Process.called)
Esempio n. 3
0
    def test_stop_fails_posix(self):
        self.mock_platform.return_value = 'Linux'
        self.mock_Popen.return_value.returncode = 1
        pact = Pact(Consumer('consumer'), Provider('provider'))
        pact._process = Mock(spec=Popen, pid=999, returncode=1)
        with self.assertRaises(RuntimeError):
            pact.stop_service()

        pact._process.terminate.assert_called_once_with()
        pact._process.communicate.assert_called_once_with()
Esempio n. 4
0
 def setUp(self):
     self.consumer = Consumer('TestConsumer')
     self.provider = Provider('TestProvider')
     self.addCleanup(patch.stopall)
     self.mock_Popen = patch.object(broker, 'Popen', autospec=True).start()
     self.mock_Popen.return_value.returncode = 0
     self.mock_fnmatch = patch.object(broker.fnmatch,
                                      'filter',
                                      autospec=True).start()
     self.mock_fnmatch.return_value = ['TestConsumer-TestProvider.json']
Esempio n. 5
0
    def test_start_no_ssl(self):
        pact = Pact(Consumer('consumer'),
                    Provider('provider'),
                    log_dir='/logs',
                    pact_dir='/pacts')
        pact.start_service()

        self.mock_Popen.assert_called_once_with([
            MOCK_SERVICE_PATH, 'service', '--host=localhost', '--port=1234',
            '--log', '/logs/pact-mock-service.log', '--pact-dir', '/pacts',
            '--pact-file-write-mode', 'overwrite',
            '--pact-specification-version=2.0.0', '--consumer', 'consumer',
            '--provider', 'provider'
        ])
Esempio n. 6
0
    def test_wait_for_server_start_success(self):
        self.mock_Session.return_value.get.return_value.status_code = 200
        pact = Pact(Consumer('consumer'), Provider('provider'))
        pact._process = Mock(spec=Popen)
        pact._wait_for_server_start()

        session = self.mock_Session.return_value
        session.mount.assert_called_once_with(
            'http://', self.mock_HTTPAdapter.return_value)
        session.get.assert_called_once_with(
            'http://localhost:1234', headers={'X-Pact-Mock-Service': 'true'})
        self.mock_HTTPAdapter.assert_called_once_with(
            max_retries=self.mock_Retry.return_value)
        self.mock_Retry.assert_called_once_with(total=9, backoff_factor=0.1)
        self.assertFalse(pact._process.communicate.called)
        self.assertFalse(pact._process.terminate.called)
Esempio n. 7
0
    def test_stop_fails_windows(self):
        self.mock_platform.return_value = 'Windows'
        self.mock_Popen.return_value.returncode = 15
        self.mock_Pid_exists.return_value = True

        pact = Pact(Consumer('consumer'), Provider('provider'))
        pact._process = Mock(spec=Popen, pid=999, returncode=15)
        with self.assertRaises(RuntimeError):
            pact.stop_service()

        self.assertFalse(pact._process.terminate.called)
        self.assertFalse(pact._process.communicate.called)
        self.mock_Process.assert_called_once_with(999)
        self.mock_Process.return_value.children.assert_called_once_with(
            recursive=True)
        self.mock_Process.return_value.wait.assert_called_once_with()
        self.mock_Pid_exists.assert_called_once_with(999)
Esempio n. 8
0
    def test_stop_windows(self):
        self.mock_platform.return_value = 'Windows'
        ruby_exe = Mock(spec=Process)
        self.mock_Process.return_value.children.return_value = [ruby_exe]
        self.mock_Pid_exists.return_value = False
        pact = Pact(Consumer('consumer'), Provider('provider'))
        pact._process = Mock(spec=Popen, pid=999)
        pact.stop_service()

        self.assertFalse(pact._process.terminate.called)
        self.assertFalse(pact._process.communicate.called)
        self.mock_Process.assert_called_once_with(999)
        self.mock_Process.return_value.children.assert_called_once_with(
            recursive=True)
        ruby_exe.terminate.assert_called_once_with()
        self.mock_Process.return_value.wait.assert_called_once_with()
        self.mock_Pid_exists.assert_called_once_with(999)
Esempio n. 9
0
    def test_start_fails(self):
        self.mock_Popen.return_value.returncode = 1
        self.mock_wait_for_server_start.side_effect = RuntimeError
        pact = Pact(Consumer('consumer'),
                    Provider('provider'),
                    log_dir='/logs',
                    pact_dir='/pacts')

        with self.assertRaises(RuntimeError):
            pact.start_service()

        self.mock_Popen.assert_called_once_with([
            MOCK_SERVICE_PATH, 'service', '--host=localhost', '--port=1234',
            '--log', '/logs/pact-mock-service.log', '--pact-dir', '/pacts',
            '--pact-file-write-mode', 'overwrite',
            '--pact-specification-version=2.0.0', '--consumer', 'consumer',
            '--provider', 'provider'
        ])
Esempio n. 10
0
 def setUp(self):
     self.consumer = Consumer('TestConsumer')
     self.provider = Provider('TestProvider')