# Path: partners/models.py
# class Partner(models.Model):
# 	
# 	name = models.CharField(max_length=100)
# 	description = models.TextField()
# 	address = models.TextField()
# 	fone = models.CharField(max_length=12)
# 
# 	def save_patners(self, partner_name, partner_description, partner_address, partner_fone):
# 		partner = Partner(name=partner_name, description = partner_description, address = partner_address, fone = partner_fone)
# 		partner.save()
# 		
# 	
# 	def __str__(self):
#                 return self.name
# 
# Path: equipments/models.py
# class Equipment(models.Model):
#     state = models.ForeignKey(EquipmentState,null=True)
#     equipment_name = models.CharField(max_length=30,default="blank")
#     date_danation = models.DateField(auto_now=True)
# 
#     def register_equipment(self, name_equipment):
#         available = AvailableEquipment()
#         available.save()
#         self.state = available
#         self.equipment_name = name_equipment
#         super(Equipment, self).save()
# 
#     def start_state(self):
#         available = AvailableEquipment()
#         available.save()
#         self.state = available
#         super(Equipment,self).save()
# 
#     def fix_equipment(self):
#         try:
#             previous_state = self.state.fix_equipment()
#             (self.state).delete()
#             self.state = previous_state
#         except TypeError:
#             pass
# 
#     def borrow_equipment(self, partner):
#         try:
#             # previous_state = self.state.borrow_equipment()
#             # self.state.delete()
#             previous_state = self.state.borrow_equipment(partner)
#             (self.state).delete()
# 
#             self.state = previous_state
#         except TypeError:
#             pass
# 
#     def take_back_equipment(self):
#         try:
#             previous_state = self.state.take_back_equipment()
#             (self.state).delete()
#             self.state = previous_state
#         except TypeError:
#             pass
# 
#     def disable_equipment(self):
#         try:
#             previous_state = self.state.disable_equipment()
#             (self.state).delete()
#             self.state = previous_state
#             pass
#         except TypeError:
#             pass
# 
#     def __str__(self):
#         return self.equipment_name
# 
# Path: equipments/models.py
# class AvailableEquipment(EquipmentState):
# 
#     def borrow_equipment(self,partner):
#         borrowed_equipment = BorrowedEquipment(partner=partner)
#         borrowed_equipment.save()
#         return borrowed_equipment
# 
#     def disable_equipment(self):
#         broken_equipment = BrokenEquipment()
#         broken_equipment.save()
#         return broken_equipment
# 
#     def __str__(self):
#         return "Available"
# 
# Path: equipments/models.py
# class BorrowedEquipment(EquipmentState):
#     borrow_date = models.DateField(auto_now=True)
#     partner = models.ForeignKey(Partner)
# 
#     def take_back_equipment(self):
#         available_equipment = AvailableEquipment()
#         available_equipment.save()
#         return available_equipment
# 
#     def disable_equipment(self):
#         broken_equipment = BrokenEquipment()
#         broken_equipment.save()
#         return broken_equipment
# 
#     def __str__(self):
#         return "Borrowed"
# 
# Path: equipments/models.py
# class BrokenEquipment(EquipmentState):
#     broken_date = models.DateField(auto_now=True)
#     price_repair = models.FloatField(blank=True,null=True)
# 
#     def fix_equipment(self):
#         available_equipment = AvailableEquipment()
#         available_equipment.save()
#         return available_equipment
# 
#     def __str__(self):
#         return "Broken"


import pytest
from partners.models import Partner
from equipments.models import Equipment
from equipments.models import AvailableEquipment
from equipments.models import BorrowedEquipment
from equipments.models import BrokenEquipment
    def test_register_equipment_post(self,client):
        response = client.post('equipment/registerequipment/',{
            'equipment_name':'test_equipment',
        },follow=True)
        response.status_code == 200

        
    def test_equipment(self,client):
        response = client.get('equipment/borrow_equipment/', follow=True)
        response.status_code == 200
    

    def test_list_equipment(self,client):
        response = client.get('equipment/list_equipment/', follow=True)
        response.status_code == 200
        
    def test_equipment_states(self):

        self.equipment.start_state()
        self.equipment.borrow_equipment(self.partner)
        assert(type(self.equipment.state) == type(BorrowedEquipment()))
        assert(self.equipment.state.partner == self.partner)

        self.equipment.take_back_equipment()
        assert(type(self.equipment.state) == type(AvailableEquipment()))

        self.equipment.disable_equipment()
        assert(type(self.equipment.state) == type(BrokenEquipment()))

        self.equipment.fix_equipment()

# Path: partners/models.py
# class Partner(models.Model):
# 	
# 	name = models.CharField(max_length=100)
# 	description = models.TextField()
# 	address = models.TextField()
# 	fone = models.CharField(max_length=12)
# 
# 	def save_patners(self, partner_name, partner_description, partner_address, partner_fone):
# 		partner = Partner(name=partner_name, description = partner_description, address = partner_address, fone = partner_fone)
# 		partner.save()
# 		
# 	
# 	def __str__(self):
#                 return self.name
# 
# Path: equipments/models.py
# class Equipment(models.Model):
#     state = models.ForeignKey(EquipmentState,null=True)
#     equipment_name = models.CharField(max_length=30,default="blank")
#     date_danation = models.DateField(auto_now=True)
# 
#     def register_equipment(self, name_equipment):
#         available = AvailableEquipment()
#         available.save()
#         self.state = available
#         self.equipment_name = name_equipment
#         super(Equipment, self).save()
# 
#     def start_state(self):
#         available = AvailableEquipment()
#         available.save()
#         self.state = available
#         super(Equipment,self).save()
# 
#     def fix_equipment(self):
#         try:
#             previous_state = self.state.fix_equipment()
#             (self.state).delete()
#             self.state = previous_state
#         except TypeError:
#             pass
# 
#     def borrow_equipment(self, partner):
#         try:
#             # previous_state = self.state.borrow_equipment()
#             # self.state.delete()
#             previous_state = self.state.borrow_equipment(partner)
#             (self.state).delete()
# 
#             self.state = previous_state
#         except TypeError:
#             pass
# 
#     def take_back_equipment(self):
#         try:
#             previous_state = self.state.take_back_equipment()
#             (self.state).delete()
#             self.state = previous_state
#         except TypeError:
#             pass
# 
#     def disable_equipment(self):
#         try:
#             previous_state = self.state.disable_equipment()
#             (self.state).delete()
#             self.state = previous_state
#             pass
#         except TypeError:
#             pass
# 
#     def __str__(self):
#         return self.equipment_name
# 
# Path: equipments/models.py
# class AvailableEquipment(EquipmentState):
# 
#     def borrow_equipment(self,partner):
#         borrowed_equipment = BorrowedEquipment(partner=partner)
#         borrowed_equipment.save()
#         return borrowed_equipment
# 
#     def disable_equipment(self):
#         broken_equipment = BrokenEquipment()
#         broken_equipment.save()
#         return broken_equipment
# 
#     def __str__(self):
#         return "Available"
# 
# Path: equipments/models.py
# class BorrowedEquipment(EquipmentState):
#     borrow_date = models.DateField(auto_now=True)
#     partner = models.ForeignKey(Partner)
# 
#     def take_back_equipment(self):
#         available_equipment = AvailableEquipment()
#         available_equipment.save()
#         return available_equipment
# 
#     def disable_equipment(self):
#         broken_equipment = BrokenEquipment()
#         broken_equipment.save()
#         return broken_equipment
# 
#     def __str__(self):
#         return "Borrowed"
# 
# Path: equipments/models.py
# class BrokenEquipment(EquipmentState):
#     broken_date = models.DateField(auto_now=True)
#     price_repair = models.FloatField(blank=True,null=True)
# 
#     def fix_equipment(self):
#         available_equipment = AvailableEquipment()
#         available_equipment.save()
#         return available_equipment
# 
#     def __str__(self):
#         return "Broken"


# Path: equipments/tests/test_equipment.py
import pytest
from partners.models import Partner
from equipments.models import Equipment
from equipments.models import AvailableEquipment
from equipments.models import BorrowedEquipment
from equipments.models import BrokenEquipment

    def test_register_equipment_post(self,client):
        response = client.post('equipment/registerequipment/',{
            'equipment_name':'test_equipment',
        },follow=True)
        response.status_code == 200

        
    def test_equipment(self,client):
        response = client.get('equipment/borrow_equipment/', follow=True)
        response.status_code == 200
    

    def test_list_equipment(self,client):
        response = client.get('equipment/list_equipment/', follow=True)
        response.status_code == 200
        
    def test_equipment_states(self):

        self.equipment.start_state()
        self.equipment.borrow_equipment(self.partner)
        assert(type(self.equipment.state) == type(BorrowedEquipment()))
        assert(self.equipment.state.partner == self.partner)

        self.equipment.take_back_equipment()
        assert(type(self.equipment.state) == type(AvailableEquipment()))

        self.equipment.disable_equipment()
        assert(type(self.equipment.state) == type(BrokenEquipment()))

        self.equipment.fix_equipment()

        assert(type(self.equipment.state) == type(AvailableEquipment()))