Beispiel #1
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
Beispiel #2
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
Beispiel #3
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)
 def test_path_exists_valid_for_https(self):
     self.assertTrue(path_exists('https://someurl'))
 def test_path_not_exists(self):
     self.assertFalse(path_exists('not_a_real_file'))
 def test_path_exists(self):
     self.assertTrue(path_exists('README.md'))