diff --git a/examples/e2e/conftest.py b/examples/e2e/conftest.py index 76c83f55a9..5979211145 100644 --- a/examples/e2e/conftest.py +++ b/examples/e2e/conftest.py @@ -14,6 +14,11 @@ def pytest_addoption(parser): help="The url to our provider." ) + parser.addoption( + "--run-broker", type=bool, action="store", + help="Whether to run broker in this test or not." + ) + # This fixture is to simulate a managed Pact Broker or Pactflow account # Do not do this yourself but setup one of the above # https://github.com/pact-foundation/pact_broker @@ -27,13 +32,19 @@ def broker(request): yield return - print('Starting broker') - with DockerCompose("../broker", - compose_file_name=["docker-compose.yml"], - pull=True) as compose: + run_broker = request.config.getoption('--run-broker') - stdout, stderr = compose.get_logs() - if stderr: - print("Errors\\n:{}".format(stderr)) - print(stdout) + if not run_broker: yield + return + else: + print('Starting broker') + with DockerCompose("../broker", + compose_file_name=["docker-compose.yml"], + pull=True) as compose: + + stdout, stderr = compose.get_logs() + if stderr: + print("Errors\\n:{}".format(stderr)) + print(stdout) + yield diff --git a/examples/e2e/run_pytest.sh b/examples/e2e/run_pytest.sh index 212b1e4c83..f1a55023ac 100755 --- a/examples/e2e/run_pytest.sh +++ b/examples/e2e/run_pytest.sh @@ -13,7 +13,7 @@ trap teardown EXIT sleep 3 -pytest contract_tests --publish-pact 1 +pytest tests --run-broker True --publish-pact 1 teardown diff --git a/examples/e2e/tests/provider/test_provider.py b/examples/e2e/tests/provider/test_provider.py index 0397bb1bce..1cd15206d9 100644 --- a/examples/e2e/tests/provider/test_provider.py +++ b/examples/e2e/tests/provider/test_provider.py @@ -29,7 +29,9 @@ def default_opts(): return { 'broker_username': PACT_BROKER_USERNAME, 'broker_password': PACT_BROKER_PASSWORD, - 'broker_url': PACT_BROKER_URL + 'broker_url': PACT_BROKER_URL, + 'publish_version': '3', + 'publish_verification_results': True } diff --git a/pact/cli/verify.py b/pact/cli/verify.py index 996d6a6c39..e597e1e0c1 100644 --- a/pact/cli/verify.py +++ b/pact/cli/verify.py @@ -164,7 +164,7 @@ def main(pacts, base_url, pact_url, pact_urls, states_url, states_setup_url, raise click.Abort() if publish_verification_results: - publish_results(error, provider_app_version) + validate_publish(error, provider_app_version) options = { 'broker_password': password, @@ -196,7 +196,7 @@ def main(pacts, base_url, pact_url, pact_urls, states_url, states_setup_url, sys.exit(success) -def publish_results(error, provider_app_version): +def validate_publish(error, provider_app_version): """Publish results to broker.""" if not provider_app_version: click.echo( diff --git a/pact/verifier.py b/pact/verifier.py index a9642aee82..13222483c1 100644 --- a/pact/verifier.py +++ b/pact/verifier.py @@ -70,6 +70,7 @@ def verify_with_broker(self, enable_pending=False, include_wip_pacts_since=None, broker_url ([String]): url of broker enable_pending ([Boolean]) include_wip_pacts_since ([String]) + publish_version ([String]) """ broker_username = kwargs.get('broker_username', None) @@ -103,8 +104,8 @@ def extract_params(self, **kwargs): provider_tags = kwargs.get('provider_tags', []) states_setup_url = kwargs.get('provider_states_setup_url', None) verbose = kwargs.get('verbose', False) - publish_version = kwargs.get('publish_version', None) - + provider_app_version = kwargs.get('publish_version', None) + publish_verification_results = kwargs.get('publish_verification_results', None) raw_consumer_selectors = kwargs.get('consumer_version_selectors', []) consumer_selectors = self._build_consumer_selectors(raw_consumer_selectors) @@ -118,8 +119,9 @@ def extract_params(self, **kwargs): 'provider_tags': list(provider_tags), 'provider_states_setup_url': states_setup_url, 'verbose': verbose, - 'publish_version': publish_version, - 'consumer_selectors': consumer_selectors + 'provider_app_version': provider_app_version, + 'consumer_selectors': consumer_selectors, + 'publish_verification_results': publish_verification_results } return self.filter_empty_options(**options) diff --git a/tests/test_verifier.py b/tests/test_verifier.py index 0639ab3cd1..3a28c3de64 100644 --- a/tests/test_verifier.py +++ b/tests/test_verifier.py @@ -89,7 +89,7 @@ def test_publish_on_success(self, mock_path_exists, mock_wrapper): provider_base_url='http://localhost:8888', log_level='INFO', verbose=False, - publish_version='1.0.0', + provider_app_version='1.0.0', enable_pending=False, include_wip_pacts_since=None) @@ -171,6 +171,28 @@ def test_verifier_with_broker(self, mock_wrapper): enable_pending=False, include_wip_pacts_since=None) + @patch("pact.verify_wrapper.VerifyWrapper.call_verify") + def test_verifier_and_pubish_with_broker(self, mock_wrapper): + + mock_wrapper.return_value = (True, 'some value') + + self.default_opts['publish_verification_results'] = True + output, _ = self.verifier.verify_with_broker(**self.default_opts) + + self.assertTrue(output) + assertVerifyCalled(mock_wrapper, + provider='test_provider', + provider_base_url='http://localhost:8888', + broker_password=self.broker_password, + broker_username=self.broker_username, + broker_token='token', + broker_url=self.broker_url, + log_level='INFO', + verbose=False, + enable_pending=False, + include_wip_pacts_since=None, + publish_verification_results=True) + @patch("pact.verify_wrapper.VerifyWrapper.call_verify") def test_verifier_with_broker_passes_consumer_selctors(self, mock_wrapper): @@ -216,7 +238,7 @@ def test_publish_on_success(self, mock_path_exists, mock_wrapper): broker_url=self.broker_url, log_level='INFO', verbose=False, - publish_version='1.0.0', + provider_app_version='1.0.0', enable_pending=False, include_wip_pacts_since=None)