# -*- mode: python -*-
from contextlib import contextmanager

from capacity import TiB

from infinisdk import InfiniBox
from infinisim.infinibox import Infinibox as Simulator


@contextmanager
def doctest_context():
    simulator = Simulator(True)
    simulator.config.mgmt['users.password_policy_enabled'] = False
    simulator.activate()
    system = InfiniBox(simulator, auth=('infinidat', '123456'))
    system.login()
    for user in system.users.to_list():
        if user.id > 0:
            user.delete()
    for ldap_config in system.ldap_configs:
        ldap_config.delete()
    system.users.create(name='someuser', password='12345678')
    try:
        yield {
            "system": system,
            "TiB": TiB,
        }
    finally:
        simulator.deactivate()
