Skip to content

Commit 9c565bb

Browse files
committed
feat: fixing up tests and examples and code for provider class
feat: Added publish params feat: wip on exampels feat: working example locally on provider verification with provider states feat: travis and make to run in ci
1 parent d4072ed commit 9c565bb

File tree

16 files changed

+561
-205
lines changed

16 files changed

+561
-205
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,8 @@ ENV/
101101

102102

103103
.noseids
104+
105+
106+
# ignore local test pact files
107+
**/userserviceclient-userservice.json
108+

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ script:
2323
- flake8
2424
- pydocstyle pact
2525
- tox -e test
26-
- if [[ $TRAVIS_PYTHON_VERSION == "3.5" ]]; then make package && pip install ./dist/pact-python-*.tar.gz && make e2e; fi
26+
- if [[ $TRAVIS_PYTHON_VERSION == "3.5" ]]; then make package && pip install ./dist/pact-python-*.tar.gz && make examples; fi
2727

2828
before_deploy:
2929
- export RELEASE_PACKAGE=$(ls dist/pact-python-*.tar.gz)

Makefile

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ help:
66
@echo " clean to clear build and distribution directories"
77
@echo " deps to install the required files for development"
88
@echo " e2e to run the end to end tests"
9+
@echo " verifier to run the verifier end to end tests"
10+
@echo " examples to run the example end to end tests"
911
@echo " package to create a distribution package in /dist/"
1012
@echo " release to perform a release build, including deps, test, and package targets"
1113
@echo " test to run all tests"
@@ -29,19 +31,36 @@ deps:
2931

3032

3133
define E2E
34+
echo "e2e make"
3235
cd examples/e2e
3336
pip install -r requirements.txt
3437
pip install -e ../../
3538
pytest tests/test_user_consumer.py
3639
./verify_pact.sh
3740
endef
38-
39-
4041
export E2E
42+
4143
.PHONY: e2e
4244
e2e:
4345
bash -c "$$E2E"
4446

47+
define verifier
48+
echo "verifier make"
49+
cd examples/verifier
50+
pip install -r requirements.txt
51+
pip install -e ../../
52+
pytest
53+
endef
54+
export verifier
55+
56+
.PHONY: verifier
57+
verifier:
58+
bash -c "$$verifier"
59+
60+
.PHONY: examples
61+
examples: verifier e2e
62+
63+
4564

4665
.PHONY: package
4766
package:

examples/verifier/Pipfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[[source]]
2+
name = "pypi"
3+
url = "https://pypi.org/simple"
4+
verify_ssl = true
5+
6+
[dev-packages]
7+
8+
[packages]
9+
pytest = "==5.4.1"
10+
requests = "==2.23.0"
11+
Flask = "==1.1.1"
12+
13+
[requires]
14+
python_version = "3.7"

examples/verifier/Pipfile.lock

Lines changed: 226 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/verifier/README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
# Introduction
22

3-
This is a verifier example.
3+
This is an e2e example to show the provider verification working.
44

55
## Setup
66

77
Create your own virtualenv for this. Run
88

99
```bash
1010
pip install -r requirements.txt
11+
pip install ../../
1112
```
1213

13-
This should provide you with a relative path to pact install relatively (2 dirs up)
14-
15-
Create the local broker (for demo purposes only) To do this separately clone this repo:
16-
* https://github.com/pact-foundation/pact-broker-docker
14+
pip install pipenv
15+
$ pipenv install
16+
pipenv shell
17+
pytest
1718

18-
Then from where this is install run in it's own terminal
19+
This should provide you with a relative path to pact install relatively (2 dirs up)
1920

21+
Create the local broker (for demo purposes only) Open a separate terminal in the examples/broker folder and run:
2022
```bash
2123
docker-compose up
2224
```
@@ -34,5 +36,5 @@ pytest
3436
Or you can run individual tests like:
3537

3638
```bash
37-
pytest tests/xxx.py::test_yyy
39+
pytest tests/test_user_consumer.py::test_get_non_existing_user
3840
```

examples/verifier/pact_provider.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from flask import jsonify, request
2+
3+
from src.provider import app, fakedb
4+
5+
6+
@app.route('/_pact/provider_states', methods=['POST'])
7+
def provider_states():
8+
mapping = {'UserA does not exist': setup_no_user_a,
9+
'UserA exists and is not an administrator':
10+
setup_user_a_nonadmin}
11+
mapping[request.json['state']]()
12+
return jsonify({'result': request.json['state']})
13+
14+
15+
def setup_no_user_a():
16+
if 'UserA' in fakedb:
17+
del fakedb['UserA']
18+
19+
20+
def setup_user_a_nonadmin():
21+
id = '00000000-0000-4000-a000-000000000000'
22+
some_date = '2016-12-15T20:16:01'
23+
ip_address = '198.0.0.1'
24+
25+
fakedb['UserA'] = {
26+
'name': "UserA",
27+
'id': id,
28+
'created_on': some_date,
29+
'ip_address': ip_address,
30+
'admin': False
31+
}
32+
33+
34+
if __name__ == '__main__':
35+
app.run(debug=True, port=5001)

0 commit comments

Comments
 (0)