Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support pending Pacts #171

Merged
merged 8 commits into from
Sep 9, 2020

Conversation

m-aciek
Copy link
Contributor

@m-aciek m-aciek commented Sep 3, 2020

Closes #164.

Maciej Olko added 2 commits September 3, 2020 17:42
@m-aciek m-aciek force-pushed the enable-pending branch 3 times, most recently from 915e278 to 80e90f6 Compare September 3, 2020 15:59
@matthewbalvanz-wf
Copy link
Contributor

@m-aciek mock should be part of the Python standard library from 3.3 and above, maybe we could remove that entirely now that support for Python 2.7 has been removed?
https://docs.python.org/3/library/unittest.mock.html

@m-aciek
Copy link
Contributor Author

m-aciek commented Sep 3, 2020

@matthewbalvanz-wf Unfortunately in 3.4 and 3.5 mock that is shipped with unittest has different API than in 3.8 so the asserts in VerifyWrapper tests fail.

@m-aciek m-aciek closed this Sep 3, 2020
@m-aciek m-aciek reopened this Sep 3, 2020
@m-aciek m-aciek marked this pull request as draft September 4, 2020 06:54
@m-aciek m-aciek force-pushed the enable-pending branch 2 times, most recently from e256b9d to a344f3d Compare September 4, 2020 10:48
@m-aciek m-aciek marked this pull request as ready for review September 4, 2020 10:49
@click.option(
'log_dir', '--log-dir',
help='The directory for the pact.log file.')
@click.option(
'log_level', '--log-level',
help='The logging level.')
@click.option(
'enable_pending', '--enable-pending/--no-enable-pending',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about 'pending', '--pending/--no-pending',default=False
is_flag=True will be passed implicitly if a boolean flag is used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to replicate the flag that is used in underlying CLI and to be in line with flag name used in documentation https://docs.pact.io/pact_broker/advanced_topics/pending_pacts/#to-start-using-the-pending-pacts-feature.

I used default=None also to replicate usage of underlying CLI so to map False -> --enable…, True -> --no-enable…, None -> no flag.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. you are right. It is said to use enable-pending convention: Master issue for new 'pending pacts' feature pact_broker#320
  2. it is also said that flag should be set to False as a default value. Moreover I do not see a case when no flag differs from no-enable-pending

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so to be in line with the guidelines you linked and to make the implementation minimal, I will stick only with positive flag, set False as default and do not add --no-enable-pending to underlying library.

@@ -199,3 +200,11 @@ def publish_results(self, provider_app_version, command):
command.extend(["--provider-app-version",
provider_app_version,
"--publish-verification-results"])

@classmethod
def _get_enable_pending_flag(cls, flag_value):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about

def _get_boolean_flag(self, flags, flag_name):
    flag_value = flags.get(flag_name)
    if flag_value is True:
        return ['--' + flag_name]
    elif flag_value is False:
        return ['--no-' + flag_name]
    return []

Copy link
Contributor Author

@m-aciek m-aciek Sep 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no such a flag as --no-verbose, and for just one case I think it is a premature optimisation.

@@ -169,6 +169,7 @@ def call_verify(self, *pacts, provider_base_url, provider, **kwargs):

if(kwargs.get('verbose', False) is True):
command.extend(['--verbose'])
command.extend(self._get_enable_pending_flag(kwargs.get('enable_pending')))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_get_boolean_flag('pending')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no such a flag as --no-verbose, and for just one case I think it is a premature optimisation.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is lacking in the ruby verifier help message (see https://github.com/pact-foundation/pact-provider-verifier/blob/master/README.md), but I checked and indeed this ruby binary accepts --no-verbose. Although according to #171 (comment) I'll drop the negative flag passing.

@@ -169,6 +169,7 @@ def call_verify(self, *pacts, provider_base_url, provider, **kwargs):

if(kwargs.get('verbose', False) is True):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

command.extend(self. _get_boolean_flag('verbose'))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no such a flag as --no-verbose, and for just one case I think it is a premature optimisation.

@m-aciek
Copy link
Contributor Author

m-aciek commented Sep 4, 2020

@matthewbalvanz-wf Summary of failing tests because of mock in 3.5 compatibility issues:

Error
Traceback (most recent call last):
  File "/Users/maciek/.pyenv/versions/3.5.9/lib/python3.5/unittest/case.py", line 59, in testPartExecutor
    yield
  File "/Users/maciek/.pyenv/versions/3.5.9/lib/python3.5/unittest/case.py", line 605, in run
    testMethod()
  File "/Users/maciek/.pyenv/versions/3.5.9/lib/python3.5/unittest/mock.py", line 1159, in patched
    return func(*args, **keywargs)
  File "/Users/maciek/projects/pact-python/tests/cli/test_verify.py", line 122, in test_broker_url_and_provider_required
    mock_wrapper.assert_called()
  File "/Users/maciek/.pyenv/versions/3.5.9/lib/python3.5/unittest/mock.py", line 585, in __getattr__
    raise AttributeError(name)
AttributeError: assert_called

Error
Traceback (most recent call last):
  File "/Users/maciek/.pyenv/versions/3.5.9/lib/python3.5/unittest/case.py", line 59, in testPartExecutor
    yield
  File "/Users/maciek/.pyenv/versions/3.5.9/lib/python3.5/unittest/case.py", line 605, in run
    testMethod()
  File "/Users/maciek/.pyenv/versions/3.5.9/lib/python3.5/unittest/mock.py", line 1159, in patched
    return func(*args, **keywargs)
  File "/Users/maciek/projects/pact-python/tests/cli/test_verify.py", line 339, in test_expand_directories_called
    mock_expand_dirs.assert_called_once()
  File "/Users/maciek/.pyenv/versions/3.5.9/lib/python3.5/unittest/mock.py", line 585, in __getattr__
    raise AttributeError(name)
AttributeError: assert_called_once

Error
Traceback (most recent call last):
  File "/Users/maciek/.pyenv/versions/3.5.9/lib/python3.5/unittest/case.py", line 59, in testPartExecutor
    yield
  File "/Users/maciek/.pyenv/versions/3.5.9/lib/python3.5/unittest/case.py", line 605, in run
    testMethod()
  File "/Users/maciek/.pyenv/versions/3.5.9/lib/python3.5/unittest/mock.py", line 1159, in patched
    return func(*args, **keywargs)
  File "/Users/maciek/projects/pact-python/tests/test_verifier.py", line 74, in test_expand_directories_called_for_pacts
    mock_expand_dir.assert_called_once()
  File "/Users/maciek/.pyenv/versions/3.5.9/lib/python3.5/unittest/mock.py", line 585, in __getattr__
    raise AttributeError(name)
AttributeError: assert_called_once

SubTest failure: Traceback (most recent call last):
  File "/…/.pyenv/versions/3.5.9/lib/python3.5/unittest/case.py", line 59, in testPartExecutor
    yield
  File "/…/.pyenv/versions/3.5.9/lib/python3.5/unittest/case.py", line 523, in subTest
    yield
  File "/…/projects/pact-python/tests/test_verifier.py", line 84, in test_passes_enable_pending_flag_value
    mock_wrapper.call_args.kwargs,
  File "/…/.pyenv/versions/3.5.9/lib/python3.5/unittest/case.py", line 682, in assertTrue
    raise self.failureException(msg)
AssertionError: False is not true : kwargs

Error
Traceback (most recent call last):
  File "/…/.pyenv/versions/3.5.9/lib/python3.5/unittest/case.py", line 59, in testPartExecutor
    yield
  File "/…/.pyenv/versions/3.5.9/lib/python3.5/unittest/case.py", line 605, in run
    testMethod()
  File "/…/.pyenv/versions/3.5.9/lib/python3.5/unittest/mock.py", line 1159, in patched
    return func(*args, **keywargs)
  File "/…/pact-python/tests/test_verify_wrapper.py", line 160, in test_rerun_command_called
    mock_rerun_cmd.assert_called_once()
  File "/…/.pyenv/versions/3.5.9/lib/python3.5/unittest/mock.py", line 585, in __getattr__
    raise AttributeError(name)
AttributeError: assert_called_once

@matthewbalvanz-wf
Copy link
Contributor

Looks like assert_called and assert_called_once were added in 3.6, so it seems like using the library until that is end of life is the path forward.

@@ -169,6 +169,7 @@ def call_verify(self, *pacts, provider_base_url, provider, **kwargs):

if(kwargs.get('verbose', False) is True):
command.extend(['--verbose'])
command.extend(self._get_enable_pending_flag(kwargs.get('enable_pending')))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@click.option(
'log_dir', '--log-dir',
help='The directory for the pact.log file.')
@click.option(
'log_level', '--log-level',
help='The logging level.')
@click.option(
'enable_pending', '--enable-pending/--no-enable-pending',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. you are right. It is said to use enable-pending convention: Master issue for new 'pending pacts' feature pact_broker#320
  2. it is also said that flag should be set to False as a default value. Moreover I do not see a case when no flag differs from no-enable-pending

@m-aciek m-aciek force-pushed the enable-pending branch 5 times, most recently from 8247424 to dddc746 Compare September 7, 2020 12:39
@m-aciek
Copy link
Contributor Author

m-aciek commented Sep 7, 2020

I've added Python 3.4 syntax compatibility and simplified code. Ready for review again.

@m-aciek
Copy link
Contributor Author

m-aciek commented Sep 7, 2020

I've fixed code issue with Click option.

@bethesque
Copy link
Member

Would you mind leaving it as --enable-pending and --no-enable-pending in the python interface? When trying to write documentation that is applicable for all languages, it makes it very difficult when each of the 11 languages chooses a slightly different option name!

@elliottmurray
Copy link
Contributor

@bethesque isn't the 'no' option redundant? Just wondering if it should be default off and you just ask --enable-pending but not sure what the plans are for this ongoing?

@m-aciek
Copy link
Contributor Author

m-aciek commented Sep 9, 2020

@bethesque @elliottmurray I had the same doubt and simplified implementation to avoid redundancy.

The use case for --no-enable-pending that I can think of would be having some default configuration (e.g. in pyproject.toml) that could be overridden in a command call.

I plan to implement support for --no-enable-pending on another branch and open new alternative pull request to avoid going round in circles in case of further discussion.

@m-aciek
Copy link
Contributor Author

m-aciek commented Sep 9, 2020

@bethesque @elliottmurray

The use case for --no-enable-pending that I can think of would be having some default configuration (e.g. in pyproject.toml) that could be overridden in a command call.

In this use case default for enable-pending flag would be None, meaning „not overriding some default configuration” in case of no of those flags are added. I'm assuming this in the implementation.

@elliottmurray
Copy link
Contributor

I'm going to merge this and do a release later. It doesn't harm as far as I can tell and we can add the extra flag in another PR

@elliottmurray elliottmurray merged commit 46372c7 into pact-foundation:master Sep 9, 2020
@bethesque
Copy link
Member

Sorry, I don't care about --no-enable-pending, just the --enable-pending (rather than --pending or whatever it was)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support pending pacts
5 participants