Skip to content

Commit

Permalink
Merge pull request #8 from studio3104/readme
Browse files Browse the repository at this point in the history
Update README and add a tiny example
  • Loading branch information
studio3104 authored May 17, 2019
2 parents 7c54e88 + 911bf4c commit 52fe56e
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 8 deletions.
41 changes: 33 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,21 @@ A set of py.test fixtures for AWS Chalice

----

This `pytest`_ plugin was generated with `Cookiecutter`_ along with `@hackebrot`_'s `cookiecutter-pytest-plugin`_ template.


Features
--------
------------

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


Requirements
------------

* TODO
- `pytest`_
- `Chalice`_


Installation
Expand All @@ -44,7 +46,30 @@ You can install "pytest-chalice" via `pip`_ from `PyPI`_::
Usage
-----

* TODO
.. code-block:: python
from chalice import Chalice
app = Chalice(__name__)
@app.route('/')
def index:
return {'hello': 'world'}
.. code-block:: python
from http import HTTPStatus
def test_index(client):
response = client.get('/')
assert response.status_code == HTTPStatus.OK
assert response.json == {'hello': 'world'}
See `examples <https://github.com/studio3104/pytest-chalice/tree/master/examples>`_ for more detailed

Contributing
------------
Expand All @@ -62,7 +87,6 @@ Issues

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

.. _`Cookiecutter`: https://github.com/audreyr/cookiecutter
.. _`@hackebrot`: https://github.com/hackebrot
.. _`MIT`: http://opensource.org/licenses/MIT
.. _`BSD-3`: http://opensource.org/licenses/BSD-3-Clause
Expand All @@ -74,3 +98,4 @@ If you encounter any problems, please `file an issue`_ along with a detailed des
.. _`tox`: https://tox.readthedocs.io/en/latest/
.. _`pip`: https://pypi.org/project/pip/
.. _`PyPI`: https://pypi.org/project
.. _`Chalice`: https://github.com/aws/chalice
9 changes: 9 additions & 0 deletions examples/simple/.chalice/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"version": "2.0",
"app_name": "simple",
"stages": {
"dev": {
"api_gateway_stage": "api"
}
}
}
2 changes: 2 additions & 0 deletions examples/simple/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.chalice/deployments/
.chalice/venv/
10 changes: 10 additions & 0 deletions examples/simple/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from typing import Dict

from chalice import Chalice

app = Chalice(app_name='simple')


@app.route('/')
def index() -> Dict[str, str]:
return {'hello': 'world'}
1 change: 1 addition & 0 deletions examples/simple/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
chalice>=1.8.0
1 change: 1 addition & 0 deletions examples/simple/test_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pytest-chalice
Empty file.
10 changes: 10 additions & 0 deletions examples/simple/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import pytest

from chalice import Chalice

from app import app as chalice_app


@pytest.fixture
def app() -> Chalice:
return chalice_app
8 changes: 8 additions & 0 deletions examples/simple/tests/test_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from http import HTTPStatus
from pytest_chalice.handlers import RequestHandler


def test_index(client: RequestHandler) -> None:
response = client.get('/')
assert response.status_code == HTTPStatus.OK
assert response.json == {'hello': 'world'}

0 comments on commit 52fe56e

Please sign in to comment.