# 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_events/models.py
# class Event(models.Model):
#     """Define class for access events."""
# 
#     lock_id = models.CharField(max_length=20, blank=True)
#     action = models.CharField(max_length=30, default='unlock')
#     RFID = models.CharField(max_length=100, blank=True)
#     photo = models.ImageField(
#         upload_to='lock_photos',
#         blank=True,
#         null=True)
#     date_created = models.DateTimeField(auto_now_add=True)
#     serial = models.CharField(max_length=20)
#     status = models.CharField(max_length=20, default='failed')
#     mtype = models.CharField(max_length=20)
# 
#     def __str__(self):
#         """Show event."""
#         return 'Event for {}'.format(self.lock_id)


from django.test import TestCase
from django.contrib.auth.models import User
from securedpi_locks.models import Lock
from securedpi_events.models import Event
from django.urls import reverse
from unittest import mock
        """Prove redirect to dashboard after manual unlock."""
        urls = [self.url1, self.url2]
        for url in urls:
            response = self.client.get(url)
            self.assertRedirects(
                response,
                expected_url=reverse('dashboard'),
                status_code=302,
                target_status_code=200)

    @mock.patch('requests.post')
    def test_lock_status_becomes_pending_after_unlock(self, request_mock):
        """
        Prove that the status of a lock changes to 'pending' after
        clicking <Unlock> button.
        """
        self.lock.status = 'locked'
        self.lock.save()
        self.assertEqual(self.lock.status, 'locked')
        self.client.get(self.url1)
        self.assertEqual(Lock.objects.get(pk=self.lock.pk).status, 'pending')

    @mock.patch('requests.post')
    def test_lock_status_becomes_pending_after_lock(self, request_mock):
        """
        Prove that the status of a lock changes to 'pending' after
        clicking <Lock> button.
        """
        self.assertEqual(self.lock.status, 'unlocked')
        self.client.get(self.url2)

# 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_events/models.py
# class Event(models.Model):
#     """Define class for access events."""
# 
#     lock_id = models.CharField(max_length=20, blank=True)
#     action = models.CharField(max_length=30, default='unlock')
#     RFID = models.CharField(max_length=100, blank=True)
#     photo = models.ImageField(
#         upload_to='lock_photos',
#         blank=True,
#         null=True)
#     date_created = models.DateTimeField(auto_now_add=True)
#     serial = models.CharField(max_length=20)
#     status = models.CharField(max_length=20, default='failed')
#     mtype = models.CharField(max_length=20)
# 
#     def __str__(self):
#         """Show event."""
#         return 'Event for {}'.format(self.lock_id)


# Path: securedpi_locks/tests.py
from django.test import TestCase
from django.contrib.auth.models import User
from securedpi_locks.models import Lock
from securedpi_events.models import Event
from django.urls import reverse
from unittest import mock

        """Prove redirect to dashboard after manual unlock."""
        urls = [self.url1, self.url2]
        for url in urls:
            response = self.client.get(url)
            self.assertRedirects(
                response,
                expected_url=reverse('dashboard'),
                status_code=302,
                target_status_code=200)

    @mock.patch('requests.post')
    def test_lock_status_becomes_pending_after_unlock(self, request_mock):
        """
        Prove that the status of a lock changes to 'pending' after
        clicking <Unlock> button.
        """
        self.lock.status = 'locked'
        self.lock.save()
        self.assertEqual(self.lock.status, 'locked')
        self.client.get(self.url1)
        self.assertEqual(Lock.objects.get(pk=self.lock.pk).status, 'pending')

    @mock.patch('requests.post')
    def test_lock_status_becomes_pending_after_lock(self, request_mock):
        """
        Prove that the status of a lock changes to 'pending' after
        clicking <Lock> button.
        """
        self.assertEqual(self.lock.status, 'unlocked')
        self.client.get(self.url2)

        self.assertEqual(Lock.objects.get(pk=self.lock.pk).status, 'pending')