Esempio n. 1
0
class VerifierPactsTestCase(TestCase):

    def setUp(self):
        super(VerifierPactsTestCase, self).setUp()
        self.addCleanup(patch.stopall)
        self.verifier = Verifier(provider='test_provider',
                                 provider_base_url="http://*****:*****@patch("pact.verify_wrapper.VerifyWrapper.call_verify")
    @patch('pact.verifier.path_exists', return_value=True)
    def test_verifier_with_provider_and_files(self, mock_path_exists, mock_wrapper):
        mock_wrapper.return_value = (True, 'some logs')

        output, _ = self.verifier.verify_pacts('path/to/pact1',
                                               'path/to/pact2')

        assertVerifyCalled(mock_wrapper,
                           'path/to/pact1',
                           'path/to/pact2',
                           provider='test_provider',
                           provider_base_url='http://*****:*****@patch("pact.verify_wrapper.VerifyWrapper.call_verify")
    @patch('pact.verifier.path_exists', return_value=True)
    def test_publish_on_success(self, mock_path_exists, mock_wrapper):
        mock_wrapper.return_value = (True, 'some logs')

        output, _ = self.verifier.verify_pacts('path/to/pact1', publish_version='1.0.0')

        assertVerifyCalled(mock_wrapper,
                           'path/to/pact1',
                           provider='test_provider',
                           provider_base_url='http://*****:*****@patch('pact.verifier.path_exists', return_value=False)
    def test_raises_error_on_missing_pact_files(self, mock_path_exists):
        self.assertRaises(Exception,
                          self.verifier.verify_pacts,
                          'path/to/pact1', 'path/to/pact2')

        mock_path_exists.assert_called_with('path/to/pact2')

    @patch("pact.verify_wrapper.VerifyWrapper.call_verify", return_value=(0, None))
    @patch('pact.verifier.expand_directories', return_value=['./pacts/pact1', './pacts/pact2'])
    @patch('pact.verifier.path_exists', return_value=True)
    def test_expand_directories_called_for_pacts(self, mock_path_exists, mock_expand_dir, mock_wrapper):
        output, _ = self.verifier.verify_pacts('path/to/pact1',
                                               'path/to/pact2')

        mock_expand_dir.assert_called_once()

    @patch('pact.verify_wrapper.VerifyWrapper.call_verify', return_value=(0, None))
    def test_passes_enable_pending_flag_value(self, mock_wrapper):
        for value in (True, False):
            with self.subTest(value=value):
                with patch('pact.verifier.path_exists'):
                    self.verifier.verify_pacts('any.json', enable_pending=value)
                self.assertTrue(
                    ('enable_pending', value) in mock_wrapper.call_args.kwargs.items(),
                    mock_wrapper.call_args.kwargs,
                )
Esempio n. 2
0
class VerifierPactsTestCase(TestCase):

    def setUp(self):
        super(VerifierPactsTestCase, self).setUp()
        self.addCleanup(patch.stopall)
        self.verifier = Verifier(provider='test_provider',
                                 provider_base_url="http://*****:*****@patch("pact.verify_wrapper.VerifyWrapper.call_verify")
    @patch('pact.verifier.path_exists', return_value=True)
    def test_verifier_with_provider_and_files(self, mock_path_exists, mock_wrapper):
        mock_wrapper.return_value = (True, 'some logs')

        output, _ = self.verifier.verify_pacts('path/to/pact1',
                                               'path/to/pact2',
                                               headers=['header1', 'header2'])

        assertVerifyCalled(mock_wrapper,
                           'path/to/pact1',
                           'path/to/pact2',
                           provider='test_provider',
                           custom_provider_headers=['header1', 'header2'],
                           provider_base_url='http://*****:*****@patch("pact.verify_wrapper.VerifyWrapper.call_verify")
    @patch('pact.verifier.path_exists', return_value=True)
    def test_verifier_with_provider_and_files_passes_consumer_selctors(self, mock_path_exists, mock_wrapper):
        mock_wrapper.return_value = (True, 'some logs')

        output, _ = self.verifier.verify_pacts(
            'path/to/pact1',
            'path/to/pact2',
            headers=['header1', 'header2'],
            consumer_version_selectors=[
                # Using OrderedDict for the sake of testing
                OrderedDict([("tag", "main"), ("latest", True)]),
                OrderedDict([("tag", "test"), ("latest", False)]),
            ]
        )

        assertVerifyCalled(mock_wrapper,
                           'path/to/pact1',
                           'path/to/pact2',
                           provider='test_provider',
                           custom_provider_headers=['header1', 'header2'],
                           provider_base_url='http://*****:*****@patch("pact.verify_wrapper.VerifyWrapper.call_verify")
    @patch('pact.verifier.path_exists', return_value=True)
    def test_publish_on_success(self, mock_path_exists, mock_wrapper):
        mock_wrapper.return_value = (True, 'some logs')

        output, _ = self.verifier.verify_pacts('path/to/pact1', publish_version='1.0.0')

        assertVerifyCalled(mock_wrapper,
                           'path/to/pact1',
                           provider='test_provider',
                           provider_base_url='http://*****:*****@patch('pact.verifier.path_exists', return_value=False)
    def test_raises_error_on_missing_pact_files(self, mock_path_exists):
        self.assertRaises(Exception,
                          self.verifier.verify_pacts,
                          'path/to/pact1', 'path/to/pact2')

        mock_path_exists.assert_called_with('path/to/pact2')

    @patch("pact.verify_wrapper.VerifyWrapper.call_verify", return_value=(0, None))
    @patch('pact.verifier.expand_directories', return_value=['./pacts/pact1', './pacts/pact2'])
    @patch('pact.verifier.path_exists', return_value=True)
    def test_expand_directories_called_for_pacts(self, mock_path_exists, mock_expand_dir, mock_wrapper):
        output, _ = self.verifier.verify_pacts('path/to/pact1',
                                               'path/to/pact2')

        mock_expand_dir.assert_called_once()

    @patch('pact.verify_wrapper.VerifyWrapper.call_verify', return_value=(0, None))
    def test_passes_enable_pending_flag_value(self, mock_wrapper):
        for value in (True, False):
            with self.subTest(value=value):
                with patch('pact.verifier.path_exists'):
                    self.verifier.verify_pacts('any.json', enable_pending=value)
                self.assertTrue(
                    ('enable_pending', value) in mock_wrapper.call_args.kwargs.items(),
                    mock_wrapper.call_args.kwargs,
                )

    @patch('pact.verify_wrapper.VerifyWrapper.call_verify', return_value=(0, None))
    @patch('pact.verifier.path_exists', return_value=True)
    def test_passes_include_wip_pacts_since_value(self, mock_path_exists, mock_wrapper):
        self.verifier.verify_pacts('any.json', include_wip_pacts_since='2018-01-01')
        self.assertTrue(
            ('include_wip_pacts_since', '2018-01-01') in mock_wrapper.call_args.kwargs.items(),
            mock_wrapper.call_args.kwargs,
        )
Esempio n. 3
0
class VerifierTestCase(TestCase):
    def setUp(self):
        super(VerifierTestCase, self).setUp()
        self.addCleanup(patch.stopall)
        self.verifier = Verifier(provider='test_provider',
                                 provider_base_url="http://*****:*****@patch('pact.verifier.path_exists', return_value=True)
    @patch('pact.verifier.sanitize_logs')
    def test_verifier_with_provider_and_files(self, mock_sanitize_logs,
                                              mock_path_exists):
        self.mock_wrapper.return_value = (True, 'some logs')

        output, _ = self.verifier.verify_pacts('path/to/pact1',
                                               'path/to/pact2')

        self.assertTrue(output)
        self.assertEqual(self.mock_wrapper.call_count, 1)
        args, kwargs = self.mock_wrapper.call_args
        self.assertEquals('path/to/pact1', args[0])
        self.assertEquals('path/to/pact2', args[1])
        self.assertDictEqual(
            {
                'provider': 'test_provider',
                'provider_base_url': 'http://*****:*****@patch('pact.verifier.sanitize_logs')
    def test_verifier_with_broker(self, mock_sanitize_logs):
        pact_broker_username = '******'
        pact_broker_password = '******'
        self.mock_wrapper.return_value = (True, 'ddf')

        output, _ = self.verifier.verify_with_broker(
            broker_username=pact_broker_username,
            broker_password=pact_broker_password,
            broker_url='http://broker')

        self.assertTrue(output)
        self.assertEqual(self.mock_wrapper.call_count, 1)
        args, kwargs = self.mock_wrapper.call_args

        self.assertEquals(len(args), 0)
        self.assertDictEqual(
            {
                'provider': 'test_provider',
                'provider_base_url': 'http://*****:*****@patch('pact.verifier.path_exists', return_value=False)
    def test_raises_error_on_missing_pact_files(self, mock_path_exists):
        self.assertRaises(Exception, self.verifier.verify_pacts,
                          'path/to/pact1', 'path/to/pact2')

        mock_path_exists.assert_called_with('path/to/pact2')

    def test_validate_on_publish_results(self):
        self.assertRaises(Exception,
                          self.verifier.verify_pacts,
                          'path/to/pact1',
                          publish=True)

    @patch('pact.verifier.path_exists', return_value=True)
    @patch('pact.verifier.sanitize_logs')
    @unittest.skip("demonstrating skipping")
    def test_publish_on_success(self, mock_path_exists, mock_sanitize_logs):
        self.mock_wrapper.return_value = (True, 'some logs')

        result = self.verifier.verify_pacts('path/to/pact1',
                                            publish=True,
                                            publish_version='1.0.0')
        print(result)  # todo

    @patch('pact.verifier.path_exists', return_value=True)
    @patch('pact.verifier.sanitize_logs')
    @patch('pact.verifier.expand_directories',
           return_value='./pacts/consumer-provider.json')
    def test_expand_directories_called(self, mock_expand_dirs,
                                       mock_sanitize_logs, mock_path_exists):
        self.mock_wrapper.return_value = (True, 'some logs')

        output, _ = self.verifier.verify_pacts('path/to/pact1',
                                               'path/to/pact2')

        mock_expand_dirs.assert_called_once()

    @patch('pact.verifier.path_exists', return_value=True)
    @patch('pact.verifier.sanitize_logs')
    @patch('pact.verifier.expand_directories',
           return_value='./pacts/consumer-provider.json')
    @patch('pact.verifier.rerun_command')
    @unittest.skip('should be in wrapper now')
    def test_rerun_command_called(self, mock_rerun_cmd, mock_expand_dirs,
                                  mock_sanitize_logs, mock_path_exists):
        self.mock_wrapper.return_value = (True, 'some logs')

        output, _ = self.verifier.verify_pacts('path/to/pact1',
                                               'path/to/pact2')

        mock_rerun_cmd.assert_called_once()