|
7 | 7 |
|
8 | 8 |
|
9 | 9 | import json |
| 10 | +import uuid |
10 | 11 | from http import HTTPStatus |
11 | 12 |
|
12 | 13 | import pytest |
@@ -185,3 +186,60 @@ async def test_patch_project( |
185 | 186 | assert data["ui"] == _patch_ui_2["ui"] |
186 | 187 | assert data["quality"] == _patch_quality["quality"] |
187 | 188 | assert data["dev"] == _patch_dev["dev"] |
| 189 | + |
| 190 | + |
| 191 | +@pytest.mark.parametrize( |
| 192 | + "user_role,expected", [(UserRole.USER, status.HTTP_204_NO_CONTENT)] |
| 193 | +) |
| 194 | +async def test_patch_project_with_client_session_header( |
| 195 | + client: TestClient, |
| 196 | + logged_user: UserInfoDict, |
| 197 | + user_project: ProjectDict, |
| 198 | + expected: HTTPStatus, |
| 199 | +): |
| 200 | + assert client.app |
| 201 | + base_url = client.app.router["patch_project"].url_for( |
| 202 | + project_id=user_project["uuid"] |
| 203 | + ) |
| 204 | + |
| 205 | + # Generate a valid UUID for client session ID |
| 206 | + client_session_id = str(uuid.uuid4()) |
| 207 | + |
| 208 | + # Test patch with X-Client-Session-Id header - should succeed |
| 209 | + resp = await client.patch( |
| 210 | + f"{base_url}", |
| 211 | + data=json.dumps( |
| 212 | + { |
| 213 | + "name": "testing-name-with-session", |
| 214 | + "description": "testing-description-with-session", |
| 215 | + } |
| 216 | + ), |
| 217 | + headers={"X-Client-Session-Id": client_session_id}, |
| 218 | + ) |
| 219 | + await assert_status(resp, expected) |
| 220 | + |
| 221 | + # Test patch without X-Client-Session-Id header - should also succeed (header is optional) |
| 222 | + resp = await client.patch( |
| 223 | + f"{base_url}", |
| 224 | + data=json.dumps( |
| 225 | + { |
| 226 | + "name": "testing-name-without-session", |
| 227 | + "description": "testing-description-without-session", |
| 228 | + } |
| 229 | + ), |
| 230 | + ) |
| 231 | + await assert_status(resp, expected) |
| 232 | + |
| 233 | + # Test patch with invalid X-Client-Session-Id header - should fail with validation error |
| 234 | + resp = await client.patch( |
| 235 | + f"{base_url}", |
| 236 | + data=json.dumps( |
| 237 | + { |
| 238 | + "name": "testing-name-invalid-session", |
| 239 | + "description": "testing-description-invalid-session", |
| 240 | + } |
| 241 | + ), |
| 242 | + headers={"X-Client-Session-Id": "invalid-uuid-format"}, |
| 243 | + ) |
| 244 | + # This should fail validation since it's not a proper UUID |
| 245 | + await assert_status(resp, status.HTTP_422_UNPROCESSABLE_ENTITY) |
0 commit comments