# Path: securedpi_locks/models.py
# class Lock(models.Model):
#     """Define class for user profile."""
#     user = models.ForeignKey(
#         settings.AUTH_USER_MODEL,
#         related_name='locks',
#         on_delete=models.CASCADE
#     )
#     name = models.CharField(max_length=20)
#     location = models.CharField(max_length=50)
#     description = models.CharField(max_length=50, blank=True)
#     date_created = models.DateField(auto_now_add=True)
#     date_modified = models.DateField(auto_now=True)
#     serial = models.CharField(max_length=50, unique=True)
#     status = models.CharField(max_length=20, default='unlocked')
#     is_active = models.BooleanField(default=False)
#     facial_recognition = models.BooleanField(default=False)
#     RFID = models.CharField(max_length=100, blank=True)
# 
#     def __str__(self):
#         return 'Lock for {}'.format(self.user)


from django.test import TestCase
from django.urls import reverse
from django.core import mail
from django.contrib.auth.models import User
from securedpi_locks.models import Lock

    def test_lock_buttons_present(self):
        """Make sure each lock has <Edit> and <Access Log> buttons present."""
        lock_pks = [self.lock1.pk, self.lock2.pk]
        for lock_pk in lock_pks:
            edit_link = 'href="{}"'.format(reverse('edit_lock', kwargs={'pk': lock_pk}))
            log_link = 'href="{}"'.format(reverse('events', kwargs={'pk': lock_pk}))
            self.assertContains(self.response, edit_link)
            self.assertContains(self.response, log_link)

    def test_lock_info_present(self):
        """Make sure all lock have their info displayed."""
        locks = [self.lock1, self.lock2]
        for lock in locks:
            info = [
                lock.name,
                lock.pk,
                lock.serial,
                lock.location,
                lock.facial_recognition
                ]
            for item in info:
                self.assertContains(self.response, item)

    def test_buttons_display_if_unlocked(self):
        """
        Make sure <Lock> button shows up and <Unlock> doesn't
        if the lock.status == 'unlocked'."""
        self.lock1.status = 'unlocked'
        self.lock1.is_active = True

# Path: securedpi_locks/models.py
# class Lock(models.Model):
#     """Define class for user profile."""
#     user = models.ForeignKey(
#         settings.AUTH_USER_MODEL,
#         related_name='locks',
#         on_delete=models.CASCADE
#     )
#     name = models.CharField(max_length=20)
#     location = models.CharField(max_length=50)
#     description = models.CharField(max_length=50, blank=True)
#     date_created = models.DateField(auto_now_add=True)
#     date_modified = models.DateField(auto_now=True)
#     serial = models.CharField(max_length=50, unique=True)
#     status = models.CharField(max_length=20, default='unlocked')
#     is_active = models.BooleanField(default=False)
#     facial_recognition = models.BooleanField(default=False)
#     RFID = models.CharField(max_length=100, blank=True)
# 
#     def __str__(self):
#         return 'Lock for {}'.format(self.user)


# Path: securedpi/test.py
from django.test import TestCase
from django.urls import reverse
from django.core import mail
from django.contrib.auth.models import User
from securedpi_locks.models import Lock


    def test_lock_buttons_present(self):
        """Make sure each lock has <Edit> and <Access Log> buttons present."""
        lock_pks = [self.lock1.pk, self.lock2.pk]
        for lock_pk in lock_pks:
            edit_link = 'href="{}"'.format(reverse('edit_lock', kwargs={'pk': lock_pk}))
            log_link = 'href="{}"'.format(reverse('events', kwargs={'pk': lock_pk}))
            self.assertContains(self.response, edit_link)
            self.assertContains(self.response, log_link)

    def test_lock_info_present(self):
        """Make sure all lock have their info displayed."""
        locks = [self.lock1, self.lock2]
        for lock in locks:
            info = [
                lock.name,
                lock.pk,
                lock.serial,
                lock.location,
                lock.facial_recognition
                ]
            for item in info:
                self.assertContains(self.response, item)

    def test_buttons_display_if_unlocked(self):
        """
        Make sure <Lock> button shows up and <Unlock> doesn't
        if the lock.status == 'unlocked'."""
        self.lock1.status = 'unlocked'
        self.lock1.is_active = True

        self.lock1.save()