Skip to content

Commit 458429c

Browse files
committed
Run ruff check --fix
1 parent 8cde26b commit 458429c

File tree

10 files changed

+47
-50
lines changed

10 files changed

+47
-50
lines changed

integration_test/integration_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def get_pdf_for_letter(python_client, id):
121121

122122
count += 3
123123
if count > 45:
124-
print("pdf {} not ready at {} after 45 seconds".format(id, datetime.utcnow()))
124+
print(f"pdf {id} not ready at {datetime.utcnow()} after 45 seconds")
125125
raise
126126
else:
127127
time.sleep(3)

integration_test/schemas/v2/notification_schemas.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def create_post_sms_response_from_notification(notification, body, from_number,
212212
"id": notification.id,
213213
"reference": notification.client_reference,
214214
"content": {"body": body, "from_number": from_number},
215-
"uri": "{}/v2/notifications/{}".format(url_root, str(notification.id)),
215+
"uri": f"{url_root}/v2/notifications/{str(notification.id)}",
216216
"template": __create_template_from_notification(notification=notification, url_root=url_root),
217217
}
218218

@@ -222,7 +222,7 @@ def create_post_email_response_from_notification(notification, content, subject,
222222
"id": notification.id,
223223
"reference": notification.client_reference,
224224
"content": {"from_email": email_from, "body": content, "subject": subject},
225-
"uri": "{}/v2/notifications/{}".format(url_root, str(notification.id)),
225+
"uri": f"{url_root}/v2/notifications/{str(notification.id)}",
226226
"template": __create_template_from_notification(notification=notification, url_root=url_root),
227227
}
228228

@@ -231,5 +231,5 @@ def __create_template_from_notification(notification, url_root):
231231
return {
232232
"id": notification.template_id,
233233
"version": notification.template_version,
234-
"uri": "{}/v2/templates/{}".format(url_root, str(notification.template_id)),
234+
"uri": f"{url_root}/v2/templates/{str(notification.template_id)}",
235235
}

notifications_python_client/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
logger = logging.getLogger(__name__)
1313

1414

15-
class BaseAPIClient(object):
15+
class BaseAPIClient:
1616
def __init__(self, api_key, base_url="https://api.notifications.service.gov.uk", timeout=30):
1717
"""
1818
Initialise the client
@@ -49,8 +49,8 @@ def delete(self, url, data=None):
4949
def generate_headers(self, api_token):
5050
return {
5151
"Content-type": "application/json",
52-
"Authorization": "Bearer {}".format(api_token),
53-
"User-agent": "NOTIFY-API-PYTHON-CLIENT/{}".format(__version__),
52+
"Authorization": f"Bearer {api_token}",
53+
"User-agent": f"NOTIFY-API-PYTHON-CLIENT/{__version__}",
5454
}
5555

5656
def request(self, method, url, data=None, params=None):

notifications_python_client/errors.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from typing import List, Union
21

32
from requests import RequestException, Response
43

@@ -45,10 +44,10 @@ def __init__(self, response: Response = None, message: str = None):
4544
self._message = message
4645

4746
def __str__(self):
48-
return "{} - {}".format(self.status_code, self.message)
47+
return f"{self.status_code} - {self.message}"
4948

5049
@property
51-
def message(self) -> Union[str, List[dict]]:
50+
def message(self) -> str | list[dict]:
5251
try:
5352
json_resp = self.response.json() # type: ignore
5453
return json_resp.get("message", json_resp.get("errors"))
@@ -78,7 +77,6 @@ class HTTP503Error(HTTPError):
7877
Used for detecting whether failed requests should be retried.
7978
"""
8079

81-
pass
8280

8381

8482
class InvalidResponse(APIError):

notifications_python_client/notifications.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ def send_precompiled_letter_notification(self, reference, pdf_file, postage=None
5959

6060
def get_received_texts(self, older_than=None):
6161
if older_than:
62-
query_string = "?older_than={}".format(older_than)
62+
query_string = f"?older_than={older_than}"
6363
else:
6464
query_string = ""
6565

66-
return self.get("/v2/received-text-messages{}".format(query_string))
66+
return self.get(f"/v2/received-text-messages{query_string}")
6767

6868
def get_received_texts_iterator(self, older_than=None):
6969
result = self.get_received_texts(older_than=older_than)
@@ -77,10 +77,10 @@ def get_received_texts_iterator(self, older_than=None):
7777
received_texts = result.get("received_text_messages")
7878

7979
def get_notification_by_id(self, id):
80-
return self.get("/v2/notifications/{}".format(id))
80+
return self.get(f"/v2/notifications/{id}")
8181

8282
def get_pdf_for_letter(self, id):
83-
url = "/v2/notifications/{}/pdf".format(id)
83+
url = f"/v2/notifications/{id}/pdf"
8484
logger.debug("API request %s %s", "GET", url)
8585
url, kwargs = self._create_request_objects(url, data=None, params=None)
8686

@@ -117,18 +117,18 @@ def get_all_notifications_iterator(self, status=None, template_type=None, refere
117117

118118
def post_template_preview(self, template_id, personalisation):
119119
template = {"personalisation": personalisation}
120-
return self.post("/v2/template/{}/preview".format(template_id), data=template)
120+
return self.post(f"/v2/template/{template_id}/preview", data=template)
121121

122122
def get_template(self, template_id):
123-
return self.get("/v2/template/{}".format(template_id))
123+
return self.get(f"/v2/template/{template_id}")
124124

125125
def get_template_version(self, template_id, version):
126-
return self.get("/v2/template/{}/version/{}".format(template_id, version))
126+
return self.get(f"/v2/template/{template_id}/version/{version}")
127127

128128
def get_all_template_versions(self, template_id):
129-
return self.get("service/{}/template/{}/versions".format(self.service_id, template_id))
129+
return self.get(f"service/{self.service_id}/template/{template_id}/versions")
130130

131131
def get_all_templates(self, template_type=None):
132-
_template_type = "?type={}".format(template_type) if template_type else ""
132+
_template_type = f"?type={template_type}" if template_type else ""
133133

134-
return self.get("/v2/templates{}".format(_template_type))
134+
return self.get(f"/v2/templates{_template_type}")

tests/conftest.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import mock
1+
from unittest import mock
2+
23
import pytest
34
import requests_mock
45

@@ -8,7 +9,7 @@
89
TEST_HOST = "http://test-host"
910
SERVICE_ID = "c745a8d8-b48a-4b0d-96e5-dbea0165ebd1"
1011
API_KEY_ID = "8b3aa916-ec82-434e-b0c5-d5d9b371d6a3"
11-
COMBINED_API_KEY = "key_name-{}-{}".format(SERVICE_ID, API_KEY_ID)
12+
COMBINED_API_KEY = f"key_name-{SERVICE_ID}-{API_KEY_ID}"
1213

1314

1415
@pytest.fixture

tests/notifications_python_client/test_authentication.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import calendar
22
import time
3+
from unittest import mock
34

45
import jwt
5-
import mock
66
import pytest
77
from freezegun import freeze_time
88

tests/notifications_python_client/test_base_api_client.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
# -*- coding: utf-8 -*-
21
import re
2+
from unittest import mock
33

4-
import mock
54
import pytest
65
import requests
76

tests/notifications_python_client/test_notifications_api_client.py

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import base64
22
import io
3-
4-
from mock import Mock
3+
from unittest.mock import Mock
54

65
from notifications_python_client import prepare_upload
76
from tests.conftest import TEST_HOST
@@ -17,7 +16,7 @@ def test_get_notification_by_id(notifications_client, rmock):
1716

1817

1918
def test_get_received_texts(notifications_client, rmock):
20-
endpoint = "{0}/v2/received-text-messages".format(TEST_HOST)
19+
endpoint = f"{TEST_HOST}/v2/received-text-messages"
2120
rmock.request("GET", endpoint, json={"status": "success"}, status_code=200)
2221

2322
notifications_client.get_received_texts()
@@ -33,7 +32,7 @@ def test_get_received_texts_older_than(notifications_client, rmock):
3332

3433

3534
def test_get_all_received_texts_iterator_calls_get_received_texts(notifications_client, rmock):
36-
endpoint = "{0}/v2/received-text-messages".format(TEST_HOST)
35+
endpoint = f"{TEST_HOST}/v2/received-text-messages"
3736
rmock.request("GET", endpoint, json={"status": "success"}, status_code=200)
3837

3938
list(notifications_client.get_received_texts_iterator())
@@ -95,7 +94,7 @@ def test_get_all_notifications_including_jobs(notifications_client, rmock):
9594

9695

9796
def test_get_all_notifications(notifications_client, rmock):
98-
endpoint = "{0}/v2/notifications".format(TEST_HOST)
97+
endpoint = f"{TEST_HOST}/v2/notifications"
9998
rmock.request("GET", endpoint, json={"status": "success"}, status_code=200)
10099

101100
notifications_client.get_all_notifications()
@@ -104,7 +103,7 @@ def test_get_all_notifications(notifications_client, rmock):
104103

105104

106105
def test_create_sms_notification(notifications_client, rmock):
107-
endpoint = "{0}/v2/notifications/sms".format(TEST_HOST)
106+
endpoint = f"{TEST_HOST}/v2/notifications/sms"
108107
rmock.request("POST", endpoint, json={"status": "success"}, status_code=200)
109108

110109
notifications_client.send_sms_notification(phone_number="07700 900000", template_id="456")
@@ -113,7 +112,7 @@ def test_create_sms_notification(notifications_client, rmock):
113112

114113

115114
def test_create_sms_notification_with_personalisation(notifications_client, rmock):
116-
endpoint = "{0}/v2/notifications/sms".format(TEST_HOST)
115+
endpoint = f"{TEST_HOST}/v2/notifications/sms"
117116
rmock.request("POST", endpoint, json={"status": "success"}, status_code=200)
118117

119118
notifications_client.send_sms_notification(
@@ -128,7 +127,7 @@ def test_create_sms_notification_with_personalisation(notifications_client, rmoc
128127

129128

130129
def test_create_sms_notification_with_sms_sender_id(notifications_client, rmock):
131-
endpoint = "{0}/v2/notifications/sms".format(TEST_HOST)
130+
endpoint = f"{TEST_HOST}/v2/notifications/sms"
132131
rmock.request("POST", endpoint, json={"status": "success"}, status_code=200)
133132

134133
notifications_client.send_sms_notification(phone_number="07700 900000", template_id="456", sms_sender_id="789")
@@ -137,7 +136,7 @@ def test_create_sms_notification_with_sms_sender_id(notifications_client, rmock)
137136

138137

139138
def test_create_email_notification(notifications_client, rmock):
140-
endpoint = "{0}/v2/notifications/email".format(TEST_HOST)
139+
endpoint = f"{TEST_HOST}/v2/notifications/email"
141140
rmock.request("POST", endpoint, json={"status": "success"}, status_code=200)
142141

143142
notifications_client.send_email_notification(email_address="[email protected]", template_id="456")
@@ -146,7 +145,7 @@ def test_create_email_notification(notifications_client, rmock):
146145

147146

148147
def test_create_email_notification_with_email_reply_to_id(notifications_client, rmock):
149-
endpoint = "{0}/v2/notifications/email".format(TEST_HOST)
148+
endpoint = f"{TEST_HOST}/v2/notifications/email"
150149
rmock.request("POST", endpoint, json={"status": "success"}, status_code=200)
151150

152151
notifications_client.send_email_notification(
@@ -161,7 +160,7 @@ def test_create_email_notification_with_email_reply_to_id(notifications_client,
161160

162161

163162
def test_create_email_notification_with_personalisation(notifications_client, rmock):
164-
endpoint = "{0}/v2/notifications/email".format(TEST_HOST)
163+
endpoint = f"{TEST_HOST}/v2/notifications/email"
165164
rmock.request("POST", endpoint, json={"status": "success"}, status_code=200)
166165

167166
notifications_client.send_email_notification(
@@ -195,7 +194,7 @@ def test_create_email_notification_with_one_click_unsubscribe_url(notifications_
195194

196195

197196
def test_create_email_notification_with_document_stream_upload(notifications_client, rmock):
198-
endpoint = "{0}/v2/notifications/email".format(TEST_HOST)
197+
endpoint = f"{TEST_HOST}/v2/notifications/email"
199198
rmock.request("POST", endpoint, json={"status": "success"}, status_code=200)
200199

201200
if hasattr(io, "BytesIO"):
@@ -225,7 +224,7 @@ def test_create_email_notification_with_document_stream_upload(notifications_cli
225224

226225

227226
def test_create_email_notification_with_document_file_upload(notifications_client, rmock):
228-
endpoint = "{0}/v2/notifications/email".format(TEST_HOST)
227+
endpoint = f"{TEST_HOST}/v2/notifications/email"
229228
rmock.request("POST", endpoint, json={"status": "success"}, status_code=200)
230229

231230
with open("tests/test_files/test.pdf", "rb") as f:
@@ -251,7 +250,7 @@ def test_create_email_notification_with_document_file_upload(notifications_clien
251250

252251

253252
def test_create_email_notification_with_csv_file_upload(notifications_client, rmock):
254-
endpoint = "{0}/v2/notifications/email".format(TEST_HOST)
253+
endpoint = f"{TEST_HOST}/v2/notifications/email"
255254
rmock.request("POST", endpoint, json={"status": "success"}, status_code=200)
256255

257256
with open("tests/test_files/test.csv", "rb") as f:
@@ -277,7 +276,7 @@ def test_create_email_notification_with_csv_file_upload(notifications_client, rm
277276

278277

279278
def test_create_letter_notification(notifications_client, rmock):
280-
endpoint = "{0}/v2/notifications/letter".format(TEST_HOST)
279+
endpoint = f"{TEST_HOST}/v2/notifications/letter"
281280
rmock.request("POST", endpoint, json={"status": "success"}, status_code=200)
282281

283282
notifications_client.send_letter_notification(
@@ -291,7 +290,7 @@ def test_create_letter_notification(notifications_client, rmock):
291290

292291

293292
def test_create_letter_notification_with_reference(notifications_client, rmock):
294-
endpoint = "{0}/v2/notifications/letter".format(TEST_HOST)
293+
endpoint = f"{TEST_HOST}/v2/notifications/letter"
295294
rmock.request("POST", endpoint, json={"status": "success"}, status_code=200)
296295

297296
notifications_client.send_letter_notification(
@@ -308,7 +307,7 @@ def test_create_letter_notification_with_reference(notifications_client, rmock):
308307

309308

310309
def test_send_precompiled_letter_notification(notifications_client, rmock, mocker):
311-
endpoint = "{0}/v2/notifications/letter".format(TEST_HOST)
310+
endpoint = f"{TEST_HOST}/v2/notifications/letter"
312311
rmock.request("POST", endpoint, json={"status": "success"}, status_code=200)
313312
mock_file = Mock(
314313
read=Mock(return_value=b"file_contents"),
@@ -323,7 +322,7 @@ def test_send_precompiled_letter_notification(notifications_client, rmock, mocke
323322

324323

325324
def test_send_precompiled_letter_notification_sets_postage(notifications_client, rmock, mocker):
326-
endpoint = "{0}/v2/notifications/letter".format(TEST_HOST)
325+
endpoint = f"{TEST_HOST}/v2/notifications/letter"
327326
rmock.request("POST", endpoint, json={"status": "success"}, status_code=200)
328327
mock_file = Mock(
329328
read=Mock(return_value=b"file_contents"),
@@ -339,7 +338,7 @@ def test_send_precompiled_letter_notification_sets_postage(notifications_client,
339338

340339

341340
def test_get_all_notifications_iterator_calls_get_notifications(notifications_client, rmock):
342-
endpoint = "{0}/v2/notifications".format(TEST_HOST)
341+
endpoint = f"{TEST_HOST}/v2/notifications"
343342
rmock.request("GET", endpoint, json={"status": "success"}, status_code=200)
344343

345344
list(notifications_client.get_all_notifications_iterator())
@@ -353,7 +352,7 @@ def test_get_all_notifications_iterator_stops_if_empty_notification_list_returne
353352
_generate_response("3e8f2f0a-0f2b-4d1b-8a01-761f14a281bb", []),
354353
]
355354

356-
endpoint = "{0}/v2/notifications".format(TEST_HOST)
355+
endpoint = f"{TEST_HOST}/v2/notifications"
357356
rmock.request("GET", endpoint, responses)
358357

359358
list(notifications_client.get_all_notifications_iterator())
@@ -367,7 +366,7 @@ def test_get_all_notifications_iterator_gets_more_notifications_with_correct_id(
367366
_generate_response("3e8f2f0a-0f2b-4d1b-8a01-761f14a281bb", []),
368367
]
369368

370-
endpoint = "{0}/v2/notifications".format(TEST_HOST)
369+
endpoint = f"{TEST_HOST}/v2/notifications"
371370
rmock.request("GET", endpoint, responses)
372371
list(notifications_client.get_all_notifications_iterator())
373372
assert rmock.call_count == 3
@@ -402,7 +401,7 @@ def test_post_template_preview(notifications_client, rmock):
402401

403402

404403
def test_get_all_templates(notifications_client, rmock):
405-
endpoint = "{0}/v2/templates".format(TEST_HOST)
404+
endpoint = f"{TEST_HOST}/v2/templates"
406405
rmock.request("GET", endpoint, json={"status": "success"}, status_code=200)
407406

408407
notifications_client.get_all_templates()
@@ -434,7 +433,7 @@ def _generate_response(next_link_uuid, notifications: list):
434433
return {
435434
"json": {
436435
"notifications": notifications,
437-
"links": {"next": "http://localhost:6011/v2/notifications?older_than={}".format(next_link_uuid)},
436+
"links": {"next": f"http://localhost:6011/v2/notifications?older_than={next_link_uuid}"},
438437
},
439438
"status_code": 200,
440439
}

utils/make_api_call.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def create_notification(notifications_client, **kwargs):
3838
return create_letter_notification(notifications_client, **kwargs)
3939
if notification_type == "precompiled_letter":
4040
return create_precompiled_letter_notification(notifications_client, **kwargs)
41-
print("Invalid type: {}, exiting".format(notification_type))
41+
print(f"Invalid type: {notification_type}, exiting")
4242
sys.exit(1)
4343

4444

0 commit comments

Comments
 (0)