# Path: depot/models.py
# class Depot(models.Model):
#     """
#     A depot has a name and many depot managers.
# 
#     :author: Leo Tappe
#     :author: Benedikt Seidl
#     """
# 
#     name = models.CharField(max_length=32)
#     description = models.CharField(max_length=256, blank=True)
#     organization = models.ForeignKey(Organization, on_delete=models.CASCADE)
#     manager_users = models.ManyToManyField(User, blank=True)
#     manager_groups = models.ManyToManyField(Group, blank=True)
#     active = models.BooleanField(default=True)
# 
#     def managed_by(self, user):
#         """
#         Depots are managed by superusers, the organization's managers,
#         any manager user and any user in a manager group.
#         """
# 
#         return (user.is_superuser
#                 or self.organization.managed_by(user)
#                 or self.manager_users.filter(id=user.id).exists()
#                 or self.manager_groups.filter(id__in=user.groups.all()).exists())
# 
#     def show_internal_items(self, user):
#         """
#         Internal items can be seen by superusers and organization members.
#         """
# 
#         return user.is_superuser or self.organization.is_member(user)
# 
#     def visible_items(self, user):
#         """
#         Return the list of items the user is allowed to see in this depot.
#         """
# 
#         if self.show_internal_items(user):
#             return self.active_items.all()
#         else:
#             return self.public_items.all()
# 
#     @property
#     def managers(self):
#         """
#         The list of users explicitly listed as managers of this depot.
#         Does not include any organization managers or superusers which are
#         not added to the depot.
#         """
# 
#         return User.objects.filter(
#             models.Q(id__in=self.manager_users.all())
#             | models.Q(groups__in=self.manager_groups.all())
#         ).distinct()
# 
#     @property
#     def public_items(self):
#         """
#         List all items with the visibility set to public.
#         """
# 
#         return self.item_set.filter(visibility=Item.VISIBILITY_PUBLIC)
# 
#     @property
#     def active_items(self):
#         return self.item_set.filter(
#             models.Q(visibility=Item.VISIBILITY_PUBLIC)
#             | models.Q(visibility=Item.VISIBILITY_INTERNAL)
#         )
# 
#     @staticmethod
#     def filter_by_user(user):
#         """
#         Filter for depots managed by the given user
#         """
# 
#         return (models.Q(organization__managers__id=user.id)
#                 | models.Q(manager_users__id=user.id)
#                 | models.Q(manager_groups__id__in=user.groups.all()))
# 
#     def __str__(self):
#         return self.name
# 
# class Organization(models.Model):
#     """
#     Representation of an organization,
#     such as FSMPI, FSMB or ASTA.
# 
#     An organization is defined by a list of user groups,
#     in our case LDAP groups. It is managed by a list of
#     users and has a list of depots.
# 
#     :author: Leo Tappe
#     :author: Benedikt Seidl
#     """
# 
#     name = models.CharField(max_length=32)
#     groups = models.ManyToManyField(Group, blank=True)
#     managers = models.ManyToManyField(User, blank=True)
# 
#     def managed_by(self, user):
#         """
#         Organizations are managed by superusers and organization managers.
#         """
# 
#         return user.is_superuser or self.managers.filter(id=user.id).exists()
# 
#     def is_member(self, user):
#         """
#         Checks if the user is in one of the groups defined in this organization.
#         """
# 
#         return self.groups.filter(id__in=user.groups.all()).exists()
# 
#     @property
#     def active_depots(self):
#         """
#         Returns all depots in this organization which have the active flag set.
#         """
# 
#         return self.depot_set.filter(active=True)
# 
#     @staticmethod
#     def filter_by_user(user):
#         """
#         Filter for organizations managed by the given user
#         """
# 
#         return models.Q(managers__id=user.id)
# 
#     def __str__(self):
#         return self.name
# 
# Path: verleihtool/test.py
# class ClientTestCase(TestCase):
#     """
#     Base test case with convenience methods to login and assert responses
# 
#     :author: Benedikt Seidl
#     """
# 
#     def setUp(self):
#         # Create normal user
#         self.user = User.objects.create_user(
#             username='user',
#             email='user@example.com',
#             password='password',
#             first_name='Ursula',
#             last_name='User'
#         )
# 
#         # Create superuser
#         self.superuser = User.objects.create_superuser(
#             username='admin',
#             email='admin@example.com',
#             password='pass',
#             first_name='Armin',
#             last_name='Admin'
#         )
# 
#         # Create a group
#         self.group = Group.objects.create()
#         self.user.groups.add(self.group)
# 
#     @property
#     def as_guest(self):
#         return Client()
# 
#     @property
#     def as_user(self):
#         c = Client()
#         c.login(username='user', password='password')
#         return c
# 
#     @property
#     def as_superuser(self):
#         c = Client()
#         c.login(username='admin', password='pass')
#         return c
# 
#     def assertSuccess(self, response, template):
#         self.assertEqual(response.status_code, 200)
#         self.assertTemplateUsed(response, template)


from depot.models import Depot, Organization
from verleihtool.test import ClientTestCase


class CheckoutFormTestCase(ClientTestCase):
    """
    Test the checkout form by asserting the auto-fill
    functionality for checkout-form

    :author: Stefan Su
    """

    def setUp(self):
        super().setUp()


# Path: depot/models.py
# class Depot(models.Model):
#     """
#     A depot has a name and many depot managers.
# 
#     :author: Leo Tappe
#     :author: Benedikt Seidl
#     """
# 
#     name = models.CharField(max_length=32)
#     description = models.CharField(max_length=256, blank=True)
#     organization = models.ForeignKey(Organization, on_delete=models.CASCADE)
#     manager_users = models.ManyToManyField(User, blank=True)
#     manager_groups = models.ManyToManyField(Group, blank=True)
#     active = models.BooleanField(default=True)
# 
#     def managed_by(self, user):
#         """
#         Depots are managed by superusers, the organization's managers,
#         any manager user and any user in a manager group.
#         """
# 
#         return (user.is_superuser
#                 or self.organization.managed_by(user)
#                 or self.manager_users.filter(id=user.id).exists()
#                 or self.manager_groups.filter(id__in=user.groups.all()).exists())
# 
#     def show_internal_items(self, user):
#         """
#         Internal items can be seen by superusers and organization members.
#         """
# 
#         return user.is_superuser or self.organization.is_member(user)
# 
#     def visible_items(self, user):
#         """
#         Return the list of items the user is allowed to see in this depot.
#         """
# 
#         if self.show_internal_items(user):
#             return self.active_items.all()
#         else:
#             return self.public_items.all()
# 
#     @property
#     def managers(self):
#         """
#         The list of users explicitly listed as managers of this depot.
#         Does not include any organization managers or superusers which are
#         not added to the depot.
#         """
# 
#         return User.objects.filter(
#             models.Q(id__in=self.manager_users.all())
#             | models.Q(groups__in=self.manager_groups.all())
#         ).distinct()
# 
#     @property
#     def public_items(self):
#         """
#         List all items with the visibility set to public.
#         """
# 
#         return self.item_set.filter(visibility=Item.VISIBILITY_PUBLIC)
# 
#     @property
#     def active_items(self):
#         return self.item_set.filter(
#             models.Q(visibility=Item.VISIBILITY_PUBLIC)
#             | models.Q(visibility=Item.VISIBILITY_INTERNAL)
#         )
# 
#     @staticmethod
#     def filter_by_user(user):
#         """
#         Filter for depots managed by the given user
#         """
# 
#         return (models.Q(organization__managers__id=user.id)
#                 | models.Q(manager_users__id=user.id)
#                 | models.Q(manager_groups__id__in=user.groups.all()))
# 
#     def __str__(self):
#         return self.name
# 
# class Organization(models.Model):
#     """
#     Representation of an organization,
#     such as FSMPI, FSMB or ASTA.
# 
#     An organization is defined by a list of user groups,
#     in our case LDAP groups. It is managed by a list of
#     users and has a list of depots.
# 
#     :author: Leo Tappe
#     :author: Benedikt Seidl
#     """
# 
#     name = models.CharField(max_length=32)
#     groups = models.ManyToManyField(Group, blank=True)
#     managers = models.ManyToManyField(User, blank=True)
# 
#     def managed_by(self, user):
#         """
#         Organizations are managed by superusers and organization managers.
#         """
# 
#         return user.is_superuser or self.managers.filter(id=user.id).exists()
# 
#     def is_member(self, user):
#         """
#         Checks if the user is in one of the groups defined in this organization.
#         """
# 
#         return self.groups.filter(id__in=user.groups.all()).exists()
# 
#     @property
#     def active_depots(self):
#         """
#         Returns all depots in this organization which have the active flag set.
#         """
# 
#         return self.depot_set.filter(active=True)
# 
#     @staticmethod
#     def filter_by_user(user):
#         """
#         Filter for organizations managed by the given user
#         """
# 
#         return models.Q(managers__id=user.id)
# 
#     def __str__(self):
#         return self.name
# 
# Path: verleihtool/test.py
# class ClientTestCase(TestCase):
#     """
#     Base test case with convenience methods to login and assert responses
# 
#     :author: Benedikt Seidl
#     """
# 
#     def setUp(self):
#         # Create normal user
#         self.user = User.objects.create_user(
#             username='user',
#             email='user@example.com',
#             password='password',
#             first_name='Ursula',
#             last_name='User'
#         )
# 
#         # Create superuser
#         self.superuser = User.objects.create_superuser(
#             username='admin',
#             email='admin@example.com',
#             password='pass',
#             first_name='Armin',
#             last_name='Admin'
#         )
# 
#         # Create a group
#         self.group = Group.objects.create()
#         self.user.groups.add(self.group)
# 
#     @property
#     def as_guest(self):
#         return Client()
# 
#     @property
#     def as_user(self):
#         c = Client()
#         c.login(username='user', password='password')
#         return c
# 
#     @property
#     def as_superuser(self):
#         c = Client()
#         c.login(username='admin', password='pass')
#         return c
# 
#     def assertSuccess(self, response, template):
#         self.assertEqual(response.status_code, 200)
#         self.assertTemplateUsed(response, template)


# Path: depot/tests/test_checkout_form.py
from depot.models import Depot, Organization
from verleihtool.test import ClientTestCase



class CheckoutFormTestCase(ClientTestCase):
    """
    Test the checkout form by asserting the auto-fill
    functionality for checkout-form

    :author: Stefan Su
    """

    def setUp(self):
        super().setUp()


        organization = Organization.objects.create()