# 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/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.contrib.auth.models import User
from securedpi_events.models import Event
from securedpi_locks.models import Lock
from django.urls import reverse
import factory
        self.template = 'securedpi_events/events.html'
        events = EventFactory.build_batch(10, lock_id=self.lock.pk)
        for event in events:
            event.save()
        self.response = self.client.get(self.url)

    def test_auth_user_has_access_to_events(self):
        """Prove that response code is 200 for auth users."""
        self.assertEquals(self.response.status_code, 200)

    def test_right_template_is_used(self):
        """Prove that right template is used to render page."""
        self.assertTemplateUsed(self.response, self.template)

    def test_events_in_context(self):
        """Prove that 'events' are in response context."""
        self.assertIn('events', self.response.context)

    def test_correct_number_of_events_page(self):
        """Prove that correct number of events renders on the events page."""
        self.assertEqual(self.response.context['events'].count(), 10)

    def test_delete_btn_present(self):
        """Prove that <delete_10_oldest_events> button present."""
        url = reverse('delete_old_events', kwargs={'pk': self.lock.pk})
        expected = 'href="{}"'.format(url)
        self.assertContains(self.response, expected)

    def test_delete_btn_works(self):
        """Prove <delete_10_oldest_events> btn works as expected."""

# 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/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/tests.py
from django.test import TestCase
from django.contrib.auth.models import User
from securedpi_events.models import Event
from securedpi_locks.models import Lock
from django.urls import reverse
import factory

        self.template = 'securedpi_events/events.html'
        events = EventFactory.build_batch(10, lock_id=self.lock.pk)
        for event in events:
            event.save()
        self.response = self.client.get(self.url)

    def test_auth_user_has_access_to_events(self):
        """Prove that response code is 200 for auth users."""
        self.assertEquals(self.response.status_code, 200)

    def test_right_template_is_used(self):
        """Prove that right template is used to render page."""
        self.assertTemplateUsed(self.response, self.template)

    def test_events_in_context(self):
        """Prove that 'events' are in response context."""
        self.assertIn('events', self.response.context)

    def test_correct_number_of_events_page(self):
        """Prove that correct number of events renders on the events page."""
        self.assertEqual(self.response.context['events'].count(), 10)

    def test_delete_btn_present(self):
        """Prove that <delete_10_oldest_events> button present."""
        url = reverse('delete_old_events', kwargs={'pk': self.lock.pk})
        expected = 'href="{}"'.format(url)
        self.assertContains(self.response, expected)

    def test_delete_btn_works(self):
        """Prove <delete_10_oldest_events> btn works as expected."""

        count = Event.objects.filter(lock_id=self.lock.pk).count()