File tree 2 files changed +15
-9
lines changed
src/backend/core/tests/documents
2 files changed +15
-9
lines changed Original file line number Diff line number Diff line change 14
14
import pycrdt
15
15
import pytest
16
16
import requests
17
+ from freezegun import freeze_time
17
18
from rest_framework .test import APIClient
18
19
19
20
from core import factories , models
@@ -133,19 +134,21 @@ def test_api_documents_duplicate_success(index):
133
134
134
135
# Ensure access persists after the owner loses access to the original document
135
136
models .DocumentAccess .objects .filter (document = document ).delete ()
136
- response = client .get (
137
- "/api/v1.0/documents/media-auth/" , HTTP_X_ORIGINAL_URL = image_refs [0 ][1 ]
138
- )
139
137
140
- assert response .status_code == 200
138
+ now = timezone .now ()
139
+ with freeze_time (now ):
140
+ response = client .get (
141
+ "/api/v1.0/documents/media-auth/" , HTTP_X_ORIGINAL_URL = image_refs [0 ][1 ]
142
+ )
141
143
144
+ assert response .status_code == 200
145
+ assert response ["X-Amz-Date" ] == now .strftime ("%Y%m%dT%H%M%SZ" )
142
146
authorization = response ["Authorization" ]
143
147
assert "AWS4-HMAC-SHA256 Credential=" in authorization
144
148
assert (
145
149
"SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature="
146
150
in authorization
147
151
)
148
- assert response ["X-Amz-Date" ] == timezone .now ().strftime ("%Y%m%dT%H%M%SZ" )
149
152
150
153
s3_url = urlparse (settings .AWS_S3_ENDPOINT_URL )
151
154
response = requests .get (
Original file line number Diff line number Diff line change 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
@@ -50,9 +51,11 @@ def test_api_documents_media_auth_anonymous_public():
50
51
factories .DocumentFactory (id = document_id , link_reach = "public" , attachments = [key ])
51
52
52
53
original_url = f"http://localhost/media/{ key :s} "
53
- response = APIClient ().get (
54
- "/api/v1.0/documents/media-auth/" , HTTP_X_ORIGINAL_URL = original_url
55
- )
54
+ now = timezone .now ()
55
+ with freeze_time (now ):
56
+ response = APIClient ().get (
57
+ "/api/v1.0/documents/media-auth/" , HTTP_X_ORIGINAL_URL = original_url
58
+ )
56
59
57
60
assert response .status_code == 200
58
61
@@ -62,7 +65,7 @@ def test_api_documents_media_auth_anonymous_public():
62
65
"SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature="
63
66
in authorization
64
67
)
65
- assert response ["X-Amz-Date" ] == timezone . now () .strftime ("%Y%m%dT%H%M%SZ" )
68
+ assert response ["X-Amz-Date" ] == now .strftime ("%Y%m%dT%H%M%SZ" )
66
69
67
70
s3_url = urlparse (settings .AWS_S3_ENDPOINT_URL )
68
71
file_url = f"{ settings .AWS_S3_ENDPOINT_URL :s} /impress-media-storage/{ key :s} "
You can’t perform that action at this time.
0 commit comments