# Path: openprovider/api.py
# def api_factory(account=''):
#     username = _get_env('username', account)
#     try:
#         password_hash = _get_env('password_hash', account)
#         password = None
#     except KeyError:
#         password_hash = None
#         password = _get_env('password', account)
#     url = os.environ.get('OPENPROVIDER_URL', 'https://api.openprovider.eu')
# 
#     return OpenProvider(username=username, password=password, password_hash=password_hash, url=url)


import pytest
import os
from openprovider.api import api_factory



def test_api_factory_no_env():
    with pytest.raises(KeyError) as excinfo:
        api_factory('myaccount')
    assert str(excinfo.value) == "'Missing openprovider username for account myaccount'"


def test_api_factory_with_env():
    os.environ['OPENPROVIDER_APIFACTORY_TEST_USERNAME'] = 'myusername'
    os.environ['OPENPROVIDER_APIFACTORY_TEST_PASSWORD'] = 'mypassword'


# Path: openprovider/api.py
# def api_factory(account=''):
#     username = _get_env('username', account)
#     try:
#         password_hash = _get_env('password_hash', account)
#         password = None
#     except KeyError:
#         password_hash = None
#         password = _get_env('password', account)
#     url = os.environ.get('OPENPROVIDER_URL', 'https://api.openprovider.eu')
# 
#     return OpenProvider(username=username, password=password, password_hash=password_hash, url=url)


# Path: tests/test_api.py
import pytest
import os
from openprovider.api import api_factory




def test_api_factory_no_env():
    with pytest.raises(KeyError) as excinfo:
        api_factory('myaccount')
    assert str(excinfo.value) == "'Missing openprovider username for account myaccount'"


def test_api_factory_with_env():
    os.environ['OPENPROVIDER_APIFACTORY_TEST_USERNAME'] = 'myusername'
    os.environ['OPENPROVIDER_APIFACTORY_TEST_PASSWORD'] = 'mypassword'


    api = api_factory('apifactory_test')