(cls, data: Mapping[str, Any])
| 160 | |
| 161 | @classmethod |
| 162 | def from_dict(cls, data: Mapping[str, Any]) -> TortoiseConfig: |
| 163 | if not isinstance(data, Mapping): |
| 164 | raise ConfigurationError("TortoiseConfig must be created from a mapping") |
| 165 | |
| 166 | if "connections" not in data: |
| 167 | raise ConfigurationError('Config must define "connections" section') |
| 168 | if "apps" not in data: |
| 169 | raise ConfigurationError('Config must define "apps" section') |
| 170 | |
| 171 | raw_connections = data["connections"] |
| 172 | if not isinstance(raw_connections, Mapping): |
| 173 | raise ConfigurationError('Config "connections" must be a mapping') |
| 174 | connections: dict[str, ConnectionConfig | DBUrlConfig] = {} |
| 175 | for name, conn in raw_connections.items(): |
| 176 | if isinstance(conn, str): |
| 177 | connections[name] = DBUrlConfig(conn) |
| 178 | elif isinstance(conn, Mapping): |
| 179 | connections[name] = ConnectionConfig.from_dict(conn) |
| 180 | else: |
| 181 | raise ConfigurationError("Connection values must be mapping or string") |
| 182 | |
| 183 | raw_apps = data["apps"] |
| 184 | if not isinstance(raw_apps, Mapping): |
| 185 | raise ConfigurationError('Config "apps" must be a mapping') |
| 186 | apps: dict[str, AppConfig] = {} |
| 187 | for name, app in raw_apps.items(): |
| 188 | if not isinstance(app, Mapping): |
| 189 | raise ConfigurationError("App values must be mappings") |
| 190 | apps[name] = AppConfig.from_dict(app) |
| 191 | |
| 192 | routers = data.get("routers") |
| 193 | if routers is not None and not isinstance(routers, list): |
| 194 | if isinstance(routers, str): |
| 195 | raise ConfigurationError("TortoiseConfig.routers must be a list or None") |
| 196 | routers = list(routers) |
| 197 | |
| 198 | return cls( |
| 199 | connections=connections, |
| 200 | apps=apps, |
| 201 | routers=routers, |
| 202 | use_tz=data.get("use_tz"), |
| 203 | timezone=data.get("timezone"), |
| 204 | ) |
nothing calls this directly
no test coverage detected