Skip to content

Commit

Permalink
Merge pull request #22 from JWCook/integration-tests
Browse files Browse the repository at this point in the history
Set up integration tests to run both locally and in GitHub Actions
  • Loading branch information
JWCook committed Feb 24, 2021
2 parents 4cc3be8 + d41241e commit 2bdac93
Show file tree
Hide file tree
Showing 16 changed files with 285 additions and 161 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ jobs:
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- uses: supercharge/mongodb-github-action@1.3.0
with:
mongodb-version: 4.4

# Cache packages per python version, and reuse until setup.py changes
- name: Cache pip packages
Expand All @@ -29,11 +32,12 @@ jobs:
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('setup.py') }}
restore-keys: ${{ runner.os }}-pip-${{ matrix.python-version }}

# TODO: tests
- name: Install dependencies
run: pip install ".[dev]"
- name: Run unit tests
run: pytest
run: pytest test/unit
- name: Run integration tests
run: pytest test/integration

analyze:
runs-on: ubuntu-18.04
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
*.py[cod]
*.idea
*.sqlite
*.egg
*.egg-info
.idea/
.vim/
.vscode/
build/
dist/
venv/
Expand Down
58 changes: 58 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Contributing

## Installation
To set up for local development:

```bash
$ git clone https://github.com/JWCook/aiohttp-client-cache
$ cd aiohttp-client-cache
$ pip install -Ue ".[dev]"
```

## Pre-commit hooks
[Pre-commit](https://github.com/pre-commit/pre-commit) config is uncluded to run the same checks
locally that are run in CI jobs by GitHub Actions. This is optional but recommended.
```bash
$ pre-commit install --config .github/pre-commit.yml
```

To uninstall:
```bash
$ pre-commit uninstall
```

## Integration Tests
Local databases are required to run integration tests, and docker-compose config is included to make
this easier. First, [install docker](https://docs.docker.com/get-docker/) and
[install docker-compose](https://docs.docker.com/compose/install/).

Then, run:
```bash
$ docker-compose up -d
pytest test/integration
```

## Documentation
[Sphinx](http://www.sphinx-doc.org/en/master/) is used to generate documentation.

To build the docs locally:
```bash
$ make -C docs html
```

To preview:
```bash
# MacOS:
$ open docs/_build/index.html
# Linux:
$ xdg-open docs/_build/index.html
```

Documentation is automatically built by ReadTheDocs whenever code is merged into the `main` branch.


## Releases
Releases are built and published to pypi based on **git tags.**
[Milestones](https://github.com/JWCook/aiohttp-client-cache/milestones) will be used to track
progress on major and minor releases.

4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# History

## 0.2.0 (TBD)
* Update SQLite backend to use `aiosqlite` for async cache operations
* Update MongoDB backend to use `motor` for async cache operations

## 0.1.0 (2020-11-14)
* Initial PyPI release
* First pass at a general refactor and conversion from `requests` to `aiohttp`
Expand Down
11 changes: 2 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,8 @@ To install with extra dependencies for all supported backends:
pip install aiohttp-client-cache[backends]
```

To set up for local development:

```bash
$ git clone https://github.com/JWCook/aiohttp-client-cache
$ cd aiohttp-client-cache
$ pip install -Ue ".[dev]"
$ # Optional but recommended:
$ pre-commit install --config .github/pre-commit.yml
```
See [Contributing](https://github.com/JWCook/aiohttp-client-cache/blob/main/README.md)
for setup info for local development.

## Usage example
See the [examples](https://github.com/JWCook/aiohttp-client-cache/blob/master/examples)
Expand Down
41 changes: 41 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Containers needed to test all backend services locally
version: '3'

services:
dynamodb:
image: amazon/dynamodb-local
hostname: dynamodb-local
container_name: dynamodb-local
ports:
- 8000:8000
command: "-jar DynamoDBLocal.jar -sharedDb -optimizeDbBeforeStartup -dbPath ./data"
volumes:
- 'dynamodb_data:/home/dynamodblocal/data'
working_dir: /home/dynamodblocal

mongo:
image: mongo
environment:
MONGO_INITDB_DATABASE: aiohttp_client_cache_pytest
ports:
- 27017:27017
volumes:
- 'mongodb_data:/data/db'

redis:
image: docker.io/bitnami/redis
environment:
ALLOW_EMPTY_PASSWORD: 'yes'
# REDIS_DISABLE_COMMANDS: 'FLUSHDB,FLUSHALL'
ports:
- 6379:6379
volumes:
- 'redis_data:/bitnami/redis/data'

volumes:
dynamodb_data:
driver: local
mongodb_data:
driver: local
redis_data:
driver: local
2 changes: 2 additions & 0 deletions docs/contributing.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.. mdinclude:: ../CONTRIBUTING.md

1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Contents

reference
history
contributing


Indices and tables
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
],
# Packages used for testing both locally and in CI jobs
'test': [
'asyncmock; python_version=="3.7"',
'black==20.8b1',
'flake8',
'isort',
Expand Down
1 change: 0 additions & 1 deletion test/__init__.py

This file was deleted.

5 changes: 0 additions & 5 deletions test/backends/__init__.py

This file was deleted.

143 changes: 0 additions & 143 deletions test/backends/test_backend_mongo.py

This file was deleted.

0 comments on commit 2bdac93

Please sign in to comment.