Skip to content

Commit

Permalink
setup pytest with gh action (#4)
Browse files Browse the repository at this point in the history
* setup pytest with gh action

* Fixes whitespace linter changes

* Adds pyenv to gitignore. Adds testing link to README

---------

Co-authored-by: Paul Pilone <paul@element84.com>
  • Loading branch information
jkeifer and paulpilone authored Apr 19, 2023
1 parent a7b5ac9 commit 5a51fa4
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 8 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/python-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Python Test
on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
strategy:
matrix:
python-version:
- "3.11"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install '.[dev]'
- name: Lint with ruff
run: |
ruff check .
- name: Test with pytest
run: pytest --cov=swoop --cov-report=xml

- name: "Upload coverage to Codecov"
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: true
verbose: true
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
Expand Down
5 changes: 5 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ pre-commit checks, this can be done with:
git commit -m "message" --no-verify
```

## Testing

Tests are run using `pytest`. Put pytest python modules and other resource in
the `/tests` directory.

## Adding/updating dependencies

### Updating `requirements.txt` to latest versions
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ brew install dbmate
```
<br>


## Database Setup / Migrations

The DB schema and migrations are managed by [Dbmate](https://github.com/amacneil/dbmate#commands).
Expand All @@ -28,8 +27,11 @@ Create the database and tables:
```
dbmate up
```
<br>

## Environment Setup and Testing

Refer to [Contributing.md](./CONTRIBUTING.md) for environment setup and testing instructions.

<br><br><br>
This project is a work in progress.
This project is a work in progress.
2 changes: 1 addition & 1 deletion db/migrations/20230328180857_initial_setup.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ DROP TABLE IF EXISTS jobs;

DROP TABLE IF EXISTS task_executions;

DROP TABLE IF EXISTS workflows;
DROP TABLE IF EXISTS workflows;
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ dev = [
"pre-commit >=3.1.1",
"pre-commit-hooks >=4.4.0",
"black >=23.1.0",
"httpx >=0.24.0",
"ruff >=0.0.253",
"mypy >=1.0.1",
"pip-tools >= 6.12.3",
"pytest >=7.2.2",
"pytest-cov >=4.0.0",
"pyupgrade >=3.3.1",
]

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ anyio==3.6.2
# via starlette
click==8.1.3
# via uvicorn
fastapi==0.95.0
fastapi==0.95.1
# via swoop (pyproject.toml)
h11==0.14.0
# via uvicorn
Expand Down
18 changes: 15 additions & 3 deletions src/swoop/api/routers/root.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from __future__ import annotations


from fastapi import APIRouter
from fastapi import APIRouter, Request

from ..models import (
ConfClasses,
Exception as APIException,
LandingPage,
Link,
)


Expand All @@ -19,11 +20,22 @@
responses={"500": {"model": APIException}},
tags=["Capabilities"],
)
def get_landing_page() -> LandingPage | APIException:
def get_landing_page(request: Request) -> LandingPage | APIException:
"""
landing page of this API
"""
pass
return LandingPage(
title="Example processing server",
description="Example server implementing the OGC API - Processes 1.0 Standard",
links=[
Link(
href=str(request.url_for("get_conformance_classes")),
rel="http://www.opengis.net/def/rel/ogc/1.0/conformance",
type="application/json",
hreflang=None,
),
],
)


@router.get(
Expand Down
Empty file added tests/__init__.py
Empty file.
Empty file added tests/api/__init__.py
Empty file.
25 changes: 25 additions & 0 deletions tests/api/test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from fastapi.testclient import TestClient

from swoop.api.main import app

client = TestClient(app)


def test_read_main():
response = client.get("/")
assert response.status_code == 200
assert response.json() == {
"description": (
"Example server implementing the OGC API - Processes 1.0 Standard"
),
"links": [
{
"href": "http://testserver/conformance",
"hreflang": None,
"rel": "http://www.opengis.net/def/rel/ogc/1.0/conformance",
"title": None,
"type": "application/json",
},
],
"title": "Example processing server",
}

0 comments on commit 5a51fa4

Please sign in to comment.