Skip to content

Commit 467b860

Browse files
authored
chore: auto-update pre-commit, apply fixes (#173)
1 parent b641f52 commit 467b860

File tree

6 files changed

+90
-90
lines changed

6 files changed

+90
-90
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
# See https://pre-commit.com/hooks.html for more hooks
33

44
# Optionally both commit and push
5-
default_stages: [commit]
5+
default_stages: [pre-commit]
66

77
# Regex for files to exclude
88
# Don't lint the generated JSON metadata files
99
exclude: "diagrams/"
1010

1111
repos:
1212
- repo: https://github.com/pre-commit/pre-commit-hooks
13-
rev: v4.0.1
13+
rev: v5.0.0
1414
hooks:
1515
- id: trailing-whitespace
1616
- id: end-of-file-fixer
1717

1818
- repo: https://github.com/astral-sh/ruff-pre-commit
19-
rev: v0.4.4
19+
rev: v0.12.5
2020
hooks:
2121
- id: ruff
2222
args: [--fix, --exit-non-zero-on-fix]

lib/database/bootstrapper_runtime/handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def get_secret(secret_name):
8080
def create_db(cursor, db_name: str) -> None:
8181
"""Create DB."""
8282
cursor.execute(
83-
sql.SQL("SELECT 1 FROM pg_catalog.pg_database " "WHERE datname = %s"), [db_name]
83+
sql.SQL("SELECT 1 FROM pg_catalog.pg_database WHERE datname = %s"), [db_name]
8484
)
8585
if cursor.fetchone():
8686
print(f" database {db_name} exists, not creating DB")

lib/ingestor-api/runtime/src/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def cancel_ingestion(
7676
raise HTTPException(
7777
status_code=400,
7878
detail=(
79-
"Unable to delete ingestion if status is not " f"{schemas.Status.queued}"
79+
f"Unable to delete ingestion if status is not {schemas.Status.queued}"
8080
),
8181
)
8282
return ingestion.cancel(db)

lib/ingestor-api/runtime/src/validators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def collection_exists(collection_id: str) -> bool:
6060
from .config import settings
6161

6262
url = "/".join(
63-
f'{url.strip("/")}' for url in [settings.stac_url, "collections", collection_id]
63+
f"{url.strip('/')}" for url in [settings.stac_url, "collections", collection_id]
6464
)
6565

6666
if (response := requests.get(url)).ok:

lib/ingestor-api/runtime/tests/test_registration.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ def test_validates_missing_collection(
9393
collection_id=self.example_ingestion.item.collection
9494
)
9595
assert response.status_code == 422, "should get validation error"
96-
assert (
97-
len(self.db.fetch_many(status="queued")["items"]) == 0
98-
), "data should not be stored in DB"
96+
assert len(self.db.fetch_many(status="queued")["items"]) == 0, (
97+
"data should not be stored in DB"
98+
)
9999

100100
def test_validates_no_collection_id(self, asset_exists):
101101
item_sans_id = self.example_ingestion.item.model_copy()
@@ -106,9 +106,9 @@ def test_validates_no_collection_id(self, asset_exists):
106106
json=item_sans_id.model_dump(mode="json"),
107107
)
108108
assert response.status_code == 422, "should get validation error"
109-
assert (
110-
len(self.db.fetch_many(status="queued")["items"]) == 0
111-
), "data should not be stored in DB"
109+
assert len(self.db.fetch_many(status="queued")["items"]) == 0, (
110+
"data should not be stored in DB"
111+
)
112112

113113
def test_validates_missing_assets(
114114
self, client_authenticated, collection_exists, asset_missing
@@ -134,9 +134,9 @@ def test_validates_missing_assets(
134134
err["loc"] == ["body", "assets", asset_type, "href"]
135135
for err in response.json()["detail"]
136136
), "should reference asset type in validation error response"
137-
assert (
138-
len(self.db.fetch_many(status="queued")["items"]) == 0
139-
), "data should not be stored in DB"
137+
assert len(self.db.fetch_many(status="queued")["items"]) == 0, (
138+
"data should not be stored in DB"
139+
)
140140

141141

142142
class TestList:

lib/stac-loader/runtime/tests/test_stac_loader_handler.py

Lines changed: 75 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ def test_handler_with_valid_item(mock_aws_context, mock_pgstac_dsn, database_url
9595
assert result is None
9696

9797
# Verify the item was added to the database
98-
assert check_item_exists(
99-
database_url, collection_id, item_id
100-
), "Item was not found in the database"
98+
assert check_item_exists(database_url, collection_id, item_id), (
99+
"Item was not found in the database"
100+
)
101101

102102

103103
def test_handler_with_valid_items_multiple_collections(
@@ -135,9 +135,9 @@ def test_handler_with_valid_items_multiple_collections(
135135

136136
# Verify all items were added to their respective collections
137137
for collection_id, item_id, _ in items:
138-
assert check_item_exists(
139-
database_url, collection_id, item_id
140-
), f"Item {item_id} was not found in collection {collection_id}"
138+
assert check_item_exists(database_url, collection_id, item_id), (
139+
f"Item {item_id} was not found in collection {collection_id}"
140+
)
141141

142142

143143
def test_handler_with_invalid_item(mock_aws_context, mock_pgstac_dsn):
@@ -191,15 +191,15 @@ def test_handler_with_multiple_items(mock_aws_context, mock_pgstac_dsn, database
191191

192192
# Verify all items were added
193193
for item_id in item_ids:
194-
assert check_item_exists(
195-
database_url, collection_id, item_id
196-
), f"Item {item_id} was not found in the database"
194+
assert check_item_exists(database_url, collection_id, item_id), (
195+
f"Item {item_id} was not found in the database"
196+
)
197197

198198
# Verify the count increased by the expected amount
199199
new_count = count_collection_items(database_url, collection_id)
200-
assert new_count == initial_count + len(
201-
items
202-
), f"Expected {initial_count + len(items)} items, but found {new_count}"
200+
assert new_count == initial_count + len(items), (
201+
f"Expected {initial_count + len(items)} items, but found {new_count}"
202+
)
203203

204204

205205
def test_handler_with_mixed_items(mock_aws_context, mock_pgstac_dsn, database_url):
@@ -240,15 +240,15 @@ def test_handler_with_mixed_items(mock_aws_context, mock_pgstac_dsn, database_ur
240240
assert valid_message_id not in failures
241241

242242
# Verify only the valid item was added
243-
assert check_item_exists(
244-
database_url, collection_id, valid_item_id
245-
), "Valid item was not found in the database"
243+
assert check_item_exists(database_url, collection_id, valid_item_id), (
244+
"Valid item was not found in the database"
245+
)
246246

247247
# Verify count increased by exactly 1
248248
new_count = count_collection_items(database_url, collection_id)
249-
assert (
250-
new_count == initial_count + 1
251-
), f"Expected {initial_count + 1} items, but found {new_count}"
249+
assert new_count == initial_count + 1, (
250+
f"Expected {initial_count + 1} items, but found {new_count}"
251+
)
252252

253253

254254
def test_handler_with_empty_event(mock_aws_context, mock_pgstac_dsn):
@@ -406,9 +406,9 @@ def test_handler_upsert_existing_item(mock_aws_context, mock_pgstac_dsn, databas
406406
items = get_all_collection_items(database_url, collection_id)
407407
updated_db_item = next((item for item in items if item["id"] == item_id), None)
408408
assert updated_db_item is not None
409-
assert (
410-
updated_db_item["content"]["properties"]["version"] == "2.0"
411-
), "Item was not properly updated with new version"
409+
assert updated_db_item["content"]["properties"]["version"] == "2.0", (
410+
"Item was not properly updated with new version"
411+
)
412412

413413
# Count should remain the same (1 item was updated, not added)
414414
count = count_collection_items(database_url, collection_id)
@@ -480,9 +480,9 @@ def test_handler_with_s3_event(mock_aws_context, mock_pgstac_dsn, database_url):
480480
)
481481

482482
# Verify the item was added to the database
483-
assert check_item_exists(
484-
database_url, collection_id, item_id
485-
), "Item from S3 was not found in the database"
483+
assert check_item_exists(database_url, collection_id, item_id), (
484+
"Item from S3 was not found in the database"
485+
)
486486

487487

488488
def test_handler_with_s3_event_invalid_extension(mock_aws_context, mock_pgstac_dsn):
@@ -632,12 +632,12 @@ def test_handler_with_mixed_s3_and_sqs_events(
632632
assert result is None
633633

634634
# Verify both items were added to the database
635-
assert check_item_exists(
636-
database_url, collection_id, sqs_item_id
637-
), "SQS item was not found in the database"
638-
assert check_item_exists(
639-
database_url, collection_id, s3_item_id
640-
), "S3 item was not found in the database"
635+
assert check_item_exists(database_url, collection_id, sqs_item_id), (
636+
"SQS item was not found in the database"
637+
)
638+
assert check_item_exists(database_url, collection_id, s3_item_id), (
639+
"S3 item was not found in the database"
640+
)
641641

642642

643643
def test_handler_with_s3_event_binary_content(mock_aws_context, mock_pgstac_dsn):
@@ -690,9 +690,9 @@ def test_handler_with_valid_collection(mock_aws_context, mock_pgstac_dsn, databa
690690
assert result is None
691691

692692
# Verify the collection was added to the database
693-
assert check_collection_exists(
694-
database_url, collection_id
695-
), "Collection was not found in the database"
693+
assert check_collection_exists(database_url, collection_id), (
694+
"Collection was not found in the database"
695+
)
696696

697697

698698
def test_handler_with_multiple_collections(
@@ -724,15 +724,15 @@ def test_handler_with_multiple_collections(
724724

725725
# Verify all collections were added
726726
for collection_id in collection_ids:
727-
assert check_collection_exists(
728-
database_url, collection_id
729-
), f"Collection {collection_id} was not found in the database"
727+
assert check_collection_exists(database_url, collection_id), (
728+
f"Collection {collection_id} was not found in the database"
729+
)
730730

731731
# Verify the count increased by the expected amount
732732
new_count = count_collections(database_url)
733-
assert new_count == initial_count + len(
734-
collections
735-
), f"Expected {initial_count + len(collections)} collections, but found {new_count}"
733+
assert new_count == initial_count + len(collections), (
734+
f"Expected {initial_count + len(collections)} collections, but found {new_count}"
735+
)
736736

737737

738738
def test_handler_with_invalid_collection(mock_aws_context, mock_pgstac_dsn):
@@ -790,14 +790,14 @@ def test_handler_with_mixed_collections_and_items(
790790
assert result is None
791791

792792
# Verify the collection was added
793-
assert check_collection_exists(
794-
database_url, collection_id
795-
), "Collection was not found in the database"
793+
assert check_collection_exists(database_url, collection_id), (
794+
"Collection was not found in the database"
795+
)
796796

797797
# Verify the item was added
798-
assert check_item_exists(
799-
database_url, existing_collection_id, item_id
800-
), "Item was not found in the database"
798+
assert check_item_exists(database_url, existing_collection_id, item_id), (
799+
"Item was not found in the database"
800+
)
801801

802802
# Verify counts increased correctly
803803
new_collection_count = count_collections(database_url)
@@ -846,9 +846,9 @@ def test_handler_with_collection_from_s3(mock_aws_context, mock_pgstac_dsn, data
846846
)
847847

848848
# Verify the collection was added to the database
849-
assert check_collection_exists(
850-
database_url, collection_id
851-
), "Collection from S3 was not found in the database"
849+
assert check_collection_exists(database_url, collection_id), (
850+
"Collection from S3 was not found in the database"
851+
)
852852

853853

854854
def test_handler_upsert_existing_collection(
@@ -895,9 +895,9 @@ def test_handler_upsert_existing_collection(
895895
# Verify the collection was updated
896896
updated_db_collection = get_collection(database_url, collection_id)
897897
assert updated_db_collection is not None
898-
assert (
899-
updated_db_collection["content"]["title"] == "Updated Title"
900-
), "Collection was not properly updated with new title"
898+
assert updated_db_collection["content"]["title"] == "Updated Title", (
899+
"Collection was not properly updated with new title"
900+
)
901901

902902
# Count should remain the same (1 collection was updated, not added)
903903
# We can't easily check this without knowing the exact initial count
@@ -1007,15 +1007,15 @@ def test_handler_with_mixed_valid_invalid_collections(
10071007
assert valid_message_id not in failures
10081008

10091009
# Verify only the valid collection was added
1010-
assert check_collection_exists(
1011-
database_url, valid_collection_id
1012-
), "Valid collection was not found in the database"
1010+
assert check_collection_exists(database_url, valid_collection_id), (
1011+
"Valid collection was not found in the database"
1012+
)
10131013

10141014
# Verify count increased by exactly 1
10151015
new_count = count_collections(database_url)
1016-
assert (
1017-
new_count == initial_count + 1
1018-
), f"Expected {initial_count + 1} collections, but found {new_count}"
1016+
assert new_count == initial_count + 1, (
1017+
f"Expected {initial_count + 1} collections, but found {new_count}"
1018+
)
10191019

10201020

10211021
def test_handler_with_malformed_sns_message(mock_aws_context, mock_pgstac_dsn):
@@ -1181,9 +1181,9 @@ def test_handler_creates_missing_collection(
11811181
)
11821182
assert result == 1, "Collection should have been created"
11831183

1184-
assert check_item_exists(
1185-
database_url, missing_collection_id, item_id
1186-
), "Item was not found in the database"
1184+
assert check_item_exists(database_url, missing_collection_id, item_id), (
1185+
"Item was not found in the database"
1186+
)
11871187

11881188

11891189
def test_handler_does_not_create_collection_without_env_var(
@@ -1222,9 +1222,9 @@ def test_handler_does_not_create_collection_without_env_var(
12221222
)
12231223
assert result == 0, "Collection should not have been created"
12241224

1225-
assert not check_item_exists(
1226-
database_url, missing_collection_id, item_id
1227-
), "Item should not have been added to the database"
1225+
assert not check_item_exists(database_url, missing_collection_id, item_id), (
1226+
"Item should not have been added to the database"
1227+
)
12281228

12291229

12301230
@patch.dict(os.environ, {"CREATE_COLLECTIONS_IF_MISSING": "true"})
@@ -1254,13 +1254,13 @@ def test_handler_does_not_recreate_existing_collection(
12541254
current_collection = db.query_one(
12551255
f"SELECT * from collections where id = '{existing_collection_id}'"
12561256
)
1257-
assert (
1258-
current_collection == original_collection
1259-
), "Existing collection should not have been modified"
1257+
assert current_collection == original_collection, (
1258+
"Existing collection should not have been modified"
1259+
)
12601260

1261-
assert check_item_exists(
1262-
database_url, existing_collection_id, item_id
1263-
), "Item was not found in the database"
1261+
assert check_item_exists(database_url, existing_collection_id, item_id), (
1262+
"Item was not found in the database"
1263+
)
12641264

12651265

12661266
@patch.dict(os.environ, {"CREATE_COLLECTIONS_IF_MISSING": "true"})
@@ -1300,9 +1300,9 @@ def test_handler_creates_collection_with_multiple_items(
13001300
assert result == 1, "Collection should have been created exactly once"
13011301

13021302
for item_id in item_ids:
1303-
assert check_item_exists(
1304-
database_url, missing_collection_id, item_id
1305-
), f"Item {item_id} was not found in the database"
1303+
assert check_item_exists(database_url, missing_collection_id, item_id), (
1304+
f"Item {item_id} was not found in the database"
1305+
)
13061306

13071307

13081308
@patch.dict(os.environ, {"CREATE_COLLECTIONS_IF_MISSING": "true"})
@@ -1342,6 +1342,6 @@ def test_handler_collection_creation_failure(
13421342
)
13431343
assert result == 0, "Collection should not have been created due to failure"
13441344

1345-
assert not check_item_exists(
1346-
database_url, missing_collection_id, item_id
1347-
), "Item should not have been added to the database"
1345+
assert not check_item_exists(database_url, missing_collection_id, item_id), (
1346+
"Item should not have been added to the database"
1347+
)

0 commit comments

Comments
 (0)