Skip to content

Commit 52fe56e

Browse files
authored
Merge pull request #8 from studio3104/readme
Update README and add a tiny example
2 parents 7c54e88 + 911bf4c commit 52fe56e

File tree

9 files changed

+74
-8
lines changed

9 files changed

+74
-8
lines changed

README.rst

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,21 @@ A set of py.test fixtures for AWS Chalice
1818

1919
----
2020

21-
This `pytest`_ plugin was generated with `Cookiecutter`_ along with `@hackebrot`_'s `cookiecutter-pytest-plugin`_ template.
22-
23-
2421
Features
25-
--------
22+
------------
2623

27-
* TODO
24+
- Launch the local gateway per test function
25+
- Provide an abstracted client fixture to access the local gateway
26+
- Expose an interface to overwrite response context with arbitrary objects
27+
- As of Chalice version 1.8.0, LocalGateway object doesn't handle Cognito's context
28+
- Not only for this purpose, it's an interface provided to allow custom contexts in unit tests
2829

2930

3031
Requirements
3132
------------
3233

33-
* TODO
34+
- `pytest`_
35+
- `Chalice`_
3436

3537

3638
Installation
@@ -44,7 +46,30 @@ You can install "pytest-chalice" via `pip`_ from `PyPI`_::
4446
Usage
4547
-----
4648

47-
* TODO
49+
.. code-block:: python
50+
51+
from chalice import Chalice
52+
53+
app = Chalice(__name__)
54+
55+
56+
@app.route('/')
57+
def index:
58+
return {'hello': 'world'}
59+
60+
61+
.. code-block:: python
62+
63+
from http import HTTPStatus
64+
65+
66+
def test_index(client):
67+
response = client.get('/')
68+
assert response.status_code == HTTPStatus.OK
69+
assert response.json == {'hello': 'world'}
70+
71+
72+
See `examples <https://github.com/studio3104/pytest-chalice/tree/master/examples>`_ for more detailed
4873

4974
Contributing
5075
------------
@@ -62,7 +87,6 @@ Issues
6287

6388
If you encounter any problems, please `file an issue`_ along with a detailed description.
6489

65-
.. _`Cookiecutter`: https://github.com/audreyr/cookiecutter
6690
.. _`@hackebrot`: https://github.com/hackebrot
6791
.. _`MIT`: http://opensource.org/licenses/MIT
6892
.. _`BSD-3`: http://opensource.org/licenses/BSD-3-Clause
@@ -74,3 +98,4 @@ If you encounter any problems, please `file an issue`_ along with a detailed des
7498
.. _`tox`: https://tox.readthedocs.io/en/latest/
7599
.. _`pip`: https://pypi.org/project/pip/
76100
.. _`PyPI`: https://pypi.org/project
101+
.. _`Chalice`: https://github.com/aws/chalice

examples/simple/.chalice/config.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"version": "2.0",
3+
"app_name": "simple",
4+
"stages": {
5+
"dev": {
6+
"api_gateway_stage": "api"
7+
}
8+
}
9+
}

examples/simple/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.chalice/deployments/
2+
.chalice/venv/

examples/simple/app.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from typing import Dict
2+
3+
from chalice import Chalice
4+
5+
app = Chalice(app_name='simple')
6+
7+
8+
@app.route('/')
9+
def index() -> Dict[str, str]:
10+
return {'hello': 'world'}

examples/simple/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
chalice>=1.8.0

examples/simple/test_requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pytest-chalice

examples/simple/tests/__init__.py

Whitespace-only changes.

examples/simple/tests/conftest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import pytest
2+
3+
from chalice import Chalice
4+
5+
from app import app as chalice_app
6+
7+
8+
@pytest.fixture
9+
def app() -> Chalice:
10+
return chalice_app

examples/simple/tests/test_app.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from http import HTTPStatus
2+
from pytest_chalice.handlers import RequestHandler
3+
4+
5+
def test_index(client: RequestHandler) -> None:
6+
response = client.get('/')
7+
assert response.status_code == HTTPStatus.OK
8+
assert response.json == {'hello': 'world'}

0 commit comments

Comments
 (0)