| 
									
										
										
										
											2021-09-09 08:51:29 -08:00
										 |  |  | from fastapi.testclient import TestClient | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-18 19:04:36 -09:00
										 |  |  | from tests import data as test_data | 
					
						
							| 
									
										
										
										
											2022-10-18 14:49:41 -08:00
										 |  |  | from tests.utils import api_routes | 
					
						
							| 
									
										
										
										
											2021-12-18 19:04:36 -09:00
										 |  |  | from tests.utils.fixture_schemas import TestUser | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-07 09:39:47 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-18 19:04:36 -09:00
										 |  |  | def test_user_get_image(api_client: TestClient, unique_user: TestUser): | 
					
						
							|  |  |  |     # Get the user's image | 
					
						
							| 
									
										
										
										
											2022-10-18 14:49:41 -08:00
										 |  |  |     response = api_client.get(api_routes.media_users_user_id_file_name(str(unique_user.user_id), "profile.webp")) | 
					
						
							| 
									
										
										
										
											2021-09-09 08:51:29 -08:00
										 |  |  |     assert response.status_code == 200 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-18 19:04:36 -09:00
										 |  |  |     # Ensure that the returned value is a valid image | 
					
						
							|  |  |  |     assert response.headers["Content-Type"] == "image/webp" | 
					
						
							| 
									
										
										
										
											2021-09-09 08:51:29 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-18 19:04:36 -09:00
										 |  |  | def test_user_update_image(api_client: TestClient, unique_user: TestUser): | 
					
						
							|  |  |  |     image = {"profile": test_data.images_test_image_1.read_bytes()} | 
					
						
							| 
									
										
										
										
											2021-09-09 08:51:29 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-18 19:04:36 -09:00
										 |  |  |     # Update the user's image | 
					
						
							| 
									
										
										
										
											2022-10-18 14:49:41 -08:00
										 |  |  |     response = api_client.post( | 
					
						
							|  |  |  |         api_routes.users_id_image(str(unique_user.user_id)), files=image, headers=unique_user.token | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2021-12-18 19:04:36 -09:00
										 |  |  |     assert response.status_code == 200 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Request the image again | 
					
						
							| 
									
										
										
										
											2022-10-18 14:49:41 -08:00
										 |  |  |     response = api_client.get(api_routes.media_users_user_id_file_name(str(unique_user.user_id), "profile.webp")) | 
					
						
							| 
									
										
										
										
											2021-12-18 19:04:36 -09:00
										 |  |  |     assert response.status_code == 200 |