Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ SENTRY_TRACES_SAMPLE_RATE=0.1
ALLOWED_HOSTS=*

AUDIT_LOG_ENABLED=1
AUDIT_LOG_STORE_OBJECT_STATE=old-and-new
AUDIT_LOG_STORE_OBJECT_STATE=old-and-new
2 changes: 0 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,3 @@ updates:
prefix: "deps"
# Disable version updates and only allow security updates
open-pull-requests-limit: 0
- "City-of-Helsinki/kuva-backend"
- "City-of-Helsinki/kuva-developers"
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
uses: City-of-Helsinki/.github/.github/workflows/ci-django-api.yml@main
secrets: inherit
with:
python-version: 3.11
postgres-major-version: 13
python-version: 3.12
extra-commands: |
echo 'SECRET_KEY=topsecret123' >> .env
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@ venv/
.ruff_cache/
docker-compose.env
docker-compose.env.yaml
.vscode/
.vscode/
34 changes: 16 additions & 18 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
# Pre-commit hook documentation:
# - https://pre-commit.com/
# - https://pre-commit.com/hooks.html
#
# Ruff pre-commit hook documentation:
# - https://github.com/astral-sh/ruff-pre-commit
# Keep tool versions in sync with the versions in requirements-dev.txt
default_language_version:
python: python3.11
python: python3
default_install_hook_types: [pre-commit, commit-msg]
default_stages: [pre-commit, manual]
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-toml
- id: check-added-large-files
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version
rev: v0.5.2
rev: v0.13.0
hooks:
# Run the linter
# Run the linter.
- id: ruff
args: [ --fix ]
# Run the formatter
args: [ "--fix" ]
# Run the formatter.
- id: ruff-format
- repo: https://github.com/compilerla/conventional-pre-commit
rev: v3.4.0
hooks:
- id: conventional-pre-commit
stages: [commit-msg]
args: []
- repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
rev: v9.22.0
hooks:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ==============================
FROM registry.access.redhat.com/ubi9/python-311 AS appbase
FROM registry.access.redhat.com/ubi9/python-312 AS appbase
# ==============================

USER root
Expand Down
59 changes: 17 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ These are the basic internal dependencies of the project. If you are running the

### Python

Python 3.11 is the minimum version required. You can check your version by running `python --version`.
Python 3.12 is the minimum version required. You can check your version by running `python --version`.

If you encounter deprecation warnings on newer versions, you may need to downgrade to Python 3.11, but ideally fix the deprecation warnings and upgrade the container's python base version.

Expand Down Expand Up @@ -267,68 +267,43 @@ AUDIT_LOG = {

## Keeping Python requirements up to date

1. Install `pip-tools`:
1. Add new packages to `requirements.in` or `requirements-dev.in`

- `pip install pip-tools`

2. Add new packages to `requirements.in` or `requirements-dev.in`

3. Update `.txt` file for the changed requirements file:
2. Update `.txt` file for the changed requirements file:

- `pip-compile requirements.in`
- `pip-compile requirements-dev.in`

4. If you want to update dependencies to their newest versions, run:
3. If you want to update dependencies to their newest versions, run:

- `pip-compile --upgrade requirements.in`

5. To install Python requirements run:
4. To install Python requirements run:

- `pip-sync requirements.txt`

6. To install Python development requirements run:
5. To install Python development requirements run:

- `pip-sync requirements-dev.txt`

7. To install Python production requirements run:
6. To install Python production requirements run:

- `pip-sync requirements.txt requirements-prod.txt`

## Code formatting

This project uses [`ruff`](https://docs.astral.sh/ruff/formatter/) for Python code formatting. Basic `ruff` commands:

`ruff format` is the primary entrypoint to the formatter. It accepts a list of files or directories, and formats all discovered Python files:
## Code format

```

ruff format # Format all files in the current directory.
ruff format path/to/code/ # Format all files in `path/to/code` (and any subdirectories).
ruff format path/to/file.py # Format a single file.

```
This project uses [Ruff](https://docs.astral.sh/ruff/) for code formatting and quality checking.

> Similar to Black, running ruff format /path/to/file.py will format the given file or directory in-place, while ruff format --check /path/to/file.py will avoid writing any formatted files back, and instead exit with a non-zero status code upon detecting any unformatted files.

To run the Ruff Linter use `ruff check`.

> `ruff check` is the primary entrypoint to the Ruff linter. It accepts a list of files or directories, and lints all discovered Python files, optionally fixing any fixable errors:

```

ruff check # Lint all files in the current directory.
ruff check --fix # Lint all files in the current directory, and fix any fixable errors.
ruff check --watch # Lint all files in the current directory, and re-lint on change.
ruff check path/to/code/ # Lint all files in `path/to/code` (and any subdirectories).

```
Basic `ruff` commands:

1. Install `pre-commit` (there are many ways to do but let's use pip as an example):
- `pip install pre-commit`
2. Set up git hooks from `.pre-commit-config.yaml`, run this command from project root:
- `pre-commit install`
* lint: `ruff check`
* apply safe lint fixes: `ruff check --fix`
* check formatting: `ruff format --check`
* format: `ruff format`

After that, formatting hooks will run against all changed files before committing
[`pre-commit`](https://pre-commit.com/) can be used to install and
run all the formatting tools as git hooks automatically before a
commit.

## Releases, changelogs and deployments

Expand Down
61 changes: 61 additions & 0 deletions api/tests/__snapshots__/test_api.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# serializer version: 1
# name: test_get_delivery_log
dict({
'errors': list([
]),
'messages': dict({
'+358461231231': dict({
'converted': '+358461231231',
'status': 'CREATED',
}),
}),
'warnings': list([
]),
})
# ---
# name: test_send_sms
dict({
'errors': list([
]),
'messages': dict({
'+358461231231': dict({
'converted': '+358461231231',
'status': 'CREATED',
}),
}),
'warnings': list([
]),
})
# ---
# name: test_webhook_delivery_log
dict({
'errors': list([
]),
'messages': dict({
'+358461231231': dict({
'converted': '+358461231231',
'status': 'CREATED',
}),
}),
'warnings': list([
]),
})
# ---
# name: test_webhook_delivery_log.1
dict({
'errors': list([
]),
'messages': dict({
'+358461231231': dict({
'billingref': 'Palvelutarjotin',
'destination': '+358461231231',
'sender': 'hel.fi',
'smscount': '1',
'status': 'DELIVERED',
'statustime': '2020-07-21T09:18:00Z',
}),
}),
'warnings': list([
]),
})
# ---
Empty file removed api/tests/snapshots/__init__.py
Empty file.
40 changes: 0 additions & 40 deletions api/tests/snapshots/snap_test_api.py

This file was deleted.

1 change: 0 additions & 1 deletion api/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
@pytest.fixture(autouse=True)
def autouse_db(db):
"""Rename the db fixture"""
pass


SMS_PAYLOAD: SendMessagePayload = {
Expand Down
6 changes: 3 additions & 3 deletions api/tests/test_audit_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ def test_bulk_deleting_delivery_logs_writes_delete_log(admin_user):
client = Client()
client.force_login(admin_user)

COUNT = 3
count = 3

delivery_logs = DeliveryLogFactory.create_batch(COUNT)
delivery_logs = DeliveryLogFactory.create_batch(count)
object_ids = [str(log.pk) for log in delivery_logs]

# Get the URL for the changelist view
Expand All @@ -187,7 +187,7 @@ def test_bulk_deleting_delivery_logs_writes_delete_log(admin_user):
audit_log_entry = qs.first()

# Verify the audit log entry details
assert len(audit_log_entry.message["audit_event"]["target"]["object_ids"]) == COUNT
assert len(audit_log_entry.message["audit_event"]["target"]["object_ids"]) == count
assert sorted(
audit_log_entry.message["audit_event"]["target"]["object_ids"]
) == sorted(object_ids)
Expand Down
2 changes: 0 additions & 2 deletions audit_log/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
class AuditLoggingDisabledError(Exception):
"""Raised when audit logging is disabled and an attempt is made to log an event."""

pass
2 changes: 1 addition & 1 deletion common/tests/test_prune_django_admin_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def test_valid_months(
dry_run_msg = "Running in dry-run mode i.e. not committing changes!\n"
del_msg = (
f"Deleted {expected_deletion_count} Django admin logs "
f"created at least {5*12 if months is None else months} months ago"
f"created at least {5 * 12 if months is None else months} months ago"
)
assert captured.err == ""
assert del_msg in captured.out
Expand Down
2 changes: 1 addition & 1 deletion docs/development-without-docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Please refer to the [main README](/README.md) for the latest instructions.
## Prerequisites

- PostgreSQL 13
- Python 3.11
- Python 3.12
- Keycloak

### Installing Python requirements
Expand Down
2 changes: 1 addition & 1 deletion keycloak/realm.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@
]
}
]
}
}
1 change: 0 additions & 1 deletion openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,3 @@ components:
in: header
name: Authorization
description: DRF TokenAuthentication. You need to generate an API token for each client.

8 changes: 4 additions & 4 deletions pipelines/notification-service-api-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
trigger: none

# Pull request (PR) triggers cause a pipeline to run whenever a pull request is
# opened with one of the specified target branches, or when updates are made to
# opened with one of the specified target branches, or when updates are made to
# such a pull request.
#
# GitHub creates a new ref when a pull request is created. The ref points to a
# merge commit, which is the merged code between the source and target branches
# GitHub creates a new ref when a pull request is created. The ref points to a
# merge commit, which is the merged code between the source and target branches
# of the pull request.
#
# Opt out of pull request validation
# Opt out of pull request validation
pr:
# PR target branch
branches:
Expand Down
Loading