mirror of
				https://github.com/mealie-recipes/mealie.git
				synced 2025-10-31 02:03:35 -04:00 
			
		
		
		
	* add default assets for user profile * add recipe avatar * change user_id to UUID * add profile image upload * setup image cache keys * cleanup tests and add image tests * purge user data on delete * new user repository tests * add user_id validator for int -> UUID conversion * delete depreciated route * force set content type * refactor tests to use temp directory * validate parent exists before createing * set user_id to correct type * update instruction id * reset primary key on migration
		
			
				
	
	
		
			34 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			34 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| from fastapi.testclient import TestClient
 | |
| 
 | |
| from tests import data as test_data
 | |
| from tests.utils.fixture_schemas import TestUser
 | |
| 
 | |
| 
 | |
| class Routes:
 | |
|     def get_user_image(user_id: str, file_name: str = "profile.webp") -> str:
 | |
|         return f"/api/media/users/{user_id}/{file_name}"
 | |
| 
 | |
|     def user_image(user_id: str) -> str:
 | |
|         return f"/api/users/{user_id}/image"
 | |
| 
 | |
| 
 | |
| def test_user_get_image(api_client: TestClient, unique_user: TestUser):
 | |
|     # Get the user's image
 | |
|     response = api_client.get(Routes.get_user_image(str(unique_user.user_id)))
 | |
|     assert response.status_code == 200
 | |
| 
 | |
|     # Ensure that the returned value is a valid image
 | |
|     assert response.headers["Content-Type"] == "image/webp"
 | |
| 
 | |
| 
 | |
| def test_user_update_image(api_client: TestClient, unique_user: TestUser):
 | |
|     image = {"profile": test_data.images_test_image_1.read_bytes()}
 | |
| 
 | |
|     # Update the user's image
 | |
|     response = api_client.post(Routes.user_image(str(unique_user.user_id)), files=image, headers=unique_user.token)
 | |
|     assert response.status_code == 200
 | |
| 
 | |
|     # Request the image again
 | |
|     response = api_client.get(Routes.get_user_image(str(unique_user.user_id)))
 | |
|     assert response.status_code == 200
 |