| 
									
										
										
										
											2024-02-07 10:53:55 -06:00
										 |  |  | import pytest | 
					
						
							| 
									
										
										
										
											2022-01-13 13:06:52 -09:00
										 |  |  | from fastapi.testclient import TestClient | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from mealie.core.config import get_app_settings | 
					
						
							|  |  |  | from mealie.core.settings.static import APP_VERSION | 
					
						
							| 
									
										
										
										
											2024-02-07 10:53:55 -06:00
										 |  |  | from mealie.repos.repository_factory import AllRepositories | 
					
						
							| 
									
										
										
										
											2022-10-18 14:49:41 -08:00
										 |  |  | from tests.utils import api_routes | 
					
						
							| 
									
										
										
										
											2022-01-13 13:06:52 -09:00
										 |  |  | from tests.utils.fixture_schemas import TestUser | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-07 10:53:55 -06:00
										 |  |  | @pytest.mark.parametrize("is_private_group", [True, False], ids=["private group", "public group"]) | 
					
						
							| 
									
										
										
										
											2024-08-22 10:14:32 -05:00
										 |  |  | def test_public_about_get_app_info( | 
					
						
							|  |  |  |     api_client: TestClient, is_private_group: bool, unfiltered_database: AllRepositories | 
					
						
							|  |  |  | ): | 
					
						
							| 
									
										
										
										
											2024-02-07 10:53:55 -06:00
										 |  |  |     settings = get_app_settings() | 
					
						
							| 
									
										
										
										
											2024-08-22 10:14:32 -05:00
										 |  |  |     group = unfiltered_database.groups.get_by_name(settings.DEFAULT_GROUP) | 
					
						
							| 
									
										
										
										
											2024-02-07 10:53:55 -06:00
										 |  |  |     assert group and group.preferences | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     group.preferences.private_group = is_private_group | 
					
						
							| 
									
										
										
										
											2024-08-22 10:14:32 -05:00
										 |  |  |     unfiltered_database.group_preferences.update(group.id, group.preferences) | 
					
						
							| 
									
										
										
										
											2024-02-07 10:53:55 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  |     response = api_client.get(api_routes.app_about) | 
					
						
							|  |  |  |     as_dict = response.json() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     assert as_dict["production"] == settings.PRODUCTION | 
					
						
							|  |  |  |     assert as_dict["version"] == APP_VERSION | 
					
						
							|  |  |  |     assert as_dict["demoStatus"] == settings.IS_DEMO | 
					
						
							|  |  |  |     assert as_dict["allowSignup"] == settings.ALLOW_SIGNUP | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if is_private_group: | 
					
						
							| 
									
										
										
										
											2024-08-12 17:09:30 +02:00
										 |  |  |         assert as_dict["defaultGroupSlug"] is None | 
					
						
							| 
									
										
										
										
											2024-02-07 10:53:55 -06:00
										 |  |  |     else: | 
					
						
							|  |  |  |         assert as_dict["defaultGroupSlug"] == group.slug | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-13 13:06:52 -09:00
										 |  |  | def test_admin_about_get_app_info(api_client: TestClient, admin_user: TestUser): | 
					
						
							| 
									
										
										
										
											2022-10-18 14:49:41 -08:00
										 |  |  |     response = api_client.get(api_routes.admin_about, headers=admin_user.token) | 
					
						
							| 
									
										
										
										
											2022-01-13 13:06:52 -09:00
										 |  |  | 
 | 
					
						
							|  |  |  |     as_dict = response.json() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     settings = get_app_settings() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     assert as_dict["version"] == APP_VERSION | 
					
						
							|  |  |  |     assert as_dict["demoStatus"] == settings.IS_DEMO | 
					
						
							|  |  |  |     assert as_dict["apiPort"] == settings.API_PORT | 
					
						
							|  |  |  |     assert as_dict["apiDocs"] == settings.API_DOCS | 
					
						
							|  |  |  |     assert as_dict["dbType"] == settings.DB_ENGINE | 
					
						
							|  |  |  |     # assert as_dict["dbUrl"] == settings.DB_URL_PUBLIC | 
					
						
							|  |  |  |     assert as_dict["defaultGroup"] == settings.DEFAULT_GROUP | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def test_admin_about_get_app_statistics(api_client: TestClient, admin_user: TestUser): | 
					
						
							| 
									
										
										
										
											2022-10-18 14:49:41 -08:00
										 |  |  |     response = api_client.get(api_routes.admin_about_statistics, headers=admin_user.token) | 
					
						
							| 
									
										
										
										
											2022-01-13 13:06:52 -09:00
										 |  |  | 
 | 
					
						
							|  |  |  |     as_dict = response.json() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-25 23:17:27 +00:00
										 |  |  |     # Smoke Test - Test the endpoint returns something that's a number | 
					
						
							| 
									
										
										
										
											2022-01-13 13:06:52 -09:00
										 |  |  |     assert as_dict["totalRecipes"] >= 0 | 
					
						
							|  |  |  |     assert as_dict["uncategorizedRecipes"] >= 0 | 
					
						
							|  |  |  |     assert as_dict["untaggedRecipes"] >= 0 | 
					
						
							|  |  |  |     assert as_dict["totalUsers"] >= 0 | 
					
						
							|  |  |  |     assert as_dict["totalGroups"] >= 0 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def test_admin_about_check_app_config(api_client: TestClient, admin_user: TestUser): | 
					
						
							| 
									
										
										
										
											2022-10-18 14:49:41 -08:00
										 |  |  |     response = api_client.get(api_routes.admin_about_check, headers=admin_user.token) | 
					
						
							| 
									
										
										
										
											2022-01-13 13:06:52 -09:00
										 |  |  | 
 | 
					
						
							|  |  |  |     as_dict = response.json() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-25 23:17:27 +00:00
										 |  |  |     # Smoke Test - Test the endpoint returns something that's a the expected shape | 
					
						
							| 
									
										
										
										
											2022-01-13 13:06:52 -09:00
										 |  |  |     assert as_dict["emailReady"] in [True, False] | 
					
						
							|  |  |  |     assert as_dict["ldapReady"] in [True, False] | 
					
						
							|  |  |  |     assert as_dict["baseUrlSet"] in [True, False] | 
					
						
							|  |  |  |     assert as_dict["isUpToDate"] in [True, False] |