示例#1
0
    def test_all_url_options(self, mock_isfile):
        self.mock_Popen.return_value.returncode = 0
        wrapper = VerifyWrapper()

        result, output = wrapper.call_verify('./pacts/consumer-provider5.json',
                                             './pacts/consumer-provider3.json',
                                             provider_base_url='http://localhost',
                                             provider_states_setup_url='http://localhost/provider-states/set',
                                             provider='provider',
                                             publish_verification_results=True,
                                             provider_app_version='1.2.3',
                                             custom_provider_headers=['Authorization: Basic cGFj', 'CustomHeader: somevalue'],
                                             log_dir='tmp/logs/pact.test.log',
                                             log_level='INFO',
                                             timeout=60,
                                             verbose=True)

        self.assertEqual(result, 0)
        self.mock_Popen.return_value.wait.assert_called_once_with()
        self.assertEqual(self.mock_Popen.call_count, 1)
        self.assertProcess(
            './pacts/consumer-provider5.json',
            './pacts/consumer-provider3.json',
            '--custom-provider-header=Authorization: Basic cGFj',
            '--custom-provider-header=CustomHeader: somevalue',
            '--provider-base-url=http://localhost',
            '--provider-states-setup-url=http://localhost/provider-states/set',
            '--provider=provider',
            '--publish-verification-results',
            '--provider-app-version', '1.2.3',
            '--log-dir=tmp/logs/pact.test.log',
            '--log-level=INFO',
            '--verbose')
示例#2
0
    def test_pact_urls_or_broker_required(self):
        self.mock_Popen.return_value.returncode = 2
        wrapper = VerifyWrapper()

        with self.assertRaises(PactException) as context:
            wrapper.call_verify(provider='provider', provider_base_url='http://localhost')

        self.assertTrue('Pact urls or Pact broker required' in context.exception.message)
示例#3
0
    def test_sanitize_called(self, mock_rerun_cmd, mock_expand_dirs, mock_sanitize_logs, mock_path_exists):
        self.mock_Popen.return_value.returncode = 0
        wrapper = VerifyWrapper()

        result, output = wrapper.call_verify('path/to/pact1',
                                             'path/to/pact2',
                                             provider_base_url='http://localhost',
                                             provider='provider')

        mock_sanitize_logs.assert_called_with(self.mock_Popen.return_value, False)
 def test_broker_without_authentication_can_be_used(self):
     self.mock_Popen.return_value.returncode = 0
     wrapper = VerifyWrapper()
     wrapper.call_verify(provider='provider',
                         provider_base_url='http://localhost',
                         broker_url='http://broker.example.com')
     self.assertProcess(*[
         '--provider-base-url=http://localhost',
         '--provider=provider',
         '--pact-broker-base-url=http://broker.example.com',
     ])
示例#5
0
    def test_pact_urls_provided(self):
        self.mock_Popen.return_value.returncode = 0
        wrapper = VerifyWrapper()

        result, output = wrapper.call_verify('./pacts/consumer-provider.json',
                                             './pacts/consumer-provider2.json',
                                             provider='test_provider',
                                             provider_base_url='http://localhost')

        self.assertProcess(*self.default_call)
        self.assertEqual(result, 0)
示例#6
0
    def test_publishing_with_version(self, mock_sanitize_logs, mock_path_exists):
        self.mock_Popen.return_value.returncode = 0
        wrapper = VerifyWrapper()

        result, output = wrapper.call_verify('./pacts/consumer-provider.json',
                                             './pacts/consumer-provider2.json',
                                             provider='test_provider',
                                             provider_base_url='http://localhost',
                                             provider_app_version='1.2.3'
                                             )
        self.default_call.extend(['--provider-app-version', '1.2.3', '--publish-verification-results'])

        self.assertProcess(*self.default_call)
        self.assertEqual(result, 0)
示例#7
0
    def test_uses_broker_if_no_pacts_and_provider_required(self):
        self.mock_Popen.return_value.returncode = 0
        wrapper = VerifyWrapper()

        result, output = wrapper.call_verify(provider='test_provider',
                                             provider_base_url='http://localhost',
                                             broker_username='******',
                                             broker_password='******',
                                             broker_url='http://broker',
                                             consumer_tags=['prod', 'dev'],
                                             provider_tags=['dev', 'qa'])

        self.assertProcess(*self.broker_call)
        self.assertEqual(result, 0)
示例#8
0
    def verify_with_broker(self,
                           enable_pending=False,
                           include_wip_pacts_since=None,
                           **kwargs):
        """Use Broker to verify.

        Args:
            broker_username ([String]): broker username
            broker_password ([String]): broker password
            broker_url ([String]): url of broker
            enable_pending ([Boolean])
            include_wip_pacts_since ([String])

        """
        broker_username = kwargs.get('broker_username', None)
        broker_password = kwargs.get('broker_password', None)
        broker_url = kwargs.get('broker_url', None)
        broker_token = kwargs.get('broker_token', None)

        options = {
            'broker_password': broker_password,
            'broker_username': broker_username,
            'broker_token': broker_token,
            'broker_url': broker_url
        }
        options.update(self.extract_params(**kwargs))

        success, logs = VerifyWrapper().call_verify(
            provider=self.provider,
            provider_base_url=self.provider_base_url,
            enable_pending=enable_pending,
            include_wip_pacts_since=include_wip_pacts_since,
            **options)
        return success, logs
示例#9
0
    def verify_pacts(self,
                     *pacts,
                     enable_pending=False,
                     include_wip_pacts_since=None,
                     **kwargs):
        """Verify our pacts from the provider.

        Returns:
          success: True if no failures
          logs: some tbd output of logs

        """
        self.validate_publish(**kwargs)

        missing_files = [path for path in pacts if not path_exists(path)]
        if missing_files:
            raise Exception("Missing pact files {}".format(missing_files))

        pacts = expand_directories(pacts)
        missing_files = [path for path in pacts if not path_exists(path)]

        # rerun_command()  # env =

        options = self.extract_params(**kwargs)
        success, logs = VerifyWrapper().call_verify(
            *pacts,
            provider=self.provider,
            provider_base_url=self.provider_base_url,
            enable_pending=enable_pending,
            include_wip_pacts_since=include_wip_pacts_since,
            **options)

        return success, logs
示例#10
0
    def verify_pacts(self, *pacts, **kwargs):
        """Verify our pacts from the provider.

        Returns:
          success: True if no failures
          logs: some tbd output of logs

        """
        self.validate_publish(**kwargs)
        verbose = kwargs.get('verbose', False)

        missing_files = [path for path in pacts if not path_exists(path)]
        if missing_files:
            raise Exception("Missing pact files {}".format(missing_files))

        pacts = expand_directories(pacts)

        # rerun_command()  # env =

        success, logs = VerifyWrapper().call_verify(*pacts,
                                                    provider=self.provider,
                                                    provider_base_url=self.provider_base_url)

        sanitize_logs(logs, verbose)
        return success, logs
示例#11
0
    def verify_with_broker(self, broker_username, broker_password, broker_url, **kwargs):
        """Use Broker to verify.

        Args:
            broker_username ([String]): broker username
            broker_password ([String]): broker password
            broker_url ([String]): url of broker

        """
        verbose = kwargs.get('verbose', False)

        success, logs = VerifyWrapper().call_verify(broker_username=broker_username,
                                                    broker_password=broker_password,
                                                    broker_url=broker_url,
                                                    provider=self.provider,
                                                    provider_base_url=self.provider_base_url)
        sanitize_logs(logs, verbose)

        return success, logs
示例#12
0
def main(pacts, base_url, pact_url, pact_urls, states_url, states_setup_url,
         username, broker_base_url, consumer_version_tag,
         consumer_version_selector, provider_version_tag, password, token,
         provider, headers, timeout, provider_app_version,
         publish_verification_results, verbose, log_dir, log_level,
         enable_pending, include_wip_pacts_since):
    """
    Verify one or more contracts against a provider service.

    Minimal example:
        pact-verifier --provider-base-url=http://localhost:8080 ./pacts
    """  # NOQA
    error = click.style('Error:', fg='red')
    warning = click.style('Warning:', fg='yellow')
    all_pact_urls = list(pacts) + list(pact_url)

    for urls in pact_urls:  # Remove in major version 1.0.0
        all_pact_urls.extend(p for p in urls.split(',') if p)

    if len(pact_urls) > 1:
        click.echo(
            warning + ' Multiple --pact-urls arguments are deprecated. ' +
            'Please provide a comma separated list of pacts to --pact-urls, ' +
            'or multiple --pact-url arguments.')

    if not all_pact_urls and broker_not_provided(broker_base_url, provider):
        click.echo(error +
                   ' You must supply at least one pact file or directory ' +
                   'to verify OR a Pact Broker and Provider.')
        raise click.Abort()

    all_pact_urls = expand_directories(all_pact_urls)

    missing_files = [path for path in all_pact_urls if not path_exists(path)]
    if missing_files:
        click.echo(error + ' The following Pact files could not be found:\n' +
                   '\n'.join(missing_files))
        raise click.Abort()

    if publish_verification_results:
        publish_results(error, provider_app_version)

    options = {
        'broker_password': password,
        'broker_username': username,
        'broker_token': token,
        'broker_url': broker_base_url,
        'log_dir': log_dir,
        'log_level': log_level,
        'provider_app_version': provider_app_version,
        'custom_provider_headers': list(headers),
        'timeout': timeout,
        'verbose': verbose,
        'consumer_tags': list(consumer_version_tag),
        'consumer_selectors': list(consumer_version_selector),
        'provider_tags': list(provider_version_tag),
        'provider_states_setup_url': states_setup_url,
    }

    options = dict(filter(lambda item: item[1] is not None, options.items()))
    options = dict(filter(lambda item: item[1] != '', options.items()))
    options = dict(filter(lambda item: is_empty_list(item), options.items()))

    success, logs = VerifyWrapper().call_verify(
        *all_pact_urls,
        provider=provider,
        provider_base_url=base_url,
        enable_pending=enable_pending,
        include_wip_pacts_since=include_wip_pacts_since,
        **options)
    sys.exit(success)