Skip to content

Commit

Permalink
some tests were failing, and the contribution guide was a little dated
Browse files Browse the repository at this point in the history
  • Loading branch information
chrstnbwnkl committed Jun 4, 2024
1 parent de91830 commit 0a8377c
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 15 deletions.
15 changes: 11 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,21 @@ pre-commit install
You'll need a few things to run the tests:

- PostreSQL installation with a DB named `gis_test` (or define another db name using `POSTGRES_DB_TEST`) **and PostGIS enabled**
- Redis database, best done with `docker run --name redis -p 6379:6379 -d redis:6.0`, then you can use the project's defaults, i.e. `REDIS_URL=redis://localhost:6379/0`
- some fake SMTP service to handle email tests, our recommendations:
- [fake-smtp-server](https://www.npmjs.com/package/fake-smtp-server): NodeJS app with a frontend on `http://localhost:1080` and SMTP port 1025
- pure Python one-liner in a separate terminal window: `sudo python -m smtpd -n -c DebuggingServer localhost:1025`
- Redis database

Both can be quickly spun up by using the provided `docker-compose.test.yml`:

```bash
docker compose -f docker-compose.test.yml up -d
```

You'll also need some fake SMTP service to handle email tests, our recommendation: [fake-smtp-server](https://www.npmjs.com/package/fake-smtp-server),
a NodeJS app with a frontend on `http://localhost:1080` and SMTP port 1025

We use `pytest` in this project with `coverage`:

```bash
export API_CONFIG=test
pytest --cov=routing_packager_app
```

Expand Down
14 changes: 14 additions & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
services:
postgres:
image: kartoza/postgis:14
environment:
POSTGRES_USER: admin
POSTGRES_PASS: admin
POSTGRES_DB: gis_test
ALLOW_IP_RANGE: 0.0.0.0/0
ports:
- 5432:5432
redis:
image: redis:6.2
ports:
- 6379:6379
12 changes: 6 additions & 6 deletions routing_packager_app/api_v1/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ class JobCreate(JobBase):
class Job(JobBase, table=True):
__tablename__ = "jobs"

id: Optional[int] = Field(primary_key=True)
arq_id: Optional[str] = Field(nullable=True)
user_id: int = Field(default=None, foreign_key="users.id")
id: int | None = Field(default=None, primary_key=True)
arq_id: str | None = Field(nullable=True)
user_id: int | None = Field(default=None, foreign_key="users.id")
status: Statuses = Field(nullable=False)
zip_path: str = Field(nullable=True)
last_started: Optional[datetime] = Field(nullable=True) # did it ever run?
last_finished: Optional[datetime] = Field(
last_started: datetime | None = Field(nullable=True) # did it ever run?
last_finished: datetime | None = Field(
sa_column=Column(DateTime(), nullable=True)
) # did it ever finish?

Expand Down Expand Up @@ -81,7 +81,7 @@ class User(UserBase, table=True):

__tablename__ = "users"

id: Optional[int] = Field(primary_key=True)
id: int | None = Field(default=None, primary_key=True)
password: str = Field(sa_column=Column(PasswordType(schemes=("pbkdf2_sha512",)), nullable=False))
jobs: List[Job] = Relationship(back_populates="user")

Expand Down
4 changes: 2 additions & 2 deletions tests/jobs/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from routing_packager_app import SETTINGS
from routing_packager_app.api_v1.models import Job
from routing_packager_app.constants import Providers, Statuses
from routing_packager_app.constants import Providers
from routing_packager_app.utils.file_utils import make_package_path
from ..utils_ import create_new_job, DEFAULT_ARGS_POST

Expand Down Expand Up @@ -74,7 +74,7 @@ def test_job_get_jobs(get_client, basic_auth_header):
# parameterize the ones that should work with the default params
@pytest.mark.parametrize(
"key_value",
(("bbox", "0,0,1,1"), ("provider", Providers.OSM), ("status", Statuses.QUEUED), ("update", False)),
(("bbox", "0,0,1,1"), ("provider", "osm"), ("status", "Queued"), ("update", False)),
)
def test_job_get_jobs_all_params(key_value, get_client, basic_auth_header):
# default
Expand Down
6 changes: 3 additions & 3 deletions tests/users/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_new_user_missing_field_error(missing_field, get_client: TestClient, bas
response = create_new_user(get_client, data, basic_auth_header, False)

assert response.status_code == 422
assert response.json()["detail"][0].get("msg") == "field required"
assert response.json()["detail"][0].get("msg") == "Field required"


@pytest.mark.parametrize("email", ("[email protected]", "user.me", "uuser@email:", "user@email."))
Expand All @@ -57,7 +57,7 @@ def test_new_user_wrong_email_error(email, get_client: TestClient, basic_auth_he
response = create_new_user(get_client, auth_header=basic_auth_header, data=data, must_succeed=False)

assert response.status_code == 422
assert response.json()["detail"][0].get("msg") == "value is not a valid email address"
assert response.json()["detail"][0].get("msg")[:34] == "value is not a valid email address"


def test_new_user_unauthorized(get_client, basic_auth_header):
Expand Down Expand Up @@ -192,6 +192,6 @@ def test_admin_user_created(get_client, get_session: Session):
assert response.json()[0]["email"] == expected_email

statement = select(User).where(User.id == 1)
admin_user = get_session.exec(statement)
admin_user = get_session.exec(statement).first()
assert admin_user is not None
assert admin_user.email == expected_email

0 comments on commit 0a8377c

Please sign in to comment.