()
| 110 | |
| 111 | |
| 112 | def redis_settings_validation(): |
| 113 | class Settings(BaseModel, arbitrary_types_allowed=True): |
| 114 | redis_settings: RedisSettings |
| 115 | |
| 116 | @field_validator('redis_settings', mode='before') |
| 117 | def parse_redis_settings(cls, v): |
| 118 | if isinstance(v, str): |
| 119 | return RedisSettings.from_dsn(v) |
| 120 | else: |
| 121 | return v |
| 122 | |
| 123 | s1 = Settings(redis_settings='redis://foobar:123/4') |
| 124 | assert s1.redis_settings.host == 'foobar' |
| 125 | assert s1.redis_settings.port == 123 |
| 126 | assert s1.redis_settings.database == 4 |
| 127 | assert s1.redis_settings.ssl is False |
| 128 | |
| 129 | s2 = Settings(redis_settings={'host': 'testing.com'}) |
| 130 | assert s2.redis_settings.host == 'testing.com' |
| 131 | assert s2.redis_settings.port == 6379 |
| 132 | |
| 133 | with pytest.raises(ValueError, match='1 validation error for Settings\nredis_settings.ssl'): |
| 134 | Settings(redis_settings={'ssl': 123}) |
| 135 | |
| 136 | s3 = Settings(redis_settings={'ssl': True}) |
| 137 | assert s3.redis_settings.host == 'localhost' |
| 138 | assert s3.redis_settings.ssl is True |
| 139 | |
| 140 | s4 = Settings(redis_settings='redis://user:pass@foobar') |
| 141 | assert s4.redis_settings.host == 'foobar' |
| 142 | assert s4.redis_settings.username == 'user' |
| 143 | assert s4.redis_settings.password == 'pass' |
| 144 | |
| 145 | s5 = Settings(redis_settings={'unix_socket_path': '/tmp/redis.sock'}) |
| 146 | assert s5.redis_settings.unix_socket_path == '/tmp/redis.sock' |
| 147 | assert s5.redis_settings.database == 0 |
| 148 | |
| 149 | s6 = Settings(redis_settings='unix:///tmp/redis.socket?db=6') |
| 150 | assert s6.redis_settings.unix_socket_path == '/tmp/redis.socket' |
| 151 | assert s6.redis_settings.database == 6 |
| 152 | |
| 153 | |
| 154 | def test_ms_to_datetime_tz(env: SetEnv): |
nothing calls this directly
no test coverage detected
searching dependent graphs…