# Path: users/models.py
# class Employee(models.Model):
#     class Meta:
#         abstract = True
# 
#     phone_number = models.CharField(max_length = 12)
#     user = models.OneToOneField(User,on_delete=models.CASCADE)
# 
#     def register_donor(self, name, phone_number, address, address_reference, observations, email,donation_date):
#         user = self.generate_user(self, name, email, '')
#         donor = Donor (user=user,
#                     name=name,
#                     email = email,
#                     phone_number=phone_number,
#                     address = address,
#                     address_reference = address_reference,
#                     observations = observations,
#                     donation_date=donation_date)
#         donor.save()
# 
#     def confirm_scheduling(self):
#         pass
# 
#     def edit_donor(self):
#         pass
# 
#     def update_donation_date(self, newDonationDate, donor):
#         donor.donation_date = newDonationDate
#         donor.save()
# 
#     def __str__(self):
#         return self.user.username
# 
# Path: users/models.py
# class Administrator(Employee, Observer):
# 
#     is_superuser = True
# 
#     def register_employee(self,employee_type, name, phone_number, email, password):
#         if employee_type == 'secretary':
#             self.create_secretary(name, phone_number, email, password)
#         else:
#             self.create_administrator(name, phone_number, email, password)
# 
#     def remove_employee(self):
#         pass
# 
#     def release_login(self, id_Secretary):
#         try:
#             secretary = Secretary.objects.get(id=id_Secretary)
#         except ObjectDoesNotExist:
#             secretary = None    
# 
#         if secretary is not None:
#             if secretary.activate == False:
#                 secretary.activate = True
#                 secretary.release_activate_at = datetime.now()
#                 secretary.save()
#                 release = True
#             else:
#                 release = False
#         else:
#             release = False
#         
#         return release                    
# 
# 
#     def block_login(self, id_Secretary):
# 
#         try:
#             secretary = Secretary.objects.get(id=id_Secretary)
#         except ObjectDoesNotExist:
#             secretary = None    
# 
#         if secretary is not None:
#             if secretary.activate == True:
#                 secretary.activate = False
#                 secretary.release_activate_at = None
#                 secretary.save()
#                 release = True
#             else:
#                 release = False
#         else:
#             release = False
#         
#         return release
# 
#     def generate_superuser(self, name, phone_number, email, password):
#         user = User(first_name=name,username=email,email=email)
#         user.set_password(password)
#         user.is_superuser = True
#         user.save()
#         return user
# 
#     def generate_user(self, name, phone_number, email, password):
#         user = User(first_name=name,username=email,email=email)
#         user.set_password(password)
#         user.save()
#         return user
# 
#     def create_secretary(self, name, phone_number, email, password):
#         user = self.generate_user(self, name, email, password)
#         secretary = Secretary (user=user,
#                                phone_number=phone_number
#         )
#         secretary.save()
# 
#         return secretary
# 
#     def create_administrator(self, name, phone_number, email, password):
#         user = self.generate_superuser(self, name, email, password)
#         admin = Administrator (user=user,
#                               phone_number=phone_number
#         )
#         admin.save()
# 
#         return admin
# 
#     def update(self, input):
#         subject = "Login suspeito"
#         message = "O Secretario dolo do email: " + input + " realizou um login agora, este email eh informativo"
#         email_destination = self.user.email
#         email = Email()
#         email.send_email(subject, message, email_destination)
#         print(email_destination)
# 
# Path: users/models.py
# class Secretary (Employee, Observable):
#     is_superuser = False
#     activate =  models.BooleanField(default=False)
#     release_activate_at = models.DateTimeField(null=True, blank=True)
#     observers_in_secretary = []
# 
#     def listAllSecretaries(self):
#         secretaries = Secretary.objects.all()
#         return secretaries
# 
#     def add_observers(self):
#         self.observers_in_secretary = Administrator.objects.all()
#         
#     def remove_observers(self, input):
#         return
# 
#     def notify_observers(self, input):
#         for observer in self.observers_in_secretary:
#             observer.update(input)
# 
# 
#     def date_time_release(self):
#         date_now = datetime.now()
# 
#         if self.release_activate_at.date() == date_now.date():
#            if self.release_activate_at.hour - date_now.hour >= 6:
#                 self.add_observers()
#                 self.notify_observers(self.user.email) 
# 
#         else:
#             self.add_observers()
#             self.notify_observers(self.user.email)


import hashlib
import pytest
from django.contrib.auth.models import User
from django.core import mail
from factories import SecretaryFactory, AdministratorFactory
from users.models import Employee
from users.models import Administrator
from users.models import Secretary
from django.core.exceptions import ObjectDoesNotExist



@pytest.mark.django_db
class TestRegisterUsers:

    def setup(self):
        self.user1 = SecretaryFactory()
        self.user2 = AdministratorFactory()

    def test_index_get(self,client):
        response = client.get('/users/')
        assert response.status_code == 200

    def test_register_user_get(self,client):
        client.login(username=self.user2.user.username,password='test_password')
        response = client.get('/users/register/')

# Path: users/models.py
# class Employee(models.Model):
#     class Meta:
#         abstract = True
# 
#     phone_number = models.CharField(max_length = 12)
#     user = models.OneToOneField(User,on_delete=models.CASCADE)
# 
#     def register_donor(self, name, phone_number, address, address_reference, observations, email,donation_date):
#         user = self.generate_user(self, name, email, '')
#         donor = Donor (user=user,
#                     name=name,
#                     email = email,
#                     phone_number=phone_number,
#                     address = address,
#                     address_reference = address_reference,
#                     observations = observations,
#                     donation_date=donation_date)
#         donor.save()
# 
#     def confirm_scheduling(self):
#         pass
# 
#     def edit_donor(self):
#         pass
# 
#     def update_donation_date(self, newDonationDate, donor):
#         donor.donation_date = newDonationDate
#         donor.save()
# 
#     def __str__(self):
#         return self.user.username
# 
# Path: users/models.py
# class Administrator(Employee, Observer):
# 
#     is_superuser = True
# 
#     def register_employee(self,employee_type, name, phone_number, email, password):
#         if employee_type == 'secretary':
#             self.create_secretary(name, phone_number, email, password)
#         else:
#             self.create_administrator(name, phone_number, email, password)
# 
#     def remove_employee(self):
#         pass
# 
#     def release_login(self, id_Secretary):
#         try:
#             secretary = Secretary.objects.get(id=id_Secretary)
#         except ObjectDoesNotExist:
#             secretary = None    
# 
#         if secretary is not None:
#             if secretary.activate == False:
#                 secretary.activate = True
#                 secretary.release_activate_at = datetime.now()
#                 secretary.save()
#                 release = True
#             else:
#                 release = False
#         else:
#             release = False
#         
#         return release                    
# 
# 
#     def block_login(self, id_Secretary):
# 
#         try:
#             secretary = Secretary.objects.get(id=id_Secretary)
#         except ObjectDoesNotExist:
#             secretary = None    
# 
#         if secretary is not None:
#             if secretary.activate == True:
#                 secretary.activate = False
#                 secretary.release_activate_at = None
#                 secretary.save()
#                 release = True
#             else:
#                 release = False
#         else:
#             release = False
#         
#         return release
# 
#     def generate_superuser(self, name, phone_number, email, password):
#         user = User(first_name=name,username=email,email=email)
#         user.set_password(password)
#         user.is_superuser = True
#         user.save()
#         return user
# 
#     def generate_user(self, name, phone_number, email, password):
#         user = User(first_name=name,username=email,email=email)
#         user.set_password(password)
#         user.save()
#         return user
# 
#     def create_secretary(self, name, phone_number, email, password):
#         user = self.generate_user(self, name, email, password)
#         secretary = Secretary (user=user,
#                                phone_number=phone_number
#         )
#         secretary.save()
# 
#         return secretary
# 
#     def create_administrator(self, name, phone_number, email, password):
#         user = self.generate_superuser(self, name, email, password)
#         admin = Administrator (user=user,
#                               phone_number=phone_number
#         )
#         admin.save()
# 
#         return admin
# 
#     def update(self, input):
#         subject = "Login suspeito"
#         message = "O Secretario dolo do email: " + input + " realizou um login agora, este email eh informativo"
#         email_destination = self.user.email
#         email = Email()
#         email.send_email(subject, message, email_destination)
#         print(email_destination)
# 
# Path: users/models.py
# class Secretary (Employee, Observable):
#     is_superuser = False
#     activate =  models.BooleanField(default=False)
#     release_activate_at = models.DateTimeField(null=True, blank=True)
#     observers_in_secretary = []
# 
#     def listAllSecretaries(self):
#         secretaries = Secretary.objects.all()
#         return secretaries
# 
#     def add_observers(self):
#         self.observers_in_secretary = Administrator.objects.all()
#         
#     def remove_observers(self, input):
#         return
# 
#     def notify_observers(self, input):
#         for observer in self.observers_in_secretary:
#             observer.update(input)
# 
# 
#     def date_time_release(self):
#         date_now = datetime.now()
# 
#         if self.release_activate_at.date() == date_now.date():
#            if self.release_activate_at.hour - date_now.hour >= 6:
#                 self.add_observers()
#                 self.notify_observers(self.user.email) 
# 
#         else:
#             self.add_observers()
#             self.notify_observers(self.user.email)


# Path: users/tests/test_register_users.py
import hashlib
import pytest
from django.contrib.auth.models import User
from django.core import mail
from factories import SecretaryFactory, AdministratorFactory
from users.models import Employee
from users.models import Administrator
from users.models import Secretary
from django.core.exceptions import ObjectDoesNotExist




@pytest.mark.django_db
class TestRegisterUsers:

    def setup(self):
        self.user1 = SecretaryFactory()
        self.user2 = AdministratorFactory()

    def test_index_get(self,client):
        response = client.get('/users/')
        assert response.status_code == 200

    def test_register_user_get(self,client):
        client.login(username=self.user2.user.username,password='test_password')
        response = client.get('/users/register/')

        assert response.status_code == 200