# Path: fnapy/utils.py
# class Query(object):
#     """A simple class to create queries"""
# 
#     def __init__(self, name, tags={}, **kwargs):
#         self._dict = OrderedDict()
#         self.name = name
#         self.attrib = kwargs
# 
#         for k, v in kwargs.items():
#             if not k.startswith("@"):
#                 self._dict["@" + k] = v
# 
#         for k, v in tags.items():
#             self._dict[k] = v
# 
#     def _create_new_dict(self):
#         new_dict = OrderedDict()
#         for k, v in self._dict.items():
#             if k.startswith("@"):
#                 new_dict[k] = v
#         return new_dict
# 
#     def was(self, state):
#         """Perform a query on the states
# 
#         :state: the name of a state
# 
#         Example
#         >>> states = Query('state').was('Created')
# 
#         """
#         new_dict = self._create_new_dict()
#         new_dict["state"] = {"#text": state}
#         return Query(self.name, tags=new_dict)
# 
#     def between(self, min, max):
#         new_dict = self._create_new_dict()
#         new_dict["min"] = {"#text": min}
#         new_dict["max"] = {"#text": max}
#         return Query(self.name, tags=new_dict)
# 
#     def _operator(self, op, value):
#         op_to_mode = {
#             "eq": "Equals",
#             "ge": "GreaterThanOrEquals",
#             "gt": "GreaterThan",
#             "le": "LessThanOrEquals",
#             "lt": "LessThan",
#         }
#         new_dict = self._create_new_dict()
#         new_dict["@mode"] = op_to_mode[op]
#         new_dict["@value"] = value
#         return Query(self.name, tags=new_dict)
# 
#     def eq(self, value):
#         return self._operator("eq", value)
# 
#     def ge(self, value):
#         return self._operator("ge", value)
# 
#     def gt(self, value):
#         return self._operator("gt", value)
# 
#     def le(self, value):
#         return self._operator("le", value)
# 
#     def lt(self, value):
#         return self._operator("lt", value)
# 
#     @property
#     def dict(self):
#         """Return the OrderedDict"""
#         return self._dict
# 
#     @property
#     def xml(self):
#         """Return the XML"""
#         return dict2xml({self.name: self.dict})
# 
#     def __str__(self):
#         return "<{0}: {1}>".format(self.__class__.__name__, self.name)
# 
#     __repr__ = __str__


from datetime import datetime
from fnapy.utils import Query
import pytz
    _dict = date.dict
    assert len(_dict) == 0

def test_query_with_attributes():
    """Query(name, type=type) should generate a valid request"""
    date = Query('date', type='CreatedAt')
    _dict = date.dict
    assert len(_dict) == 1
    assert _dict.get('@type') == 'CreatedAt'

def test_query_between():
    """Query(name, type=type).between(min=dmin, max=dmax) should generate a valid request"""
    dmin = datetime(2016, 8, 23, 0, 0, 0).replace(tzinfo=pytz.utc).isoformat()
    dmax = datetime(2016, 9, 2, 0, 0, 0).replace(tzinfo=pytz.utc).isoformat()
    date = Query('date', type='CreatedAt')
    _dict = date.between(min=dmin, max=dmax).dict

    # Assert the number of keys is correct
    assert len(_dict) == 3

    # Assert the keys are correct
    assert _dict.get('@type') == 'CreatedAt'
    assert _dict.get('min', {}).get('#text') == dmin
    assert _dict.get('max', {}).get('#text') == dmax

    # Assert the order of the keys is preserverd
    assert list(_dict) == ['@type', 'min', 'max']

def test_query_was():
    """Query('state').was(state) should generate a valid request"""

# Path: fnapy/utils.py
# class Query(object):
#     """A simple class to create queries"""
# 
#     def __init__(self, name, tags={}, **kwargs):
#         self._dict = OrderedDict()
#         self.name = name
#         self.attrib = kwargs
# 
#         for k, v in kwargs.items():
#             if not k.startswith("@"):
#                 self._dict["@" + k] = v
# 
#         for k, v in tags.items():
#             self._dict[k] = v
# 
#     def _create_new_dict(self):
#         new_dict = OrderedDict()
#         for k, v in self._dict.items():
#             if k.startswith("@"):
#                 new_dict[k] = v
#         return new_dict
# 
#     def was(self, state):
#         """Perform a query on the states
# 
#         :state: the name of a state
# 
#         Example
#         >>> states = Query('state').was('Created')
# 
#         """
#         new_dict = self._create_new_dict()
#         new_dict["state"] = {"#text": state}
#         return Query(self.name, tags=new_dict)
# 
#     def between(self, min, max):
#         new_dict = self._create_new_dict()
#         new_dict["min"] = {"#text": min}
#         new_dict["max"] = {"#text": max}
#         return Query(self.name, tags=new_dict)
# 
#     def _operator(self, op, value):
#         op_to_mode = {
#             "eq": "Equals",
#             "ge": "GreaterThanOrEquals",
#             "gt": "GreaterThan",
#             "le": "LessThanOrEquals",
#             "lt": "LessThan",
#         }
#         new_dict = self._create_new_dict()
#         new_dict["@mode"] = op_to_mode[op]
#         new_dict["@value"] = value
#         return Query(self.name, tags=new_dict)
# 
#     def eq(self, value):
#         return self._operator("eq", value)
# 
#     def ge(self, value):
#         return self._operator("ge", value)
# 
#     def gt(self, value):
#         return self._operator("gt", value)
# 
#     def le(self, value):
#         return self._operator("le", value)
# 
#     def lt(self, value):
#         return self._operator("lt", value)
# 
#     @property
#     def dict(self):
#         """Return the OrderedDict"""
#         return self._dict
# 
#     @property
#     def xml(self):
#         """Return the XML"""
#         return dict2xml({self.name: self.dict})
# 
#     def __str__(self):
#         return "<{0}: {1}>".format(self.__class__.__name__, self.name)
# 
#     __repr__ = __str__


# Path: tests/test_query.py
from datetime import datetime
from fnapy.utils import Query
import pytz

    _dict = date.dict
    assert len(_dict) == 0

def test_query_with_attributes():
    """Query(name, type=type) should generate a valid request"""
    date = Query('date', type='CreatedAt')
    _dict = date.dict
    assert len(_dict) == 1
    assert _dict.get('@type') == 'CreatedAt'

def test_query_between():
    """Query(name, type=type).between(min=dmin, max=dmax) should generate a valid request"""
    dmin = datetime(2016, 8, 23, 0, 0, 0).replace(tzinfo=pytz.utc).isoformat()
    dmax = datetime(2016, 9, 2, 0, 0, 0).replace(tzinfo=pytz.utc).isoformat()
    date = Query('date', type='CreatedAt')
    _dict = date.between(min=dmin, max=dmax).dict

    # Assert the number of keys is correct
    assert len(_dict) == 3

    # Assert the keys are correct
    assert _dict.get('@type') == 'CreatedAt'
    assert _dict.get('min', {}).get('#text') == dmin
    assert _dict.get('max', {}).get('#text') == dmax

    # Assert the order of the keys is preserverd
    assert list(_dict) == ['@type', 'min', 'max']

def test_query_was():
    """Query('state').was(state) should generate a valid request"""

    states = Query('state').was('Created')