fastapi-testing 0.2.1__tar.gz → 0.2.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: fastapi-testing
3
- Version: 0.2.1
3
+ Version: 0.2.2
4
4
  Summary: A lightweight, async-first testing framework for FastAPI applications
5
5
  License: MIT
6
6
  Keywords: fastapi,testing,async,pytest,integration-testing,test-framework
@@ -21,8 +21,6 @@ Classifier: Topic :: Software Development :: Testing
21
21
  Classifier: Typing :: Typed
22
22
  Requires-Dist: fastapi (>=0.115.0,<0.116.0)
23
23
  Requires-Dist: httpx[http2] (>=0.23.0,<0.28.0)
24
- Requires-Dist: pydantic (>=2.10.6,<3.0.0)
25
- Requires-Dist: pydantic-settings (>=2.7.1,<3.0.0)
26
24
  Requires-Dist: starlette (>=0.45.0,<0.46.0)
27
25
  Requires-Dist: uvicorn (>=0.34.0,<0.35.0)
28
26
  Requires-Dist: websockets (>=15.0,<16.0)
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "fastapi-testing"
3
- version = "0.2.1"
3
+ version = "0.2.2"
4
4
  description = "A lightweight, async-first testing framework for FastAPI applications"
5
5
  authors = ["Ove Ranheim <oranheim@gmail.com>"]
6
6
  readme = "README.md"
@@ -29,13 +29,12 @@ fastapi = "^0.115.0"
29
29
  httpx = { extras = ["http2"], version = ">=0.23.0,<0.28.0" }
30
30
  uvicorn = "^0.34.0"
31
31
  starlette = "^0.45.0"
32
- pydantic = "^2.10.6"
33
- pydantic-settings = "^2.7.1"
34
32
  websockets = "^15.0"
35
33
 
36
34
  [tool.poetry.group.dev.dependencies]
37
35
  pytest = "^8.3.0"
38
36
  pytest-asyncio = "^0.25.2"
37
+ pydantic = "^2.10.6"
39
38
  flake8 = "^7.1.0"
40
39
  restructuredtext-lint = "^1.4.0"
41
40
  pygments = "^2.19.1"
@@ -1,6 +1,7 @@
1
1
  import asyncio
2
2
  import json
3
3
  import logging
4
+ import os
4
5
  from contextlib import asynccontextmanager
5
6
  from dataclasses import dataclass
6
7
  from typing import List, Optional, Any, Set, AsyncGenerator, Dict, Union
@@ -9,7 +10,6 @@ import httpx
9
10
  import uvicorn
10
11
  from fastapi import FastAPI
11
12
  from fastapi.applications import AppType
12
- from pydantic_settings import BaseSettings, SettingsConfigDict
13
13
  from starlette.types import Lifespan
14
14
  from websockets.asyncio.client import ClientConnection, connect
15
15
  from websockets.protocol import State
@@ -25,34 +25,83 @@ DEFAULT_WS_RETRY_ATTEMPTS = 3
25
25
  DEFAULT_WS_RETRY_DELAY = 1.0
26
26
 
27
27
 
28
- class Config(BaseSettings):
28
+ class Config:
29
29
  """
30
30
  Global configuration settings for fastapi-testing framework.
31
-
32
- Environment variables:
33
- - FASTAPI_TESTING_WS_MAX_MESSAGE_SIZE: Maximum size for websocket messages.
34
- - FASTAPI_TESTING_WS_QUEUE_SIZE: Maximum websocket queue size.
35
- - FASTAPI_TESTING_HTTP_MAX_KEEPALIVE: Maximum HTTP keepalive connections.
36
- - FASTAPI_TESTING_HTTP_MAX_CONNECTIONS: Maximum HTTP connections.
37
- - FASTAPI_TESTING_WS_RETRY_ATTEMPTS: Number of websocket retry attempts.
38
- - FASTAPI_TESTING_WS_RETRY_DELAY: Delay (in seconds) between websocket retries.
39
- - FASTAPI_TESTING_PORT_RANGE_START: Start port for testing servers.
40
- - FASTAPI_TESTING_PORT_RANGE_END: End port for testing servers.
41
31
  """
42
- model_config = SettingsConfigDict(env_file=".env", env_prefix="FASTAPI_TESTING_")
43
- WS_MAX_MESSAGE_SIZE: int = DEFAULT_WS_MESSAGE_SIZE
44
- WS_MAX_QUEUE_SIZE: int = DEFAULT_WS_QUEUE_SIZE
45
- HTTP_MAX_KEEPALIVE: int = DEFAULT_KEEPALIVE_CONNS
46
- HTTP_MAX_CONNECTIONS: int = DEFAULT_MAX_CONNS
47
- WS_RETRY_ATTEMPTS: int = DEFAULT_WS_RETRY_ATTEMPTS
48
- WS_RETRY_DELAY: float = DEFAULT_WS_RETRY_DELAY
49
- PORT_RANGE_START: int = 8001
50
- PORT_RANGE_END: int = 9000
51
-
52
32
 
33
+ def __init__(
34
+ self,
35
+ ws_max_message_size: int = DEFAULT_WS_MESSAGE_SIZE,
36
+ ws_max_queue_size: int = DEFAULT_WS_QUEUE_SIZE,
37
+ http_max_keepalive: int = DEFAULT_KEEPALIVE_CONNS,
38
+ http_max_connections: int = DEFAULT_MAX_CONNS,
39
+ ws_retry_attempts: int = DEFAULT_WS_RETRY_ATTEMPTS,
40
+ ws_retry_delay: float = DEFAULT_WS_RETRY_DELAY,
41
+ port_range_start: int = 8001,
42
+ port_range_end: int = 9000,
43
+ ):
44
+ self.WS_MAX_MESSAGE_SIZE = ws_max_message_size
45
+ self.WS_MAX_QUEUE_SIZE = ws_max_queue_size
46
+ self.HTTP_MAX_KEEPALIVE = http_max_keepalive
47
+ self.HTTP_MAX_CONNECTIONS = http_max_connections
48
+ self.WS_RETRY_ATTEMPTS = ws_retry_attempts
49
+ self.WS_RETRY_DELAY = ws_retry_delay
50
+ self.PORT_RANGE_START = port_range_start
51
+ self.PORT_RANGE_END = port_range_end
52
+
53
+ @classmethod
54
+ def from_env(cls, prefix: str = "FASTAPI_TESTING_"):
55
+ """
56
+ Create configuration from environment variables.
57
+ This is an explicit opt-in method.
58
+ """
59
+ # Only look for variables with the specified prefix
60
+ env_vars = {k: v for k, v in os.environ.items() if k.startswith(prefix)}
61
+
62
+ # Convert to expected parameter names
63
+ config_params = {}
64
+ for env_key, env_value in env_vars.items():
65
+ config_key = env_key[len(prefix):].lower()
66
+ # Handle type conversion
67
+ if config_key in [
68
+ "ws_max_message_size",
69
+ "ws_max_queue_size",
70
+ "http_max_keepalive",
71
+ "http_max_connections",
72
+ "ws_retry_attempts",
73
+ "port_range_start",
74
+ "port_range_end"
75
+ ]:
76
+ try:
77
+ config_params[config_key] = int(env_value)
78
+ except ValueError:
79
+ pass # Silently ignore invalid values
80
+ elif config_key == "ws_retry_delay":
81
+ try:
82
+ config_params[config_key] = float(env_value)
83
+ except ValueError:
84
+ pass
85
+
86
+ return cls(**config_params)
87
+
88
+ @classmethod
89
+ def from_file(cls, file_path: str):
90
+ """Load configuration from a file."""
91
+ # Implementation for loading from a file (JSON, YAML, etc.)
92
+ pass
93
+
94
+
95
+ # Create the global configuration with defaults
53
96
  global_config = Config()
54
97
 
55
98
 
99
+ # Users can override it with their own configuration:
100
+ # global_config = Config.from_env()
101
+ # or
102
+ # global_config = Config(ws_max_message_size=2**21, http_max_connections=200)
103
+
104
+
56
105
  class InvalidResponseTypeError(Exception):
57
106
  """Exception raised when an operation is not supported for the response type."""
58
107
  pass
File without changes