12
12
13
13
import pytest
14
14
import requests
15
+ from freezegun import freeze_time
15
16
from rest_framework .test import APIClient
16
17
17
18
from core import factories , models
@@ -52,9 +53,11 @@ def test_api_documents_media_auth_anonymous_public():
52
53
factories .DocumentFactory (id = document_id , link_reach = "public" , attachments = [key ])
53
54
54
55
original_url = f"http://localhost/media/{ key :s} "
55
- response = APIClient ().get (
56
- "/api/v1.0/documents/media-auth/" , HTTP_X_ORIGINAL_URL = original_url
57
- )
56
+ now = timezone .now ()
57
+ with freeze_time (now ):
58
+ response = APIClient ().get (
59
+ "/api/v1.0/documents/media-auth/" , HTTP_X_ORIGINAL_URL = original_url
60
+ )
58
61
59
62
assert response .status_code == 200
60
63
@@ -64,7 +67,7 @@ def test_api_documents_media_auth_anonymous_public():
64
67
"SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature="
65
68
in authorization
66
69
)
67
- assert response ["X-Amz-Date" ] == timezone . now () .strftime ("%Y%m%dT%H%M%SZ" )
70
+ assert response ["X-Amz-Date" ] == now .strftime ("%Y%m%dT%H%M%SZ" )
68
71
69
72
s3_url = urlparse (settings .AWS_S3_ENDPOINT_URL )
70
73
file_url = f"{ settings .AWS_S3_ENDPOINT_URL :s} /impress-media-storage/{ key :s} "
@@ -167,9 +170,11 @@ def test_api_documents_media_auth_anonymous_attachments():
167
170
parent = factories .DocumentFactory (link_reach = "public" )
168
171
factories .DocumentFactory (parent = parent , link_reach = "restricted" , attachments = [key ])
169
172
170
- response = APIClient ().get (
171
- "/api/v1.0/documents/media-auth/" , HTTP_X_ORIGINAL_URL = media_url
172
- )
173
+ now = timezone .now ()
174
+ with freeze_time (now ):
175
+ response = APIClient ().get (
176
+ "/api/v1.0/documents/media-auth/" , HTTP_X_ORIGINAL_URL = media_url
177
+ )
173
178
174
179
assert response .status_code == 200
175
180
@@ -179,7 +184,7 @@ def test_api_documents_media_auth_anonymous_attachments():
179
184
"SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature="
180
185
in authorization
181
186
)
182
- assert response ["X-Amz-Date" ] == timezone . now () .strftime ("%Y%m%dT%H%M%SZ" )
187
+ assert response ["X-Amz-Date" ] == now .strftime ("%Y%m%dT%H%M%SZ" )
183
188
184
189
s3_url = urlparse (settings .AWS_S3_ENDPOINT_URL )
185
190
file_url = f"{ settings .AWS_S3_ENDPOINT_URL :s} /impress-media-storage/{ key :s} "
@@ -221,9 +226,11 @@ def test_api_documents_media_auth_authenticated_public_or_authenticated(reach):
221
226
222
227
factories .DocumentFactory (id = document_id , link_reach = reach , attachments = [key ])
223
228
224
- response = client .get (
225
- "/api/v1.0/documents/media-auth/" , HTTP_X_ORIGINAL_URL = media_url
226
- )
229
+ now = timezone .now ()
230
+ with freeze_time (now ):
231
+ response = client .get (
232
+ "/api/v1.0/documents/media-auth/" , HTTP_X_ORIGINAL_URL = media_url
233
+ )
227
234
228
235
assert response .status_code == 200
229
236
@@ -233,7 +240,7 @@ def test_api_documents_media_auth_authenticated_public_or_authenticated(reach):
233
240
"SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature="
234
241
in authorization
235
242
)
236
- assert response ["X-Amz-Date" ] == timezone . now () .strftime ("%Y%m%dT%H%M%SZ" )
243
+ assert response ["X-Amz-Date" ] == now .strftime ("%Y%m%dT%H%M%SZ" )
237
244
238
245
s3_url = urlparse (settings .AWS_S3_ENDPOINT_URL )
239
246
file_url = f"{ settings .AWS_S3_ENDPOINT_URL :s} /impress-media-storage/{ key :s} "
@@ -307,9 +314,11 @@ def test_api_documents_media_auth_related(via, mock_user_teams):
307
314
mock_user_teams .return_value = ["lasuite" , "unknown" ]
308
315
factories .TeamDocumentAccessFactory (document = document , team = "lasuite" )
309
316
310
- response = client .get (
311
- "/api/v1.0/documents/media-auth/" , HTTP_X_ORIGINAL_URL = media_url
312
- )
317
+ now = timezone .now ()
318
+ with freeze_time (now ):
319
+ response = client .get (
320
+ "/api/v1.0/documents/media-auth/" , HTTP_X_ORIGINAL_URL = media_url
321
+ )
313
322
314
323
assert response .status_code == 200
315
324
@@ -319,7 +328,7 @@ def test_api_documents_media_auth_related(via, mock_user_teams):
319
328
"SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature="
320
329
in authorization
321
330
)
322
- assert response ["X-Amz-Date" ] == timezone . now () .strftime ("%Y%m%dT%H%M%SZ" )
331
+ assert response ["X-Amz-Date" ] == now .strftime ("%Y%m%dT%H%M%SZ" )
323
332
324
333
s3_url = urlparse (settings .AWS_S3_ENDPOINT_URL )
325
334
file_url = f"{ settings .AWS_S3_ENDPOINT_URL :s} /impress-media-storage/{ key :s} "
@@ -373,10 +382,12 @@ def test_api_documents_media_auth_missing_status_metadata():
373
382
374
383
factories .DocumentFactory (id = document_id , link_reach = "public" , attachments = [key ])
375
384
385
+ now = timezone .now ()
376
386
original_url = f"http://localhost/media/{ key :s} "
377
- response = APIClient ().get (
378
- "/api/v1.0/documents/media-auth/" , HTTP_X_ORIGINAL_URL = original_url
379
- )
387
+ with freeze_time (now ):
388
+ response = APIClient ().get (
389
+ "/api/v1.0/documents/media-auth/" , HTTP_X_ORIGINAL_URL = original_url
390
+ )
380
391
381
392
assert response .status_code == 200
382
393
@@ -386,7 +397,7 @@ def test_api_documents_media_auth_missing_status_metadata():
386
397
"SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature="
387
398
in authorization
388
399
)
389
- assert response ["X-Amz-Date" ] == timezone . now () .strftime ("%Y%m%dT%H%M%SZ" )
400
+ assert response ["X-Amz-Date" ] == now .strftime ("%Y%m%dT%H%M%SZ" )
390
401
391
402
s3_url = urlparse (settings .AWS_S3_ENDPOINT_URL )
392
403
file_url = f"{ settings .AWS_S3_ENDPOINT_URL :s} /impress-media-storage/{ key :s} "
0 commit comments