|
1 | 1 | import getpass |
2 | 2 | import json |
3 | 3 | from datetime import datetime |
| 4 | +from pathlib import Path |
4 | 5 |
|
5 | 6 | import pytest |
6 | 7 | import responses |
@@ -209,31 +210,37 @@ def test_ignores_404_from_delete_call_when_nuking(api_responses, api_token, base |
209 | 210 | webapp.create("3.10", "/virtualenv/path", "/project/path", nuke=True) |
210 | 211 |
|
211 | 212 |
|
212 | | -def test_does_two_posts_to_static_files_endpoint(api_token, api_responses, domain_url, webapp): |
| 213 | +def test_create_static_file_mapping_posts_correctly(api_token, api_responses, domain_url, webapp): |
213 | 214 | static_files_url = f"{domain_url}static_files/" |
214 | 215 | api_responses.add(responses.POST, static_files_url, status=201) |
215 | | - api_responses.add(responses.POST, static_files_url, status=201) |
216 | 216 |
|
217 | | - webapp.add_default_static_files_mappings("/project/path") |
| 217 | + webapp.create_static_file_mapping("/assets/", "/project/assets") |
218 | 218 |
|
219 | | - post1 = api_responses.calls[0] |
220 | | - assert post1.request.url == static_files_url |
221 | | - assert post1.request.headers["content-type"] == "application/json" |
222 | | - assert post1.request.headers["Authorization"] == f"Token {api_token}" |
223 | | - assert json.loads(post1.request.body.decode("utf8")) == { |
224 | | - "url": "/static/", |
225 | | - "path": "/project/path/static", |
226 | | - } |
227 | | - post2 = api_responses.calls[1] |
228 | | - assert post2.request.url == static_files_url |
229 | | - assert post2.request.headers["content-type"] == "application/json" |
230 | | - assert post2.request.headers["Authorization"] == f"Token {api_token}" |
231 | | - assert json.loads(post2.request.body.decode("utf8")) == { |
232 | | - "url": "/media/", |
233 | | - "path": "/project/path/media", |
| 219 | + post = api_responses.calls[0] |
| 220 | + assert post.request.url == static_files_url |
| 221 | + assert post.request.headers["content-type"] == "application/json" |
| 222 | + assert post.request.headers["Authorization"] == f"Token {api_token}" |
| 223 | + assert json.loads(post.request.body.decode("utf8")) == { |
| 224 | + "url": "/assets/", |
| 225 | + "path": "/project/assets", |
234 | 226 | } |
235 | 227 |
|
236 | 228 |
|
| 229 | +def test_adds_default_static_files_mappings(mocker, webapp): |
| 230 | + mock_create = mocker.patch.object(webapp, "create_static_file_mapping") |
| 231 | + |
| 232 | + project_path = "/directory/path" |
| 233 | + webapp.add_default_static_files_mappings(project_path) |
| 234 | + |
| 235 | + mock_create.assert_has_calls( |
| 236 | + [ |
| 237 | + mocker.call("/static/", Path(project_path) / "static"), |
| 238 | + mocker.call("/media/", Path(project_path) / "media"), |
| 239 | + ] |
| 240 | + ) |
| 241 | + |
| 242 | + |
| 243 | + |
237 | 244 | def test_does_post_to_reload_url(api_responses, api_token, domain_url, webapp): |
238 | 245 | reload_url = f"{domain_url}reload/" |
239 | 246 | api_responses.add(responses.POST, reload_url, status=200) |
|
0 commit comments