# 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: openprovider/exceptions.py
# class BadRequest(OpenproviderError):
#     """A request didn't pass validation or was denied by Openprovider."""
# 
# class NoSuchElement(OpenproviderError):
#     """The element you tried to retrieve could not be found."""
# 
# Path: openprovider/models.py
# class DomainDetails(Model):
#     """
# 
#     A detailed domain.
#     """
# 
#     domain = submodel(Domain, "domain")
#     registry_details = submodel(RegistryDetails, "registryDetails")
# 
#     def __str__(self):
#         return str(self.domain)
# 
# class RegistryDetails(Model):
#     """
#     A container for a messages from the registry
# 
#     messages
#         A list of messages
#     """
# 
#     @property
#     def messages(self):
#         try:
#             return [RegistryMessage(item) for item in self.array[0].item]
#         except AttributeError:
#             return []
# 
# Path: tests/api_tests.py
# def betamaxed(original_function):
#     @wraps(original_function)
#     def new_function(api, *args, **kwargs):
#         with Betamax(api.session).use_cassette(original_function.__name__):
#             return original_function(api, *args, **kwargs)
# 
#     return new_function
# 
# def configure_betamax(api, **additional_apis):
#     with Betamax.configure() as config:
#         config.cassette_library_dir = 'tests/fixtures/cassettes'
#         config.default_cassette_options['match_options'] = ['method', 'uri', 'body']
# 
#         def _set_api(api, template):
#             for attr in ('username', 'password', 'password_hash'):
#                 value = getattr(api, attr, None)
#                 if value:
#                     config.define_cassette_placeholder(template % attr.upper(), value)
# 
#         # Configure primary API
#         config.define_cassette_placeholder('<URL>', api.url)
#         _set_api(api, '<%s>')
#         # placeholders aren't replaced in gzipped responses
#         api.session.headers['Accept-Encoding'] = ''
# 
#         # Any additional APIs
#         for name, api in additional_apis.items():
#             template = '<' + name.upper() + '_%s>' if name else '<%s>'
#             _set_api(api, template)
#             # placeholders aren't replaced in gzipped responses
#             api.session.headers['Accept-Encoding'] = ''


import calendar
import pytest
from betamax import Betamax
from datetime import datetime as dt
from openprovider.api import api_factory
from openprovider.exceptions import BadRequest, NoSuchElement
from openprovider.models import DomainDetails, RegistryDetails
from . import configure_betamax, betamaxed
    assert isinstance(response.registry_details.messages[0].date, dt)
    assert isinstance(response.registry_details.messages[0].message, str)


@betamaxed
def test_domain_check_active(api):
    """Obviously taken domains should return 'active'."""
    assert api.domains.check("example.com") == "active"


@betamaxed
def test_domain_check_free(api):
    """Obviously free domain should return 'free'."""
    assert api.domains.check("oy6uT6caew3deej.com") == "free"


@betamaxed
def test_domain_check_invalid_tld(api):
    """Domains with an invalid TLD should raise a BadRequest."""
    with pytest.raises(BadRequest):
        api.domains.check("a.com")


@betamaxed
def test_domain_check_invalid_sld(api):
    """Domains with an invalid SLD should raise a BadRequest."""
    with pytest.raises(BadRequest):
        api.domains.check("a.com")



# 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: openprovider/exceptions.py
# class BadRequest(OpenproviderError):
#     """A request didn't pass validation or was denied by Openprovider."""
# 
# class NoSuchElement(OpenproviderError):
#     """The element you tried to retrieve could not be found."""
# 
# Path: openprovider/models.py
# class DomainDetails(Model):
#     """
# 
#     A detailed domain.
#     """
# 
#     domain = submodel(Domain, "domain")
#     registry_details = submodel(RegistryDetails, "registryDetails")
# 
#     def __str__(self):
#         return str(self.domain)
# 
# class RegistryDetails(Model):
#     """
#     A container for a messages from the registry
# 
#     messages
#         A list of messages
#     """
# 
#     @property
#     def messages(self):
#         try:
#             return [RegistryMessage(item) for item in self.array[0].item]
#         except AttributeError:
#             return []
# 
# Path: tests/api_tests.py
# def betamaxed(original_function):
#     @wraps(original_function)
#     def new_function(api, *args, **kwargs):
#         with Betamax(api.session).use_cassette(original_function.__name__):
#             return original_function(api, *args, **kwargs)
# 
#     return new_function
# 
# def configure_betamax(api, **additional_apis):
#     with Betamax.configure() as config:
#         config.cassette_library_dir = 'tests/fixtures/cassettes'
#         config.default_cassette_options['match_options'] = ['method', 'uri', 'body']
# 
#         def _set_api(api, template):
#             for attr in ('username', 'password', 'password_hash'):
#                 value = getattr(api, attr, None)
#                 if value:
#                     config.define_cassette_placeholder(template % attr.upper(), value)
# 
#         # Configure primary API
#         config.define_cassette_placeholder('<URL>', api.url)
#         _set_api(api, '<%s>')
#         # placeholders aren't replaced in gzipped responses
#         api.session.headers['Accept-Encoding'] = ''
# 
#         # Any additional APIs
#         for name, api in additional_apis.items():
#             template = '<' + name.upper() + '_%s>' if name else '<%s>'
#             _set_api(api, template)
#             # placeholders aren't replaced in gzipped responses
#             api.session.headers['Accept-Encoding'] = ''


# Path: tests/test_domain.py
import calendar
import pytest
from betamax import Betamax
from datetime import datetime as dt
from openprovider.api import api_factory
from openprovider.exceptions import BadRequest, NoSuchElement
from openprovider.models import DomainDetails, RegistryDetails
from . import configure_betamax, betamaxed

    assert isinstance(response.registry_details.messages[0].date, dt)
    assert isinstance(response.registry_details.messages[0].message, str)


@betamaxed
def test_domain_check_active(api):
    """Obviously taken domains should return 'active'."""
    assert api.domains.check("example.com") == "active"


@betamaxed
def test_domain_check_free(api):
    """Obviously free domain should return 'free'."""
    assert api.domains.check("oy6uT6caew3deej.com") == "free"


@betamaxed
def test_domain_check_invalid_tld(api):
    """Domains with an invalid TLD should raise a BadRequest."""
    with pytest.raises(BadRequest):
        api.domains.check("a.com")


@betamaxed
def test_domain_check_invalid_sld(api):
    """Domains with an invalid SLD should raise a BadRequest."""
    with pytest.raises(BadRequest):
        api.domains.check("a.com")



@betamaxed