# Path: pytrainer/core/equipment.py
# class Equipment(DeclarativeBase):
#    """An equipment item that can be used during an activity, such as a pair of running shoes."""
# 
#    __tablename__ = 'equipment'
#    active = Column(Boolean)
#    description = Column(Unicode(length=100), unique=True, index=True)
#    id = Column(Integer, primary_key=True)
#    life_expectancy = Column(ForcedInteger)
#    notes = Column(UnicodeText)
#    prior_usage = Column(ForcedInteger)
# 
#    def __init__(self, **kwargs):
#        self.description = u""
#        self.active = True
#        self.life_expectancy = 0
#        self.prior_usage = 0
#        self.notes = u""
#        super(Equipment, self).__init__(**kwargs)
# 
#    def __eq__(self, o):
#        if isinstance(o, Equipment):
#            if self.id is not None and o.id is not None:
#                return self.id == o.id
#        return False
#        
#    def __hash__(self):
#        if self.id is not None:
#            return self.id
#        else:
#            return object.__hash__(self)
# 
# class EquipmentService(object):
#    
#    """Provides access to stored equipment items."""
#    
#    def __init__(self, ddbb):
#        self._ddbb = ddbb
#        
#    def get_all_equipment(self):
#        """Get all equipment items."""
#        return self._ddbb.session.query(Equipment).all()
#    
#    def get_active_equipment(self):
#        """Get all the active equipment items."""
#        return self._ddbb.session.query(Equipment).filter(Equipment.active == True).all()
#    
#    def get_equipment_item(self, item_id):
#        """Get an individual equipment item by id.
#        
#        If no item with the given id exists then None is returned.
#        """
#        try:
#            return self._ddbb.session.query(Equipment).filter(Equipment.id == item_id).one()
#        except exc.NoResultFound:
#            return None
#        
#    def store_equipment(self, equipment):
#        """Store a new or update an existing equipment item.
#        
#        The stored object is returned."""
#        logging.debug("Storing equipment item.")
#        try:
#           self._ddbb.session.add(equipment)
#           self._ddbb.session.commit()
#        except IntegrityError:
#           raise EquipmentServiceException("An equipment item already exists with description '{0}'".format(equipment.description))
#        return equipment
# 
#    def remove_equipment(self, equipment):
#        """Remove an existing equipment item."""
#        logging.debug("Deleting equipment item with id: '{0}'".format(equipment.id))
#        self._ddbb.session.delete(equipment)
#        self._ddbb.session.commit()
#    
#    def get_equipment_usage(self, equipment):
#        """Get the total use of the given equipment."""
#        result = self._ddbb.session.query(func.sum(Activity.distance).label('sum')).filter(Activity.equipment.contains(equipment))
#        usage = result.scalar()
#        return (0 if usage == None else float(usage)) + equipment.prior_usage
# 
# class EquipmentServiceException(Exception):
#    
#    def __init__(self, value):
#        self.value = value
#    
#    def __str__(self):
#        return repr(self.value)
# 
# Path: pytrainer/lib/ddbb.py
# class DDBB(Singleton):
# class ForcedInteger(TypeDecorator):
#     def __init__(self, url=None):
#     def get_connection_url(self):
#     def connect(self):
#     def disconnect(self):
#     def select(self,table,cells,condition=None, mod=None):
#     def create_tables(self, add_default=True):
#     def drop_tables(self):
#     def create_backup(self):
#     def process_bind_param(self, value, dialect):


import unittest
import sys
from pytrainer.core.equipment import Equipment, EquipmentService,\
    EquipmentServiceException
from pytrainer.lib.ddbb import DDBB, DeclarativeBase
from sqlalchemy.exc import StatementError, IntegrityError, ProgrammingError, OperationalError, DataError
        self.ddbb.session.add(equipment)
        self.ddbb.session.commit()
        self.assertEqual(u"42", equipment.notes)
            
    def test_equals_new_instances(self):
        equipment1 = Equipment()
        equipment2 = Equipment()
        self.assertNotEqual(equipment1, equipment2, "")
            
    def test_equals_instances_with_same_id(self):
        equipment1 = Equipment()
        equipment1.id = 1
        equipment2 = Equipment()
        equipment2.id = 1
        self.assertEqual(equipment1, equipment2, "Equipment instances with same id should be equal.")
            
    def test_equals_instances_with_different_ids(self):
        equipment1 = Equipment()
        equipment1.id = 1
        equipment2 = Equipment()
        equipment2.id = 2
        self.assertNotEqual(equipment1, equipment2, "Equipment instances with different ids should not be equal.")

class EquipmentServiceTest(unittest.TestCase):
    
    def setUp(self):
        self.mock_ddbb = DDBB()
        self.mock_ddbb.connect()
        self.mock_ddbb.create_tables()
        self.equipment_service = EquipmentService(self.mock_ddbb)

# Path: pytrainer/core/equipment.py
# class Equipment(DeclarativeBase):
#    """An equipment item that can be used during an activity, such as a pair of running shoes."""
# 
#    __tablename__ = 'equipment'
#    active = Column(Boolean)
#    description = Column(Unicode(length=100), unique=True, index=True)
#    id = Column(Integer, primary_key=True)
#    life_expectancy = Column(ForcedInteger)
#    notes = Column(UnicodeText)
#    prior_usage = Column(ForcedInteger)
# 
#    def __init__(self, **kwargs):
#        self.description = u""
#        self.active = True
#        self.life_expectancy = 0
#        self.prior_usage = 0
#        self.notes = u""
#        super(Equipment, self).__init__(**kwargs)
# 
#    def __eq__(self, o):
#        if isinstance(o, Equipment):
#            if self.id is not None and o.id is not None:
#                return self.id == o.id
#        return False
#        
#    def __hash__(self):
#        if self.id is not None:
#            return self.id
#        else:
#            return object.__hash__(self)
# 
# class EquipmentService(object):
#    
#    """Provides access to stored equipment items."""
#    
#    def __init__(self, ddbb):
#        self._ddbb = ddbb
#        
#    def get_all_equipment(self):
#        """Get all equipment items."""
#        return self._ddbb.session.query(Equipment).all()
#    
#    def get_active_equipment(self):
#        """Get all the active equipment items."""
#        return self._ddbb.session.query(Equipment).filter(Equipment.active == True).all()
#    
#    def get_equipment_item(self, item_id):
#        """Get an individual equipment item by id.
#        
#        If no item with the given id exists then None is returned.
#        """
#        try:
#            return self._ddbb.session.query(Equipment).filter(Equipment.id == item_id).one()
#        except exc.NoResultFound:
#            return None
#        
#    def store_equipment(self, equipment):
#        """Store a new or update an existing equipment item.
#        
#        The stored object is returned."""
#        logging.debug("Storing equipment item.")
#        try:
#           self._ddbb.session.add(equipment)
#           self._ddbb.session.commit()
#        except IntegrityError:
#           raise EquipmentServiceException("An equipment item already exists with description '{0}'".format(equipment.description))
#        return equipment
# 
#    def remove_equipment(self, equipment):
#        """Remove an existing equipment item."""
#        logging.debug("Deleting equipment item with id: '{0}'".format(equipment.id))
#        self._ddbb.session.delete(equipment)
#        self._ddbb.session.commit()
#    
#    def get_equipment_usage(self, equipment):
#        """Get the total use of the given equipment."""
#        result = self._ddbb.session.query(func.sum(Activity.distance).label('sum')).filter(Activity.equipment.contains(equipment))
#        usage = result.scalar()
#        return (0 if usage == None else float(usage)) + equipment.prior_usage
# 
# class EquipmentServiceException(Exception):
#    
#    def __init__(self, value):
#        self.value = value
#    
#    def __str__(self):
#        return repr(self.value)
# 
# Path: pytrainer/lib/ddbb.py
# class DDBB(Singleton):
# class ForcedInteger(TypeDecorator):
#     def __init__(self, url=None):
#     def get_connection_url(self):
#     def connect(self):
#     def disconnect(self):
#     def select(self,table,cells,condition=None, mod=None):
#     def create_tables(self, add_default=True):
#     def drop_tables(self):
#     def create_backup(self):
#     def process_bind_param(self, value, dialect):


# Path: pytrainer/test/core/test_equipment.py
import unittest
import sys
from pytrainer.core.equipment import Equipment, EquipmentService,\
    EquipmentServiceException
from pytrainer.lib.ddbb import DDBB, DeclarativeBase
from sqlalchemy.exc import StatementError, IntegrityError, ProgrammingError, OperationalError, DataError

        self.ddbb.session.add(equipment)
        self.ddbb.session.commit()
        self.assertEqual(u"42", equipment.notes)
            
    def test_equals_new_instances(self):
        equipment1 = Equipment()
        equipment2 = Equipment()
        self.assertNotEqual(equipment1, equipment2, "")
            
    def test_equals_instances_with_same_id(self):
        equipment1 = Equipment()
        equipment1.id = 1
        equipment2 = Equipment()
        equipment2.id = 1
        self.assertEqual(equipment1, equipment2, "Equipment instances with same id should be equal.")
            
    def test_equals_instances_with_different_ids(self):
        equipment1 = Equipment()
        equipment1.id = 1
        equipment2 = Equipment()
        equipment2.id = 2
        self.assertNotEqual(equipment1, equipment2, "Equipment instances with different ids should not be equal.")

class EquipmentServiceTest(unittest.TestCase):
    
    def setUp(self):
        self.mock_ddbb = DDBB()
        self.mock_ddbb.connect()
        self.mock_ddbb.create_tables()
        self.equipment_service = EquipmentService(self.mock_ddbb)

        self.equipment_table = DeclarativeBase.metadata.tables['equipment']