Accounts setup helper to deal with multiple configure-process and io & imap initialization phases. From tests, use the higher level public ACFactory methods instead of its private helper class.
| 264 | |
| 265 | |
| 266 | class ACSetup: |
| 267 | """ |
| 268 | Accounts setup helper to deal with multiple configure-process |
| 269 | and io & imap initialization phases. |
| 270 | |
| 271 | From tests, use the higher level |
| 272 | public ACFactory methods instead of its private helper class. |
| 273 | """ |
| 274 | |
| 275 | CONFIGURING = "CONFIGURING" |
| 276 | CONFIGURED = "CONFIGURED" |
| 277 | IDLEREADY = "IDLEREADY" |
| 278 | |
| 279 | _configured_events: Queue |
| 280 | |
| 281 | def __init__(self, testprocess, init_time) -> None: |
| 282 | self._configured_events = Queue() |
| 283 | self._account2state: Dict[Account, str] = {} |
| 284 | self._account2config: Dict[Account, Dict[str, str]] = {} |
| 285 | self._imap_cleaned: Set[str] = set() |
| 286 | self.testprocess = testprocess |
| 287 | self.init_time = init_time |
| 288 | |
| 289 | def log(self, *args): |
| 290 | print("[acsetup]", f"{time.time() - self.init_time:.3f}", *args) |
| 291 | |
| 292 | def add_configured(self, account): |
| 293 | """add an already configured account.""" |
| 294 | assert account.is_configured() |
| 295 | self._account2state[account] = self.CONFIGURED |
| 296 | self.log("added already configured account", account, account.get_config("addr")) |
| 297 | |
| 298 | def start_configure(self, account): |
| 299 | """add an account and start its configure process.""" |
| 300 | |
| 301 | class PendingTracker: |
| 302 | @account_hookimpl |
| 303 | def ac_configure_completed(this, success: bool, comment: Optional[str]) -> None: |
| 304 | self._configured_events.put((account, success, comment)) |
| 305 | |
| 306 | account.add_account_plugin(PendingTracker(), name="pending_tracker") |
| 307 | self._account2state[account] = self.CONFIGURING |
| 308 | account.configure() |
| 309 | self.log("started configure on", account) |
| 310 | |
| 311 | def wait_one_configured(self, account): |
| 312 | """wait until this account has successfully configured.""" |
| 313 | if self._account2state[account] == self.CONFIGURING: |
| 314 | while True: |
| 315 | acc = self._pop_config_success() |
| 316 | if acc == account: |
| 317 | break |
| 318 | self.init_imap(acc) |
| 319 | self.init_logging(acc) |
| 320 | acc._evtracker.consume_events() |
| 321 | |
| 322 | def bring_online(self): |
| 323 | """Wait for all accounts to become ready to receive messages. |
no outgoing calls