mirror of
				https://github.com/ijaric/voice_assistant.git
				synced 2025-10-30 23:23:25 +00:00 
			
		
		
		
	fix: [#8] get_api to property
This commit is contained in:
		
							parent
							
								
									5cdefbc031
								
							
						
					
					
						commit
						d23d94da82
					
				|  | @ -16,3 +16,5 @@ class Settings(pydantic_settings.BaseSettings): | ||||||
|     project: app_split_settings.ProjectSettings = pydantic.Field( |     project: app_split_settings.ProjectSettings = pydantic.Field( | ||||||
|         default_factory=lambda: app_split_settings.ProjectSettings() |         default_factory=lambda: app_split_settings.ProjectSettings() | ||||||
|     ) |     ) | ||||||
|  | 
 | ||||||
|  | print(Settings()) | ||||||
|  |  | ||||||
|  | @ -12,7 +12,7 @@ import tests.functional.models as functional_models | ||||||
| 
 | 
 | ||||||
| @pytest_asyncio.fixture  # type: ignore[reportUntypedFunctionDecorator] | @pytest_asyncio.fixture  # type: ignore[reportUntypedFunctionDecorator] | ||||||
| async def http_client( | async def http_client( | ||||||
|     base_url: str = tests_core_settings.tests_settings.api.get_api_url(), |     base_url: str = tests_core_settings.tests_settings.api.get_api_url, | ||||||
| ) -> typing.AsyncGenerator[httpx.AsyncClient, typing.Any]: | ) -> typing.AsyncGenerator[httpx.AsyncClient, typing.Any]: | ||||||
|     session = httpx.AsyncClient(base_url=base_url) |     session = httpx.AsyncClient(base_url=base_url) | ||||||
|     yield session |     yield session | ||||||
|  | @ -56,7 +56,7 @@ def app() -> fastapi.FastAPI: | ||||||
| @pytest_asyncio.fixture  # type: ignore[reportUntypedFunctionDecorator] | @pytest_asyncio.fixture  # type: ignore[reportUntypedFunctionDecorator] | ||||||
| async def app_http_client( | async def app_http_client( | ||||||
|     app: fastapi.FastAPI, |     app: fastapi.FastAPI, | ||||||
|     base_url: str = tests_core_settings.tests_settings.api.get_api_url(), |     base_url: str = tests_core_settings.tests_settings.api.get_api_url, | ||||||
| ) -> typing.AsyncGenerator[httpx.AsyncClient, typing.Any]: | ) -> typing.AsyncGenerator[httpx.AsyncClient, typing.Any]: | ||||||
|     session = httpx.AsyncClient(app=app, base_url=base_url) |     session = httpx.AsyncClient(app=app, base_url=base_url) | ||||||
|     yield session |     yield session | ||||||
|  |  | ||||||
|  | @ -1,3 +1,4 @@ | ||||||
|  | import pydantic | ||||||
| import pydantic_settings | import pydantic_settings | ||||||
| 
 | 
 | ||||||
| import lib.app.split_settings.utils as app_split_settings_utils | import lib.app.split_settings.utils as app_split_settings_utils | ||||||
|  | @ -6,7 +7,7 @@ import lib.app.split_settings.utils as app_split_settings_utils | ||||||
| class ApiSettings(pydantic_settings.BaseSettings): | class ApiSettings(pydantic_settings.BaseSettings): | ||||||
|     model_config = pydantic_settings.SettingsConfigDict( |     model_config = pydantic_settings.SettingsConfigDict( | ||||||
|         env_file=app_split_settings_utils.ENV_PATH, |         env_file=app_split_settings_utils.ENV_PATH, | ||||||
|         env_prefix="API_", |         env_prefix="TEST_API_", | ||||||
|         env_file_encoding="utf-8", |         env_file_encoding="utf-8", | ||||||
|         extra="ignore", |         extra="ignore", | ||||||
|     ) |     ) | ||||||
|  | @ -15,5 +16,7 @@ class ApiSettings(pydantic_settings.BaseSettings): | ||||||
|     host: str = "0.0.0.0" |     host: str = "0.0.0.0" | ||||||
|     port: int = 8000 |     port: int = 8000 | ||||||
| 
 | 
 | ||||||
|     def get_api_url(self): |     @pydantic.computed_field | ||||||
|  |     @property | ||||||
|  |     def get_api_url(self) -> str: | ||||||
|         return f"{self.protocol}://{self.host}:{self.port}/api/v1" |         return f"{self.protocol}://{self.host}:{self.port}/api/v1" | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| import pathlib | import pathlib | ||||||
| 
 | 
 | ||||||
| BASE_PATH = pathlib.Path(__file__).parent.parent.parent.parent.resolve() | BASE_PATH = pathlib.Path(__file__).parent.parent.parent.parent.parent.resolve() | ||||||
| ENV_PATH = BASE_PATH / ".env" | ENV_PATH = BASE_PATH / ".env" | ||||||
|  |  | ||||||
|  | @ -26,7 +26,7 @@ class MakeResponseCallableType(typing.Protocol): | ||||||
|     async def __call__( |     async def __call__( | ||||||
|         self, |         self, | ||||||
|         api_method: str = "", |         api_method: str = "", | ||||||
|         url: str = functional_settings.tests_settings.api.get_api_url(), |         url: str = functional_settings.tests_settings.api.get_api_url, | ||||||
|         method: MethodsEnum = MethodsEnum.GET, |         method: MethodsEnum = MethodsEnum.GET, | ||||||
|         headers: dict[str, str] = functional_settings.tests_settings.project.headers, |         headers: dict[str, str] = functional_settings.tests_settings.project.headers, | ||||||
|         body: dict[str, typing.Any] | None = None, |         body: dict[str, typing.Any] | None = None, | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user