# Path: openprovider/models.py
# class Model(object):
#     """
#     Superclass for all models. Delegates attribute access to a wrapped class.
#     """
# 
#     def __init__(self, obj=None, **kwargs):
#         self._obj = obj
#         self._attrs = dict((snake_to_camel(key), value) for (key, value) in kwargs.items())
# 
#     def __dir__(self):
#         attrs = set(list(self.__dict__.keys()) + [camel_to_snake(key) for key in self._attrs.keys()])
#         if self._obj is not None:
#             attrs.update(camel_to_snake(t.tag) for t in self._obj.iterchildren())
#         return [attr for attr in attrs if not attr.startswith('_')]
# 
#     def __getattr__(self, attr):
#         """
#         Magic for returning an attribute. Will try the attributes of the
#         wrapper class first, then attributes in self._attrs, then the attributes
#         of the wrapped objectified element.
# 
#         Will try a camelCased version of the snake_cased input if the attribute
#         contains an underscore. This means foo.company_name will return the same
#         as foo.companyName.
#         """
# 
#         if "_" in attr:
#             attr = snake_to_camel(attr)
# 
#         if attr in self.__dict__:
#             # Check ourselves first to avoid infinite loops
#             return getattr(self, attr)
# 
#         try:
#             return self._attrs[attr]
#         except KeyError:
#             if self._obj is not None:
#                 try:
#                     return self._obj[attr]
#                 except (AttributeError, KeyError):
#                     pass
# 
#         raise AttributeError("Model has no attribute '%s' (tried %r)"
#                              % (camel_to_snake(attr), dir(self)))
# 
#     def get_elem(self):
#         """Returns the wrapped lxml element, if one exists, or else None."""
#         return self._obj
# 
#     def dump(self, *args, **kwargs):
#         """Dumps a representation of the Model on standard output."""
#         lxml.etree.dump(self._obj, *args, **kwargs)
# 
#     def __repr__(self):
#         args = ', '.join('%s=%r' % (attr, getattr(self, attr)) for attr in dir(self))
#         return "<%s.%s(%s)>" % (type(self).__module__, type(self).__name__, args)
# 
#     def __str__(self):
#         return str(lxml.etree.tostring(self._obj)) if self._obj is not None else 'Empty model'
# 
# class Name(Model):
#     """
#     A person's name.
# 
#     initials (required)
#         Initials (first letters of first names, first letter of last name)
#     firstName (required)
#         First name
#     prefix (optional)
#         Prefix (often occuring in Dutch names; for example van de)
#     lastName (required)
#         Last name
#     """
# 
#     def __eq__(self, other):
#         attributes = ['initials', 'first_name', 'prefix', 'last_name']
#         return all(getattr(self, attr, None) == getattr(other, attr, None) for attr in attributes)
# 
#     def __str__(self):
#         if getattr(self, "prefix", None):
#             return "%s %s %s" % (self.first_name, self.prefix, self.last_name)
#         else:
#             return "%s %s" % (self.first_name, self.last_name)
# 
# class Domain(Model):
#     """
#     A domain name.
# 
#     name (required)
#         The domain name without extension
#     extension (required)
#         The extension part of the domain name
#     """
# 
#     def __str__(self):
#         return "%s.%s" % (self.name, self.extension)
# 
# class Phone(Model):
#     """
#     An international phone number.
# 
#     country_code (required)
#     area_code (required)
#     subscriber_number (required)
#     """
# 
#     country_code = textattribute("countryCode")
#     area_code = textattribute("areaCode")
#     subscriber_number = textattribute("subscriberNumber")
# 
#     def __eq__(self, other):
#         attributes = ['country_code', 'area_code', 'subscriber_number']
#         return all(getattr(self, attr, None) == getattr(other, attr, None) for attr in attributes)
# 
#     def __str__(self):
#         """Return the string representation of phone number."""
#         return "%s %s %s" % (self.country_code, self.area_code, self.subscriber_number)
# 
# class Address(Model):
#     """
#     A physical street address.
# 
#     street (required)
#     number (required)
#     suffix (optional)
#     zipcode (required)
#     city (required)
#     state (optional)
#     country (required)
#     """
# 
#     def __eq__(self, other):
#         attributes = ['street', 'number', 'suffix', 'zipcode', 'city', 'state', 'country']
#         return all(getattr(self, attr, None) == getattr(other, attr, None) for attr in attributes)


import pytest
from openprovider.models import Model, Name, Domain, Phone, Address
# coding=utf-8

"""Contains tests both for the models system and for the models themselves."""




def test_model_construct_kwargs():
    """Tests construction of a Model by keyword arguments."""
    mod = Model(foo="foo", bar=Model(baz="baz"))
    assert mod.foo == "foo"
    assert mod.bar.baz == "baz"


def test_model_snake_case():
    """Tests Model's case-aliasing magic."""

# Path: openprovider/models.py
# class Model(object):
#     """
#     Superclass for all models. Delegates attribute access to a wrapped class.
#     """
# 
#     def __init__(self, obj=None, **kwargs):
#         self._obj = obj
#         self._attrs = dict((snake_to_camel(key), value) for (key, value) in kwargs.items())
# 
#     def __dir__(self):
#         attrs = set(list(self.__dict__.keys()) + [camel_to_snake(key) for key in self._attrs.keys()])
#         if self._obj is not None:
#             attrs.update(camel_to_snake(t.tag) for t in self._obj.iterchildren())
#         return [attr for attr in attrs if not attr.startswith('_')]
# 
#     def __getattr__(self, attr):
#         """
#         Magic for returning an attribute. Will try the attributes of the
#         wrapper class first, then attributes in self._attrs, then the attributes
#         of the wrapped objectified element.
# 
#         Will try a camelCased version of the snake_cased input if the attribute
#         contains an underscore. This means foo.company_name will return the same
#         as foo.companyName.
#         """
# 
#         if "_" in attr:
#             attr = snake_to_camel(attr)
# 
#         if attr in self.__dict__:
#             # Check ourselves first to avoid infinite loops
#             return getattr(self, attr)
# 
#         try:
#             return self._attrs[attr]
#         except KeyError:
#             if self._obj is not None:
#                 try:
#                     return self._obj[attr]
#                 except (AttributeError, KeyError):
#                     pass
# 
#         raise AttributeError("Model has no attribute '%s' (tried %r)"
#                              % (camel_to_snake(attr), dir(self)))
# 
#     def get_elem(self):
#         """Returns the wrapped lxml element, if one exists, or else None."""
#         return self._obj
# 
#     def dump(self, *args, **kwargs):
#         """Dumps a representation of the Model on standard output."""
#         lxml.etree.dump(self._obj, *args, **kwargs)
# 
#     def __repr__(self):
#         args = ', '.join('%s=%r' % (attr, getattr(self, attr)) for attr in dir(self))
#         return "<%s.%s(%s)>" % (type(self).__module__, type(self).__name__, args)
# 
#     def __str__(self):
#         return str(lxml.etree.tostring(self._obj)) if self._obj is not None else 'Empty model'
# 
# class Name(Model):
#     """
#     A person's name.
# 
#     initials (required)
#         Initials (first letters of first names, first letter of last name)
#     firstName (required)
#         First name
#     prefix (optional)
#         Prefix (often occuring in Dutch names; for example van de)
#     lastName (required)
#         Last name
#     """
# 
#     def __eq__(self, other):
#         attributes = ['initials', 'first_name', 'prefix', 'last_name']
#         return all(getattr(self, attr, None) == getattr(other, attr, None) for attr in attributes)
# 
#     def __str__(self):
#         if getattr(self, "prefix", None):
#             return "%s %s %s" % (self.first_name, self.prefix, self.last_name)
#         else:
#             return "%s %s" % (self.first_name, self.last_name)
# 
# class Domain(Model):
#     """
#     A domain name.
# 
#     name (required)
#         The domain name without extension
#     extension (required)
#         The extension part of the domain name
#     """
# 
#     def __str__(self):
#         return "%s.%s" % (self.name, self.extension)
# 
# class Phone(Model):
#     """
#     An international phone number.
# 
#     country_code (required)
#     area_code (required)
#     subscriber_number (required)
#     """
# 
#     country_code = textattribute("countryCode")
#     area_code = textattribute("areaCode")
#     subscriber_number = textattribute("subscriberNumber")
# 
#     def __eq__(self, other):
#         attributes = ['country_code', 'area_code', 'subscriber_number']
#         return all(getattr(self, attr, None) == getattr(other, attr, None) for attr in attributes)
# 
#     def __str__(self):
#         """Return the string representation of phone number."""
#         return "%s %s %s" % (self.country_code, self.area_code, self.subscriber_number)
# 
# class Address(Model):
#     """
#     A physical street address.
# 
#     street (required)
#     number (required)
#     suffix (optional)
#     zipcode (required)
#     city (required)
#     state (optional)
#     country (required)
#     """
# 
#     def __eq__(self, other):
#         attributes = ['street', 'number', 'suffix', 'zipcode', 'city', 'state', 'country']
#         return all(getattr(self, attr, None) == getattr(other, attr, None) for attr in attributes)


# Path: tests/test_models.py
import pytest
from openprovider.models import Model, Name, Domain, Phone, Address

# coding=utf-8

"""Contains tests both for the models system and for the models themselves."""




def test_model_construct_kwargs():
    """Tests construction of a Model by keyword arguments."""
    mod = Model(foo="foo", bar=Model(baz="baz"))
    assert mod.foo == "foo"
    assert mod.bar.baz == "baz"


def test_model_snake_case():
    """Tests Model's case-aliasing magic."""

    mod = Model(spam_and_eggs="Spam, spam, glorious spam")