|
7 | 7 | from event.models import Event |
8 | 8 | from event.presentation.models import Presentation, PresentationType |
9 | 9 | from event.presentation.test.conftest import PresentationTestEntity |
| 10 | +from file.models import PublicFile |
10 | 11 | from rest_framework.test import APIClient |
11 | 12 | from user.models.organization import Organization |
12 | 13 |
|
@@ -86,3 +87,56 @@ def test_presentation_defaults_to_latest_event(api_client: APIClient): |
86 | 87 | response_data = response.json() |
87 | 88 | assert len(response_data) == 1 |
88 | 89 | assert response_data[0]["id"] == str(new_prst.id) |
| 90 | + |
| 91 | + |
| 92 | +def _make_public_file(name: str) -> PublicFile: |
| 93 | + return PublicFile.objects.create(file=f"public/{name}.png", mimetype="image/png", hash=name, size=0) |
| 94 | + |
| 95 | + |
| 96 | +def _get_speaker_image(api_client: APIClient) -> str | None: |
| 97 | + response = api_client.get(reverse("v1:presentation-list")) |
| 98 | + assert response.status_code == http.HTTPStatus.OK |
| 99 | + return response.json()[0]["speakers"][0]["image"] |
| 100 | + |
| 101 | + |
| 102 | +@pytest.mark.django_db |
| 103 | +def test_speaker_image_falls_back_to_profile_image( |
| 104 | + api_client: APIClient, create_presentation_set: PresentationTestEntity |
| 105 | +): |
| 106 | + # Given: 발표자 이미지는 비어 있고 프로필 이미지만 등록된 발표자 |
| 107 | + user = create_presentation_set.user |
| 108 | + user.image = _make_public_file("profile") |
| 109 | + user.save() |
| 110 | + |
| 111 | + # Then: 프로필 이미지가 대신 노출된다. |
| 112 | + image_url = _get_speaker_image(api_client) |
| 113 | + assert image_url is not None and image_url.endswith(user.image.file.url) |
| 114 | + |
| 115 | + |
| 116 | +@pytest.mark.django_db |
| 117 | +def test_speaker_image_takes_precedence_over_profile_image( |
| 118 | + api_client: APIClient, create_presentation_set: PresentationTestEntity |
| 119 | +): |
| 120 | + # Given: 발표자 이미지와 프로필 이미지가 모두 등록된 발표자 |
| 121 | + user = create_presentation_set.user |
| 122 | + user.image = _make_public_file("profile") |
| 123 | + user.save() |
| 124 | + |
| 125 | + speaker = create_presentation_set.presentation_speaker |
| 126 | + speaker.image = _make_public_file("speaker") |
| 127 | + speaker.save() |
| 128 | + |
| 129 | + # Then: 발표자 이미지가 우선한다. |
| 130 | + image_url = _get_speaker_image(api_client) |
| 131 | + assert image_url is not None and image_url.endswith(speaker.image.file.url) |
| 132 | + |
| 133 | + |
| 134 | +@pytest.mark.django_db |
| 135 | +def test_speaker_image_is_null_without_any_image( |
| 136 | + api_client: APIClient, create_presentation_set: PresentationTestEntity |
| 137 | +): |
| 138 | + # Given: 발표자 이미지도 프로필 이미지도 없는 발표자 |
| 139 | + assert create_presentation_set.presentation_speaker.image is None |
| 140 | + assert create_presentation_set.user.image is None |
| 141 | + |
| 142 | + assert _get_speaker_image(api_client) is None |
0 commit comments