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
122 changes: 83 additions & 39 deletions README.md

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ line-length = 120
# Don't require __init__.py files
"INP",
]
"dev/*" = [
# Don't require __init__.py files
"INP",
# Allow print in helper scripts
"T201",
# Token URLs are no passwords
"S105",
]

[tool.ruff.lint.flake8-quotes]
inline-quotes = "single"
Expand Down
20 changes: 15 additions & 5 deletions tests/integration/public_api/ocpi/connector_tariff_api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ def test_connector_outputs_tariff_uids_of_its_evse(
db: SQLAlchemy,
public_test_client: OpenApiFlaskClient,
) -> None:
"""Sources publish tariffs per EVSE, so the connectors of an EVSE output its tariff uids."""
"""
Sources publish tariffs per EVSE, so the connectors of an EVSE output its tariff uids.
"""
tariff = get_tariff_1()
db.session.add(tariff)
db.session.flush()
Expand All @@ -56,7 +58,9 @@ def test_connector_outputs_all_tariff_uids_of_its_evse(
db: SQLAlchemy,
public_test_client: OpenApiFlaskClient,
) -> None:
"""An EVSE offered under several tariffs passes all of their uids to its connectors."""
"""
An EVSE offered under several tariffs passes all of their uids to its connectors.
"""
first_tariff = get_tariff_1()
second_tariff = get_tariff_2()
db.session.add_all([first_tariff, second_tariff])
Expand Down Expand Up @@ -106,7 +110,9 @@ def test_connector_tariff_uids_take_precedence_over_the_evse_ones(
db: SQLAlchemy,
public_test_client: OpenApiFlaskClient,
) -> None:
"""A connector carrying its own tariffs does not inherit the ones of its EVSE."""
"""
A connector carrying its own tariffs does not inherit the ones of its EVSE.
"""
evse_tariff = get_tariff_1()
connector_tariff = get_tariff_2()
db.session.add_all([evse_tariff, connector_tariff])
Expand All @@ -128,7 +134,9 @@ def test_connector_without_tariffs_omits_tariff_ids(
db: SQLAlchemy,
public_test_client: OpenApiFlaskClient,
) -> None:
"""tariff_ids is optional in OCPI, so a connector without any tariff leaves it out."""
"""
tariff_ids is optional in OCPI, so a connector without any tariff leaves it out.
"""
db.session.add(get_location_1(evses=[get_full_evse_1()], operator=get_business_1()))
db.session.commit()

Expand All @@ -142,7 +150,9 @@ def test_evse_endpoint_outputs_connector_tariff_uids(
db: SQLAlchemy,
public_test_client: OpenApiFlaskClient,
) -> None:
"""The connectors nested into an EVSE response carry the tariff uids too."""
"""
The connectors nested into an EVSE response carry the tariff uids too.
"""
tariff = get_tariff_1()
db.session.add(tariff)
db.session.flush()
Expand Down
8 changes: 6 additions & 2 deletions tests/integration/public_api/ocpi/v2_2/tariff_api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ def test_get_ocpi_22_tariff_merges_tariff_data(
db: SQLAlchemy,
public_test_client: OpenApiFlaskClient,
) -> None:
"""Two associations pointing to the same tariff produce two OCPI 2.2 tariffs with same pricing but different types."""
"""
Two associations pointing to the same tariff produce two OCPI 2.2 tariffs with same pricing but different types.
"""
tariff = get_tariff_1()
tariff.elements = [
TariffElement(
Expand Down Expand Up @@ -178,7 +180,9 @@ def test_get_ocpi_22_tariffs_does_not_load_evses_and_connectors(
db: SQLAlchemy,
public_test_client: OpenApiFlaskClient,
) -> None:
"""OCPI 2.2 tariffs do not render the EVSEs and connectors of a tariff association, so they are not loaded."""
"""
OCPI 2.2 tariffs do not render the EVSEs and connectors of a tariff association, so they are not loaded.
"""
tariff = get_tariff_1()
db.session.add(tariff)
db.session.flush()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ def test_get_ocpi_30_tariff_associations_loads_just_evse_ids(
db: SQLAlchemy,
public_test_client: OpenApiFlaskClient,
) -> None:
"""Tariff associations render just the ids of their EVSEs, so the EVSEs are not loaded completely."""
"""
Tariff associations render just the ids of their EVSEs, so the EVSEs are not loaded completely.
"""
tariff = get_tariff_1()
db.session.add(tariff)
db.session.flush()
Expand Down
4 changes: 3 additions & 1 deletion tests/integration/repositories/location_repository_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@


def test_fetch_location_by_uid_respects_source(db: SQLAlchemy) -> None:
"""Different sources can use the same location uid, so the source has to be part of the lookup."""
"""
Different sources can use the same location uid, so the source has to be part of the lookup.
"""
db.session.add_all([
get_location_1(source=SOURCE_UID_1, name='Location of source 1'),
get_location_1(source=SOURCE_UID_2, name='Location of source 2'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,18 @@

@pytest.fixture
def stub_celery_delay():
"""Stub out CeleryHelper.delay so the bnetza import task is not actually enqueued."""
"""
Stub out CeleryHelper.delay so the bnetza import task is not actually enqueued.
"""
with patch.object(dependencies.get_celery_helper(), 'delay') as mock_delay:
yield mock_delay


@pytest.fixture
def isolated_bnetza_dir(tmp_path: Path):
"""Redirect BNETZA_IMPORT_DIR to a per-test temp directory to avoid polluting `data/`."""
"""
Redirect BNETZA_IMPORT_DIR to a per-test temp directory to avoid polluting `data/`.
"""
config = dependencies.get_config_helper().get_config()
original = config.get('BNETZA_IMPORT_DIR')
config['BNETZA_IMPORT_DIR'] = str(tmp_path)
Expand Down
16 changes: 12 additions & 4 deletions tests/integration/server_rest_api/datex2/datex2_import_api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ def _import_static_data(requests_mock: Mocker) -> None:


def _fetch_realtime_data_updated_at(db: SQLAlchemy) -> datetime | None:
"""Return the source's ``realtime_data_updated_at`` as an aware UTC datetime."""
"""
Return the source's ``realtime_data_updated_at`` as an aware UTC datetime.
"""
db.session.expire_all()
source = db.session.query(Source).filter(Source.uid == SOURCE_UID).first()
if source is None or source.realtime_data_updated_at is None:
Expand All @@ -74,7 +76,9 @@ def _fetch_realtime_data_updated_at(db: SQLAlchemy) -> datetime | None:

@pytest.fixture
def isolated_datex2_dir(tmp_path: Path):
"""Redirect DATEX2_IMPORT_DIR to a per-test temp directory."""
"""
Redirect DATEX2_IMPORT_DIR to a per-test temp directory.
"""
config = dependencies.get_config_helper().get_config()
original = config.get('DATEX2_IMPORT_DIR')
config['DATEX2_IMPORT_DIR'] = str(tmp_path)
Expand All @@ -100,7 +104,9 @@ def run_task_synchronously(task, *args, **kwargs):

@pytest.fixture
def stubbed_celery_delay():
"""Replace ``CeleryHelper.delay`` with a no-op mock for tests that don't need the task to run."""
"""
Replace ``CeleryHelper.delay`` with a no-op mock for tests that don't need the task to run.
"""
with patch.object(dependencies.get_celery_helper(), 'delay') as mock_delay:
yield mock_delay

Expand Down Expand Up @@ -430,7 +436,9 @@ def test_push_realtime_v35_delta_push_updates_realtime_data_updated_at(
isolated_datex2_dir: Path,
stubbed_celery_delay,
) -> None:
"""A synchronously applied deltaPush must update ``realtime_data_updated_at`` as well."""
"""
A synchronously applied deltaPush must update ``realtime_data_updated_at`` as well.
"""
_import_static_data(requests_mock)

realtime_data = _load_test_data('datex2_enbw_realtime_reduced.json')
Expand Down
4 changes: 3 additions & 1 deletion tests/integration/server_rest_api/giroe/giroe_api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ def _giroe_connector_uid(connector_id: int) -> str:


def _valid_location_payload(location_id: int, *, public: bool = True) -> dict:
"""Build a minimal-but-complete giroe Location payload accepted by LocationInput."""
"""
Build a minimal-but-complete giroe Location payload accepted by LocationInput.
"""
now = datetime.now(timezone.utc).isoformat()
return {
'id': location_id,
Expand Down
4 changes: 3 additions & 1 deletion tests/integration/server_rest_api/openapi_docs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ def test_server_openapi_json_renders(test_client: OpenApiFlaskClient) -> None:


def test_server_openapi_html_renders(test_client: OpenApiFlaskClient) -> None:
"""The Stoplight-Elements HTML wrapper page must load without errors."""
"""
The Stoplight-Elements HTML wrapper page must load without errors.
"""
response = test_client.get('/documentation/server.html')

assert response.status_code == HTTPStatus.OK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,9 @@ def test_save_location_updates_replaces_per_evse_associations_with_a_shared_one(


def _create_location_update_with_two_evses(*, tariff_association_uids: list[str]) -> LocationUpdate:
"""One location with two EVSEs, each pointing at the tariff association of the given uid."""
"""
One location with two EVSEs, each pointing at the tariff association of the given uid.
"""
tariff_update = TariffUpdate(
uid='tariff1',
source='test_source_uid',
Expand Down Expand Up @@ -631,7 +633,9 @@ def _create_location_update_with_tariff(


def test_save_location_updates_deletes_tariffs_with_new_uid(db, testing_import_service: BaseImportService):
"""A tariff which the source does not send anymore is deleted instead of staying behind unreferenced."""
"""
A tariff which the source does not send anymore is deleted instead of staying behind unreferenced.
"""
testing_import_service.save_location_updates([_create_location_update_with_tariff(tariff_uid='tariff1')])
testing_import_service.save_location_updates([_create_location_update_with_tariff(tariff_uid='tariff2')])

Expand All @@ -647,7 +651,9 @@ def test_save_location_updates_deletes_tariff_associations_of_kept_tariff(
db,
testing_import_service: BaseImportService,
):
"""The tariff survives its renamed association, but the old association does not."""
"""
The tariff survives its renamed association, but the old association does not.
"""
testing_import_service.save_location_updates([_create_location_update_with_tariff(tariff_association_uid='ta1')])
testing_import_service.save_location_updates([_create_location_update_with_tariff(tariff_association_uid='ta2')])

Expand All @@ -656,7 +662,9 @@ def test_save_location_updates_deletes_tariff_associations_of_kept_tariff(


def test_save_location_updates_deletes_tariffs_of_deleted_locations(db, testing_import_service: BaseImportService):
"""Tariffs do not belong to a location, so a vanished location has to take its tariffs with it."""
"""
Tariffs do not belong to a location, so a vanished location has to take its tariffs with it.
"""
testing_import_service.save_location_updates([
_create_location_update_with_tariff(location_uid='loc1', tariff_association_uid='ta1', tariff_uid='tariff1'),
_create_location_update_with_tariff(location_uid='loc2', tariff_association_uid='ta2', tariff_uid='tariff2'),
Expand All @@ -674,7 +682,9 @@ def test_save_location_updates_deletes_tariffs_of_deleted_locations(db, testing_


def test_save_location_updates_keeps_tariffs_of_other_sources(db, testing_import_service: BaseImportService):
"""The cleanup is limited to the source which is imported."""
"""
The cleanup is limited to the source which is imported.
"""
other_source_tariff = Tariff(
uid='tariff1',
source='other_source_uid',
Expand Down
Loading
Loading