Skip to content

Commit 442612d

Browse files
authored
Merge pull request #5 from Kalimaha/pypact-investigation
Pypact investigation
2 parents c975b6b + e0e1bd8 commit 442612d

12 files changed

+164
-1
lines changed

Diff for: .gitignore

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
*.pyc
2+
.cache/
3+
.idea/
4+
build/
5+
pypact.egg-info/
6+
tests/__pycache__/
7+
.eggs/
8+
.coverage
9+
*.log
10+
*.egg
11+
*.iml
12+
pytest_pact.egg-info/
13+
pytest_pact/__pycache__

Diff for: .travis.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
language: python
2+
python:
3+
- 2.7
4+
- 3.3
5+
- 3.4
6+
- 3.5
7+
- 3.6
8+
install:
9+
- "pip install -r requirements.txt"
10+
- "pip install pytest pytest-cov pytest-sugar"
11+
- "pip install coveralls"
12+
- "pip install -e ."
13+
script:
14+
- py.test --cov pytest_pact --cov-report term-missing
15+
after_success:
16+
- coveralls

Diff for: README.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
1-
# pypact
1+
[![Build Status](https://travis-ci.org/Kalimaha/pytest-pact.svg?branch=master)](https://travis-ci.org/Kalimaha/pytest-pact)
2+
[![Coverage Status](https://coveralls.io/repos/github/Kalimaha/pytest-pact/badge.svg?branch=master)](https://coveralls.io/github/Kalimaha/pytest-pact?branch=master)
3+
4+
# PyPact
25
Python implementation for Pact (http://pact.io/)
6+
7+
## Setup
8+
```
9+
python setup.py install
10+
```

Diff for: dist/.keep

Whitespace-only changes.

Diff for: pytest_pact/PyPact.py

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import pytest
2+
3+
4+
state = pytest.mark.state
5+
given = pytest.mark.given
6+
base_uri = pytest.mark.base_uri
7+
pact_uri = pytest.mark.pact_uri
8+
with_request = pytest.mark.with_request
9+
has_pact_with = pytest.mark.has_pact_with
10+
upon_receiving = pytest.mark.upon_receiving
11+
will_respond_with = pytest.mark.will_respond_with
12+
service_consumer = pytest.mark.service_consumer
13+
honours_pact_with = pytest.mark.honours_pact_with
14+
15+
16+
@pytest.hookimpl(hookwrapper=True)
17+
def pytest_pyfunc_call(pyfuncitem):
18+
# print(describe_consumer_pact(pyfuncitem))
19+
20+
# pypact = PyPact()
21+
# pypact.executor(pyfuncitem)
22+
23+
24+
25+
outcome = yield
26+
# outcome.excinfo may be None or a (cls, val, tb) tuple
27+
print(outcome)
28+
29+
res = outcome.get_result() # will raise if outcome was exception
30+
# postprocess result
31+
print(res)
32+
33+
34+
def consumer_or_provider(pyfuncitem):
35+
pass
36+
37+
class PyPactConsumer(object):
38+
pass
39+
40+
class PyPactProvider(object):
41+
pass
42+
43+
44+
def describe_consumer_pact(pyfuncitem):
45+
s = ''
46+
s += 'Given ' + read_marker(pyfuncitem, 'given') + ', '
47+
s += 'upon receiving ' + read_marker(pyfuncitem, 'upon_receiving') + ' '
48+
s += 'from ' + read_marker(pyfuncitem, 'service_consumer') + ' '
49+
s += 'with:\n\n' + read_marker(pyfuncitem, 'with_request') + '\n\n'
50+
s += read_marker(pyfuncitem, 'has_pact_with') + ' will respond with:\n\n'
51+
s += read_marker(pyfuncitem, 'will_respond_with')
52+
return s
53+
54+
def read_marker(pyfuncitem, marker_name):
55+
marker = pyfuncitem.get_marker(marker_name)
56+
return str(marker.args[0]) if marker else ''

Diff for: pytest_pact/__init__.py

Whitespace-only changes.

Diff for: requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pytest>=3.0

Diff for: setup.cfg

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[aliases]
2+
test=pytest

Diff for: setup.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from setuptools import setup
2+
from setuptools import find_packages
3+
4+
setup(
5+
name='pytest-pact',
6+
version='0.1.0',
7+
author='Guido Barbaglia',
8+
author_email='[email protected]',
9+
packages=find_packages(),
10+
license='LICENSE.txt',
11+
long_description=open('README.md').read(),
12+
description='Python implementation for Pact (http://pact.io/)',
13+
install_requires=[],
14+
setup_requires=['pytest-runner'],
15+
tests_require=['pytest', 'pytest-sugar'],
16+
url='https://github.com/Kalimaha/pytest-pact/',
17+
entry_points = {
18+
'pytest11': [
19+
'pytest-pact = pytest_pact.PyPact',
20+
]
21+
}
22+
)

Diff for: tests/__init__.py

Whitespace-only changes.

Diff for: tests/test_books_service.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from pytest_pact.PyPact import *
2+
3+
4+
@base_uri('localhost:1234')
5+
@service_consumer('Library App')
6+
@has_pact_with('Books Service')
7+
class TestBooksService():
8+
9+
expected_response = {
10+
'status': 200,
11+
'headers': {'Content-Type': 'application/json'},
12+
'body': {
13+
'id': '123',
14+
'title': 'A Fortune-Teller Told Me'
15+
}
16+
}
17+
18+
@given('some books exist')
19+
@upon_receiving('a request for a book')
20+
@with_request({'method': 'get', 'path': '/books/123'})
21+
@will_respond_with(expected_response)
22+
def test_get_book(self):
23+
pass

Diff for: tests/test_pypact.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from pytest_pact.PyPact import *
2+
3+
4+
def test_read_existing_marker():
5+
expected_marker = 'some books exist'
6+
class FakeMarker(object):
7+
args = [expected_marker]
8+
class FakePyFuncItem(object):
9+
def get_marker(self, marker_name):
10+
return FakeMarker()
11+
pyfuncitem = FakePyFuncItem()
12+
marker_name = 'given'
13+
assert read_marker(pyfuncitem, marker_name) == expected_marker
14+
15+
16+
def test_read_non_existing_marker():
17+
class FakePyFuncItem(object):
18+
def get_marker(self, marker_name):
19+
return None
20+
pyfuncitem = FakePyFuncItem()
21+
marker_name = 'given'
22+
assert read_marker(pyfuncitem, marker_name) == ''

0 commit comments

Comments
 (0)