# 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
        """Setup for testing."""
        self.setup = super(ManualActionTestCase, self).setUp()
        self.url1 = reverse(
            'manual_unlock',
            kwargs={'pk': self.lock.pk, 'action': 'unlock'}
            )
        self.url2 = reverse(
            'manual_lock',
            kwargs={'pk': self.lock.pk, 'action': 'lock'}
            )

    @mock.patch('requests.post')
    def test_manual_unlock_creates_event(self, request_mock):
        """Prove that an event is created after clicking on <Unlock> button."""
        self.assertEqual(Event.objects.all().count(), 0)
        self.client.get(self.url1)
        self.assertEqual(Event.objects.all().count(), 1)

    @mock.patch('requests.post')
    def test_manual_lock_creates_event(self, request_mock):
        """Prove that an event is created after clicking on <Lock> button."""
        self.assertEqual(Event.objects.all().count(), 0)
        self.client.get(self.url2)
        self.assertEqual(Event.objects.all().count(), 1)

    @mock.patch('requests.post')
    def test_attrs_of_created_unlock_event(self, request_mock):
        """Prove that the created event has expected attributes."""
        self.client.get(self.url1)
        self.assertEqual(Event.objects.first().lock_id, str(self.lock.pk))

# 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

        """Setup for testing."""
        self.setup = super(ManualActionTestCase, self).setUp()
        self.url1 = reverse(
            'manual_unlock',
            kwargs={'pk': self.lock.pk, 'action': 'unlock'}
            )
        self.url2 = reverse(
            'manual_lock',
            kwargs={'pk': self.lock.pk, 'action': 'lock'}
            )

    @mock.patch('requests.post')
    def test_manual_unlock_creates_event(self, request_mock):
        """Prove that an event is created after clicking on <Unlock> button."""
        self.assertEqual(Event.objects.all().count(), 0)
        self.client.get(self.url1)
        self.assertEqual(Event.objects.all().count(), 1)

    @mock.patch('requests.post')
    def test_manual_lock_creates_event(self, request_mock):
        """Prove that an event is created after clicking on <Lock> button."""
        self.assertEqual(Event.objects.all().count(), 0)
        self.client.get(self.url2)
        self.assertEqual(Event.objects.all().count(), 1)

    @mock.patch('requests.post')
    def test_attrs_of_created_unlock_event(self, request_mock):
        """Prove that the created event has expected attributes."""
        self.client.get(self.url1)
        self.assertEqual(Event.objects.first().lock_id, str(self.lock.pk))

        self.assertEqual(Event.objects.first().action, 'unlock')