Skip to content

Commit

Permalink
Error message for non extending PactHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
Guido Barbaglia committed Aug 23, 2017
1 parent ff821be commit b550157
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 3 deletions.
9 changes: 8 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,11 @@ possible to test all the versions at once with:

.. code:: bash
$ ./bin/test all
$ ./bin/test all
Upload New Version
------------------

.. code:: bash
$ python3 setup.py sdist upload
1 change: 1 addition & 0 deletions pact_test/constants/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
MISSING_SETUP = 'Missing "setup" method in "pact_helper.py".'
MISSING_HAS_PACT_WITH = 'Missing setup for "has_pact_with" at '
MISSING_TEAR_DOWN = 'Missing "tear_down" method in "pact_helper.py".'
EXTEND_PACT_HELPER = 'Pact Helper class must extend pact_test.PactHelper'
3 changes: 3 additions & 0 deletions pact_test/utils/pact_helper_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pact_test import PactHelper
from pact_test.constants import MISSING_SETUP
from pact_test.constants import MISSING_TEAR_DOWN
from pact_test.constants import EXTEND_PACT_HELPER
from pact_test.constants import MISSING_PACT_HELPER


Expand All @@ -21,6 +22,8 @@ def _load_user_class(user_module):
if inspect.isclass(obj) and len(inspect.getmro(obj)) > 2 and issubclass(obj, PactHelper):
user_class = obj()

if user_class is None:
return Left(EXTEND_PACT_HELPER)
if hasattr(user_class, 'setup') is False:
return Left(MISSING_SETUP)
if hasattr(user_class, 'tear_down') is False:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name='pact-test',
version='0.1.2',
version='0.1.7',
author='Guido Barbaglia',
author_email='guido.barbaglia@gmail.com',
packages=find_packages(),
Expand Down
3 changes: 3 additions & 0 deletions tests/resources/pact_helper_no_super_class/pact_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class MyPactHelper(object):
def setup(self):
pass
13 changes: 12 additions & 1 deletion tests/utils/pact_helper_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def test_load_user_class_missing_setup():

def test_load_user_class_missing_tear_down():
consumer_tests_path = os.path.join(os.getcwd(), 'tests',
'resources', 'pact_helper_no_tear_down')
'resources',
'pact_helper_no_tear_down')
pact_helper = load_pact_helper(consumer_tests_path).value

error_message = 'Missing "tear_down" method in "pact_helper.py".'
Expand All @@ -51,3 +52,13 @@ def test_load_pact_helper():
'resources', 'pact_helper')
pact_helper = load_pact_helper(consumer_tests_path).value
assert issubclass(pact_helper.__class__, PactHelper)


def test_not_extending_pact_helper():
consumer_tests_path = os.path.join(os.getcwd(), 'tests',
'resources',
'pact_helper_no_super_class')
pact_helper = load_pact_helper(consumer_tests_path).value

error_message = 'Pact Helper class must extend pact_test.PactHelper'
assert pact_helper == error_message

0 comments on commit b550157

Please sign in to comment.