1
1
import base64
2
2
import io
3
-
4
- from mock import Mock
3
+ from unittest .mock import Mock
5
4
6
5
from notifications_python_client import prepare_upload
7
6
from tests .conftest import TEST_HOST
@@ -17,7 +16,7 @@ def test_get_notification_by_id(notifications_client, rmock):
17
16
18
17
19
18
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"
21
20
rmock .request ("GET" , endpoint , json = {"status" : "success" }, status_code = 200 )
22
21
23
22
notifications_client .get_received_texts ()
@@ -33,7 +32,7 @@ def test_get_received_texts_older_than(notifications_client, rmock):
33
32
34
33
35
34
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"
37
36
rmock .request ("GET" , endpoint , json = {"status" : "success" }, status_code = 200 )
38
37
39
38
list (notifications_client .get_received_texts_iterator ())
@@ -95,7 +94,7 @@ def test_get_all_notifications_including_jobs(notifications_client, rmock):
95
94
96
95
97
96
def test_get_all_notifications (notifications_client , rmock ):
98
- endpoint = "{0 }/v2/notifications". format ( TEST_HOST )
97
+ endpoint = f" { TEST_HOST } /v2/notifications"
99
98
rmock .request ("GET" , endpoint , json = {"status" : "success" }, status_code = 200 )
100
99
101
100
notifications_client .get_all_notifications ()
@@ -104,7 +103,7 @@ def test_get_all_notifications(notifications_client, rmock):
104
103
105
104
106
105
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"
108
107
rmock .request ("POST" , endpoint , json = {"status" : "success" }, status_code = 200 )
109
108
110
109
notifications_client .send_sms_notification (phone_number = "07700 900000" , template_id = "456" )
@@ -113,7 +112,7 @@ def test_create_sms_notification(notifications_client, rmock):
113
112
114
113
115
114
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"
117
116
rmock .request ("POST" , endpoint , json = {"status" : "success" }, status_code = 200 )
118
117
119
118
notifications_client .send_sms_notification (
@@ -128,7 +127,7 @@ def test_create_sms_notification_with_personalisation(notifications_client, rmoc
128
127
129
128
130
129
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"
132
131
rmock .request ("POST" , endpoint , json = {"status" : "success" }, status_code = 200 )
133
132
134
133
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)
137
136
138
137
139
138
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"
141
140
rmock .request ("POST" , endpoint , json = {"status" : "success" }, status_code = 200 )
142
141
143
142
notifications_client .
send_email_notification (
email_address = "[email protected] " ,
template_id = "456" )
@@ -146,7 +145,7 @@ def test_create_email_notification(notifications_client, rmock):
146
145
147
146
148
147
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"
150
149
rmock .request ("POST" , endpoint , json = {"status" : "success" }, status_code = 200 )
151
150
152
151
notifications_client .send_email_notification (
@@ -161,7 +160,7 @@ def test_create_email_notification_with_email_reply_to_id(notifications_client,
161
160
162
161
163
162
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"
165
164
rmock .request ("POST" , endpoint , json = {"status" : "success" }, status_code = 200 )
166
165
167
166
notifications_client .send_email_notification (
@@ -195,7 +194,7 @@ def test_create_email_notification_with_one_click_unsubscribe_url(notifications_
195
194
196
195
197
196
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"
199
198
rmock .request ("POST" , endpoint , json = {"status" : "success" }, status_code = 200 )
200
199
201
200
if hasattr (io , "BytesIO" ):
@@ -225,7 +224,7 @@ def test_create_email_notification_with_document_stream_upload(notifications_cli
225
224
226
225
227
226
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"
229
228
rmock .request ("POST" , endpoint , json = {"status" : "success" }, status_code = 200 )
230
229
231
230
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
251
250
252
251
253
252
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"
255
254
rmock .request ("POST" , endpoint , json = {"status" : "success" }, status_code = 200 )
256
255
257
256
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
277
276
278
277
279
278
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"
281
280
rmock .request ("POST" , endpoint , json = {"status" : "success" }, status_code = 200 )
282
281
283
282
notifications_client .send_letter_notification (
@@ -291,7 +290,7 @@ def test_create_letter_notification(notifications_client, rmock):
291
290
292
291
293
292
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"
295
294
rmock .request ("POST" , endpoint , json = {"status" : "success" }, status_code = 200 )
296
295
297
296
notifications_client .send_letter_notification (
@@ -308,7 +307,7 @@ def test_create_letter_notification_with_reference(notifications_client, rmock):
308
307
309
308
310
309
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"
312
311
rmock .request ("POST" , endpoint , json = {"status" : "success" }, status_code = 200 )
313
312
mock_file = Mock (
314
313
read = Mock (return_value = b"file_contents" ),
@@ -323,7 +322,7 @@ def test_send_precompiled_letter_notification(notifications_client, rmock, mocke
323
322
324
323
325
324
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"
327
326
rmock .request ("POST" , endpoint , json = {"status" : "success" }, status_code = 200 )
328
327
mock_file = Mock (
329
328
read = Mock (return_value = b"file_contents" ),
@@ -339,7 +338,7 @@ def test_send_precompiled_letter_notification_sets_postage(notifications_client,
339
338
340
339
341
340
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"
343
342
rmock .request ("GET" , endpoint , json = {"status" : "success" }, status_code = 200 )
344
343
345
344
list (notifications_client .get_all_notifications_iterator ())
@@ -353,7 +352,7 @@ def test_get_all_notifications_iterator_stops_if_empty_notification_list_returne
353
352
_generate_response ("3e8f2f0a-0f2b-4d1b-8a01-761f14a281bb" , []),
354
353
]
355
354
356
- endpoint = "{0 }/v2/notifications". format ( TEST_HOST )
355
+ endpoint = f" { TEST_HOST } /v2/notifications"
357
356
rmock .request ("GET" , endpoint , responses )
358
357
359
358
list (notifications_client .get_all_notifications_iterator ())
@@ -367,7 +366,7 @@ def test_get_all_notifications_iterator_gets_more_notifications_with_correct_id(
367
366
_generate_response ("3e8f2f0a-0f2b-4d1b-8a01-761f14a281bb" , []),
368
367
]
369
368
370
- endpoint = "{0 }/v2/notifications". format ( TEST_HOST )
369
+ endpoint = f" { TEST_HOST } /v2/notifications"
371
370
rmock .request ("GET" , endpoint , responses )
372
371
list (notifications_client .get_all_notifications_iterator ())
373
372
assert rmock .call_count == 3
@@ -402,7 +401,7 @@ def test_post_template_preview(notifications_client, rmock):
402
401
403
402
404
403
def test_get_all_templates (notifications_client , rmock ):
405
- endpoint = "{0 }/v2/templates". format ( TEST_HOST )
404
+ endpoint = f" { TEST_HOST } /v2/templates"
406
405
rmock .request ("GET" , endpoint , json = {"status" : "success" }, status_code = 200 )
407
406
408
407
notifications_client .get_all_templates ()
@@ -434,7 +433,7 @@ def _generate_response(next_link_uuid, notifications: list):
434
433
return {
435
434
"json" : {
436
435
"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 } " },
438
437
},
439
438
"status_code" : 200 ,
440
439
}
0 commit comments