Skip to content

Commit b21389a

Browse files
committed
Enforce linting
1 parent f440aec commit b21389a

13 files changed

+61
-21
lines changed

.flake8

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[flake8]
2+
max-line-length = 100
3+
exclude = .git, .venv, .virtualenv, .tox, dist, doc, *egg, build, tools, templates, styles, static

.pylintrc

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[MESSAGES CONTROL]
2+
disable=
3+
missing-docstring,
4+
too-few-public-methods,
5+
too-many-public-methods,
6+
too-many-lines,
7+
logging-fstring-interpolation,
8+
9+
[SIMILARITIES]
10+
min-similarity-lines=5
11+
ignore-comments=yes
12+
ignore-docstrings=yes
13+
ignore-imports=yes
14+
15+
max-args = 10

Makefile

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: install install-dev start start-services stop-services delete-db
1+
.PHONY: install install-dev start start-services stop-services delete-db flake8 pylint lint
22

33
install:
44
pip install -r requirements.txt
@@ -17,3 +17,11 @@ stop-services:
1717

1818
delete-db: stop-services
1919
docker volume rm coar-notify-inbox_mongodb_data
20+
21+
flake8:
22+
flake8
23+
24+
pylint:
25+
pylint --fail-under=10 db routers tasks tests validation app.py config.py
26+
27+
lint: flake8 pylint

app.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
allow_headers=["*"],
2626
)
2727

28-
app.mount("/static", StaticFiles(directory=os.path.join(os.path.dirname(__file__), "static")), name="static")
28+
app.mount("/static",
29+
StaticFiles(directory=os.path.join(os.path.dirname(__file__), "static")), name="static")
2930
app.include_router(inbox_router)
3031

3132

db/__init__.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,5 @@ async def get_db():
88
return client.notification_store
99

1010

11-
async def get_collection(db, collection_name: str):
12-
return db[collection_name]
13-
14-
11+
async def get_collection(database, collection_name: str):
12+
return database[collection_name]

db/notifications.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212

1313

1414
async def _get_notifications_collection():
15-
db = await get_db()
16-
return await get_collection(db, NOTIFICATIONS_COLLECTION_NAME)
15+
database = await get_db()
16+
return await get_collection(database, NOTIFICATIONS_COLLECTION_NAME)
1717

1818

1919
async def _get_notification_states_collection():
20-
db = await get_db()
21-
return await get_collection(db, NOTIFICATION_STATES_COLLECTION_NAME)
20+
database = await get_db()
21+
return await get_collection(database, NOTIFICATION_STATES_COLLECTION_NAME)
2222

2323

2424
async def create_notification(notification: Notification) -> str:

mypy.ini

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[mypy]
2+
ignore_missing_imports = True

requirements.dev.txt

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
httpx==0.24.1
2+
flake8==6.1.0
3+
pylint==2.17.5
24
pytest==7.4.0
35
pytest-asyncio==0.21.1

routers/inbox.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ async def read_inbox(request: Request) -> JSONResponse:
5151

5252

5353
@router.post("/")
54-
async def add_notification(request: Request, background_tasks: BackgroundTasks, payload: dict = Body(...)):
54+
async def add_notification(request: Request, background_tasks: BackgroundTasks,
55+
payload: dict = Body(...)):
5556
conforms, errors = validate_notification(payload)
5657

5758
if not conforms:

tasks/webhooks.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ def send_notification_to_webhook(notification: Notification, webhook_url: str) -
1414
response = requests.post(
1515
url=webhook_url,
1616
headers={"content-type": "application/ld+json"},
17-
json=json.dumps(notification, default=str)
17+
json=json.dumps(notification, default=str),
18+
timeout=(10, 10),
1819
)
1920

2021
response.raise_for_status()
2122

22-
logger.info(f"Successfully sent notification to {webhook_url}. Status code: {response.status_code}")
23+
logger.info(f"Successfully sent notification to {webhook_url}. "
24+
f"Status code: {response.status_code}")
2325
except requests.RequestException:
2426
logger.exception(f"Failed to send notification to {webhook_url}")

tests/app_test.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from fastapi.testclient import TestClient
21
from unittest.mock import patch
32

3+
from fastapi.testclient import TestClient
4+
45
from app import app
56

67
client = TestClient(app)

tests/conftest.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ def valid_offer_review_payload():
102102
},
103103
"id": "urn:uuid:0370c0fb-bb78-4a9b-87f5-bed307a509dd",
104104
"object": {
105-
"id": "https://research-organisation.org/repository/preprint/201203/421/",
105+
"id": "https://research.org/repository/preprint/201203/421/",
106106
"ietf:cite-as": "https://doi.org/10.5555/12345680",
107107
"type": "sorg:AboutPage",
108108
"url": {
109-
"id": "https://research-organisation.org/repository/preprint/201203/421/content.pdf",
109+
"id": "https://research.org/repository/preprint/201203/421/content.pdf",
110110
"mediaType": "application/pdf",
111111
"type": [
112112
"Article",
@@ -115,8 +115,8 @@ def valid_offer_review_payload():
115115
}
116116
},
117117
"origin": {
118-
"id": "https://research-organisation.org/repository",
119-
"inbox": "https://research-organisation.org/inbox/",
118+
"id": "https://research.org/repository",
119+
"inbox": "https://research.org/inbox/",
120120
"type": "Service"
121121
},
122122
"target": {

tests/db/notifications_test.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
import pytest
21
from unittest.mock import AsyncMock, patch
2+
3+
import pytest
4+
35
from db.models import Notification
4-
from db.notifications import create_notification, get_notification, get_notifications, delete_notification
6+
from db.notifications import (
7+
create_notification,
8+
get_notification,
9+
get_notifications,
10+
delete_notification,
11+
)
512

613

714
@patch('db.notifications.get_db')
@@ -67,4 +74,4 @@ async def test_delete_notification(mock_get_collection, mock_get_db, notificatio
6774

6875
mock_get_db.assert_called_once()
6976
mock_get_collection.assert_called_once()
70-
mock_get_collection.return_value.delete_one.assert_called_once()
77+
mock_get_collection.return_value.delete_one.assert_called_once()

0 commit comments

Comments
 (0)