Skip to content

Commit

Permalink
Merge pull request #32 from SimKev2/pacturls
Browse files Browse the repository at this point in the history
Issue: Cannot supply multiple files to pact-verifier
  • Loading branch information
matthewbalvanz-wf authored Jul 16, 2017
2 parents e382eb4 + b6e1a8b commit 223ea76
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ local_settings.py
instance/
.webassets-cache

# Intellij stuff
.idea/

# Scrapy stuff:
.scrapy

Expand Down
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ The simplest example is verifying a server with locally stored Pact files and no
states:

```bash
pact-verifier --provider-base-url=http://localhost:8080 --pact-urls=./pacts/consumer-provider.json
pact-verifier --provider-base-url=http://localhost:8080 --pact-url=./pacts/consumer-provider.json
```

Which will immediately invoke the Pact verifier, making HTTP requests to the server located
Expand All @@ -235,10 +235,20 @@ There are several options for configuring how the Pacts are verified:

Required. Defines the URL of the server to make requests to when verifying the Pacts.

###### --pact-url

Required if --pact-urls not specified. The location of a Pact file you want
to verify. This can be a URL to a [Pact Broker] or a local path, to provide
multiple files, specify multiple arguments.

```
pact-verifier --provider-base-url=http://localhost:8080 --pact-url=./pacts/one.json --pact-url=./pacts/two.json
```

###### --pact-urls

Required. The location of the Pact files you want to verify. This can be a URL to a [Pact Broker]
or one or more local paths, separated by a comma.
Required if --pact-url not specified. The location of the Pact files you want
to verify. This can be a URL to a [Pact Broker] or one or more local paths, separated by a comma.

###### --provider-states-url

Expand Down
2 changes: 1 addition & 1 deletion pact/__version__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Pact version info."""

__version__ = '0.6.2'
__version__ = '0.7.0'
40 changes: 34 additions & 6 deletions pact/test/test_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,14 @@ def setUp(self):
self.runner = CliRunner()
self.default_call = [
'--provider-base-url=http://localhost',
'--pact-urls=./pacts/consumer-provider.json']
'--pact-urls=./pacts/consumer-provider.json,'
'./pacts/consumer-provider2.json,./pacts/consumer-provider3.json']

self.default_opts = [
'--provider-base-url=http://localhost',
'--pact-urls=./pacts/consumer-provider.json']
'--pact-url=./pacts/consumer-provider.json',
'--pact-urls=./pacts/consumer-provider2.json,'
'./pacts/consumer-provider3.json']

def assertProcess(self, *expected):
self.assertEqual(self.mock_Popen.call_count, 1)
Expand All @@ -59,8 +62,9 @@ def test_provider_base_url_is_required(self):
def test_pact_urls_are_required(self):
result = self.runner.invoke(
verify.main, ['--provider-base-url=http://localhost'])
self.assertEqual(result.exit_code, 2)
self.assertIn(b'--pact-urls', result.output_bytes)
print(result)
self.assertEqual(result.exit_code, 1)
self.assertIn(b'--pact-url or --pact-urls', result.output_bytes)
self.assertFalse(self.mock_Popen.called)

def test_local_pact_urls_must_exist(self):
Expand Down Expand Up @@ -121,7 +125,10 @@ def test_all_options(self):
self.mock_Popen.return_value.returncode = 0
result = self.runner.invoke(verify.main, [
'--provider-base-url=http://localhost',
'--pact-urls=./pacts/consumer-provider.json',
'--pact-urls=./pacts/consumer-provider.json,'
'./pacts/consumer-provider2.json',
'--pact-url=./pacts/consumer-provider3.json',
'--pact-url=./pacts/consumer-provider4.json',
'--provider-states-url=http=//localhost/provider-states',
'--provider-states-setup-url=http://localhost/provider-states/set',
'--pact-broker-username=user',
Expand All @@ -132,14 +139,35 @@ def test_all_options(self):
self.assertEqual(self.mock_Popen.call_count, 1)
self.assertProcess(
'--provider-base-url=http://localhost',
'--pact-urls=./pacts/consumer-provider.json',
'--pact-urls=./pacts/consumer-provider3.json,'
'./pacts/consumer-provider4.json,'
'./pacts/consumer-provider.json,./pacts/consumer-provider2.json',
'--provider-states-url=http=//localhost/provider-states',
'--provider-states-setup-url=http://localhost/provider-states/set',
'--broker-username=user',
'--broker-password=pass')
self.mock_Popen.return_value.communicate.assert_called_once_with(
timeout=60)

def test_deprecated_pact_urls(self):
self.mock_Popen.return_value.returncode = 0
result = self.runner.invoke(verify.main, [
'--provider-base-url=http://localhost',
'--pact-urls=./pacts/consumer-provider.json',
'--pact-urls=./pacts/consumer-provider2.json'
])
self.assertEqual(result.exit_code, 0)
self.assertIn(
b'Multiple --pact-urls arguments are deprecated.',
result.output_bytes)
self.assertEqual(self.mock_Popen.call_count, 1)
self.assertProcess(
'--provider-base-url=http://localhost',
'--pact-urls=./pacts/consumer-provider.json,'
'./pacts/consumer-provider2.json')
self.mock_Popen.return_value.communicate.assert_called_once_with(
timeout=30)


class path_existsTestCase(TestCase):
def setUp(self):
Expand Down
38 changes: 31 additions & 7 deletions pact/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@
help='Base URL of the provider to verify against.',
required=True)
@click.option(
'pact_urls', '--pact-urls',
'pact_url', '--pact-url',
help='The URI of the pact to verify.'
' Can be an HTTP URI or a local file path.'
' It can be specified multiple times to verify several pacts.',
multiple=True,
required=True)
multiple=True)
@click.option(
'pact_urls', '--pact-urls',
default='',
help='The URI(s) of the pact to verify.'
' Can be an HTTP URI(s) or local file path(s).'
' Provide multiple URI separated by a comma.',
multiple=True) # Remove in major version 1.0.0
@click.option(
'states_url', '--provider-states-url',
help='URL to fetch the provider states for the given provider API.')
Expand All @@ -44,24 +50,42 @@
help='The duration in seconds we should wait to confirm verification'
' process was successful. Defaults to 30.',
type=int)
def main(base_url, pact_urls, states_url, states_setup_url, username,
def main(base_url, pact_url, pact_urls, states_url, states_setup_url, username,
password, timeout):
"""
Verify one or more contracts against a provider service.
Minimal example:
pact-verifier --provider-base-url=http://localhost:8080 --pact-urls=./pacts
pact-verifier --provider-base-url=http://localhost:8080 --pact-url=./pact
""" # NOQA
error = click.style('Error:', fg='red')
warning = click.style('Warning:', fg='yellow')
if bool(states_url) != bool(states_setup_url):
click.echo(
error
+ ' To use provider states you must provide both'
' --provider-states-url and --provider-states-setup-url.')
raise click.Abort()

missing_files = [path for path in pact_urls if not path_exists(path)]
all_pact_urls = 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:
click.echo(
error
+ ' At least one of --pact-url or --pact-urls is required.')
raise click.Abort()

missing_files = [path for path in all_pact_urls if not path_exists(path)]
if missing_files:
click.echo(
error
Expand All @@ -71,7 +95,7 @@ def main(base_url, pact_urls, states_url, states_setup_url, username,

options = {
'--provider-base-url': base_url,
'--pact-urls': ','.join(pact_urls),
'--pact-urls': ','.join(all_pact_urls),
'--provider-states-url': states_url,
'--provider-states-setup-url': states_setup_url,
'--broker-username': username,
Expand Down

0 comments on commit 223ea76

Please sign in to comment.