# Path: server/models.py
# class Computer(models.Model):
#     # recovery_key = models.CharField(max_length=200, verbose_name="Recovery Key")
#     serial = models.CharField(max_length=200, verbose_name="Serial Number", unique=True)
#     username = models.CharField(max_length=200, verbose_name="User Name")
#     computername = models.CharField(max_length=200, verbose_name="Computer Name")
#     last_checkin = models.DateTimeField(blank=True, null=True)
# 
#     def __str__(self):
#         return self.computername
# 
#     class Meta:
#         ordering = ["serial"]
#         permissions = (
#             ("can_approve", (u"Can approve requests to see encryption keys")),
#         )
# 
# class Secret(models.Model):
#     computer = models.ForeignKey(Computer, on_delete=models.CASCADE)
#     secret = EncryptedCharField(max_length=256)
#     secret_type = models.CharField(
#         max_length=256, choices=SECRET_TYPES, default="recovery_key"
#     )
#     date_escrowed = models.DateTimeField(auto_now_add=True)
#     rotation_required = models.BooleanField(default=False)
# 
#     def validate_unique(self, *args, **kwargs):
#         if (
#             self.secret
#             in [
#                 str(s)
#                 for s in self.__class__.objects.filter(
#                     secret_type=self.secret_type, computer=self.computer
#                 )
#             ]
#             and not self.rotation_required
#         ):
#             raise ValidationError("already used")
#         super(Secret, self).validate_unique(*args, **kwargs)
# 
#     def save(self, *args, **kwargs):
#         self.validate_unique()
#         super(Secret, self).save(*args, **kwargs)
# 
#     def __str__(self):
#         return self.secret
# 
#     class Meta:
#         ordering = ["-date_escrowed"]


from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from django.contrib.auth.models import User
from selenium import webdriver
from server.models import Computer, Secret
from datetime import datetime


class FunctionalTest(StaticLiveServerTestCase):
    def setUp(self):
        self.browser = webdriver.Firefox()
        User.objects.create_superuser("admin", "a@a.com", "sekrit")
        User.objects._create_user(
            "tech", "t@a.com", "password", is_staff=True, is_superuser=False
        )
        tech_test_computer = Computer(serial="TECHSERIAL")
        tech_test_computer.username = "Daft Tech"
        tech_test_computer.computername = "compy587"
        tech_test_computer.save()
        secret = Secret(
            computer=tech_test_computer,

# Path: server/models.py
# class Computer(models.Model):
#     # recovery_key = models.CharField(max_length=200, verbose_name="Recovery Key")
#     serial = models.CharField(max_length=200, verbose_name="Serial Number", unique=True)
#     username = models.CharField(max_length=200, verbose_name="User Name")
#     computername = models.CharField(max_length=200, verbose_name="Computer Name")
#     last_checkin = models.DateTimeField(blank=True, null=True)
# 
#     def __str__(self):
#         return self.computername
# 
#     class Meta:
#         ordering = ["serial"]
#         permissions = (
#             ("can_approve", (u"Can approve requests to see encryption keys")),
#         )
# 
# class Secret(models.Model):
#     computer = models.ForeignKey(Computer, on_delete=models.CASCADE)
#     secret = EncryptedCharField(max_length=256)
#     secret_type = models.CharField(
#         max_length=256, choices=SECRET_TYPES, default="recovery_key"
#     )
#     date_escrowed = models.DateTimeField(auto_now_add=True)
#     rotation_required = models.BooleanField(default=False)
# 
#     def validate_unique(self, *args, **kwargs):
#         if (
#             self.secret
#             in [
#                 str(s)
#                 for s in self.__class__.objects.filter(
#                     secret_type=self.secret_type, computer=self.computer
#                 )
#             ]
#             and not self.rotation_required
#         ):
#             raise ValidationError("already used")
#         super(Secret, self).validate_unique(*args, **kwargs)
# 
#     def save(self, *args, **kwargs):
#         self.validate_unique()
#         super(Secret, self).save(*args, **kwargs)
# 
#     def __str__(self):
#         return self.secret
# 
#     class Meta:
#         ordering = ["-date_escrowed"]


# Path: functional_tests/base.py
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from django.contrib.auth.models import User
from selenium import webdriver
from server.models import Computer, Secret
from datetime import datetime



class FunctionalTest(StaticLiveServerTestCase):
    def setUp(self):
        self.browser = webdriver.Firefox()
        User.objects.create_superuser("admin", "a@a.com", "sekrit")
        User.objects._create_user(
            "tech", "t@a.com", "password", is_staff=True, is_superuser=False
        )
        tech_test_computer = Computer(serial="TECHSERIAL")
        tech_test_computer.username = "Daft Tech"
        tech_test_computer.computername = "compy587"
        tech_test_computer.save()
        secret = Secret(
            computer=tech_test_computer,

            secret="SHHH-DONT-TELL",