# Path: groupmanagement/models.py
# class ExtendedGroup(models.Model):
#     group = models.OneToOneField(Group, on_delete=models.CASCADE, limit_choices_to=get_base_group_choices)
#     owner = models.ForeignKey(User, related_name='owned_groups', on_delete=models.CASCADE, limit_choices_to=get_group_manager_choices)
#     admins = models.ManyToManyField(User, related_name='admin_groups', blank=True, limit_choices_to=get_group_manager_choices)
#     parent = models.ForeignKey('self', null=True, on_delete=models.SET_NULL, related_name='child_groups', blank=True)
#     hidden = models.BooleanField(default=False, blank=True)
#     description = models.CharField(max_length=254, null=True, blank=True)
#     require_application = models.BooleanField(default=False, blank=True)
# 
#     @property
#     def name(self):
#         return self.group.name
# 
#     def __unicode__(self):
#         return self.name.encode('utf-8')
# 
#     def get_members(self):
#         return User.objects.filter(groups__name__in=[self.name])
# 
#     class Meta:
#         permissions = (("can_manage_groups", "Can own or administrate groups."),)
# 
#     objects = ExtendedGroupManager()
# 
#     def get_possible_admins(self):
#         admins = []
#         for u in self.group.user_set.exclude(pk=self.owner.pk):
#             if u.has_perm('groupmanagement.can_manage_groups'):
#                 admins.append(u)
#         return admins
# 
#     def get_possible_owners(self):
#         return self.admins.exclude(pk=self.owner.pk)
# 
#     def is_visible_to_user(self, user):
#         if user.is_superuser:
#             return True
#         elif user in self.group.user_set.all():
#             return True
#         elif not self.hidden:
#             if self.parent and self.parent in user.groups.all():
#                 return True
#         return False
# 
#     def can_promote_member(self, user, member):
#         if user == self.owner:
#             if member in self.get_possible_admins() and not user in self.admins.all() and not user == self.owner:
#                 return True
#         return False
# 
#     def can_demote_admin(self, user, admin):
#         if user == self.owner and admin in self.admins.all():
#             return True
#         elif user == admin and user in self.admins.all():
#             return True
#         return False
# 
#     def can_leave_group(self, user):
#         if user == self.owner:
#             return False
#         elif user in self.admins.all():
#             return False
#         return True
# 
#     def can_remove_member(self, user, member):
#         if member == self.owner:
#             return False
#         elif member in self.admins.all():
#             return False
#         elif user == self.owner or user in self.admins.all():
#             return True
# 
#     @property
#     def basic_members(self):
#         return [u for u in self.group.user_set.all() if u != self.owner and u not in self.admins.all()]
# 
# Path: authentication/models.py
# class User(AbstractBaseUser, PermissionsMixin):
#     main_character_id = models.PositiveIntegerField(primary_key=True)
#     email = models.EmailField(max_length=255, null=True, blank=True)
#     is_staff = models.BooleanField(default=False)
#     is_active = models.BooleanField(default=False)
# 
#     USERNAME_FIELD = 'main_character_id'
#     REQUIRED_FIELDS = []
# 
#     objects = UserManager()
# 
#     class Meta:
#         verbose_name = 'user'
#         verbose_name_plural = 'users'
# 
#     @property
#     def main_character(self):
#         if self.characters.filter(id=self.main_character_id).exists():
#             return self.characters.get(id=self.main_character_id)
#         elif EVECharacter.objects.filter(id=self.main_character_id).exists():
#             logger.warn("User with main character ID %s has detached main character model" % self.get_full_name())
#             return EVECharacter.objects.get(id=self.main_character_id)
#         else:
#             return None
# 
#     def get_full_name(self):
#         return str(self.main_character_id)
#     def get_short_name(self):
#         if self.main_character:
#             return str(self.main_character)
#         else:
#             return self.get_full_name()
# 
#     def __unicode__(self):
#         if self.main_character:
#             return str(self.main_character).encode('utf-8')
#         else:
#             logger.debug("Missing character model for user with main character id %s, returning id as __unicode__." % self.main_character_id)
#             return self.get_short_name().encode('utf-8')
# 
# Path: access/signals.py



from django.test import TestCase
from .models import ExtendedGroup
from django.contrib.auth.models import Group, Permission
from authentication.models import User
from access.signals import user_loses_access
from django.contrib.contenttypes.models import ContentType


class ExtendedGroupTestCase(TestCase):
    owner_id = 94677678
    admin_id = 234899860
    def setUp(self):
        self.owner = User.objects.create_user(main_character_id=self.owner_id)

# Path: groupmanagement/models.py
# class ExtendedGroup(models.Model):
#     group = models.OneToOneField(Group, on_delete=models.CASCADE, limit_choices_to=get_base_group_choices)
#     owner = models.ForeignKey(User, related_name='owned_groups', on_delete=models.CASCADE, limit_choices_to=get_group_manager_choices)
#     admins = models.ManyToManyField(User, related_name='admin_groups', blank=True, limit_choices_to=get_group_manager_choices)
#     parent = models.ForeignKey('self', null=True, on_delete=models.SET_NULL, related_name='child_groups', blank=True)
#     hidden = models.BooleanField(default=False, blank=True)
#     description = models.CharField(max_length=254, null=True, blank=True)
#     require_application = models.BooleanField(default=False, blank=True)
# 
#     @property
#     def name(self):
#         return self.group.name
# 
#     def __unicode__(self):
#         return self.name.encode('utf-8')
# 
#     def get_members(self):
#         return User.objects.filter(groups__name__in=[self.name])
# 
#     class Meta:
#         permissions = (("can_manage_groups", "Can own or administrate groups."),)
# 
#     objects = ExtendedGroupManager()
# 
#     def get_possible_admins(self):
#         admins = []
#         for u in self.group.user_set.exclude(pk=self.owner.pk):
#             if u.has_perm('groupmanagement.can_manage_groups'):
#                 admins.append(u)
#         return admins
# 
#     def get_possible_owners(self):
#         return self.admins.exclude(pk=self.owner.pk)
# 
#     def is_visible_to_user(self, user):
#         if user.is_superuser:
#             return True
#         elif user in self.group.user_set.all():
#             return True
#         elif not self.hidden:
#             if self.parent and self.parent in user.groups.all():
#                 return True
#         return False
# 
#     def can_promote_member(self, user, member):
#         if user == self.owner:
#             if member in self.get_possible_admins() and not user in self.admins.all() and not user == self.owner:
#                 return True
#         return False
# 
#     def can_demote_admin(self, user, admin):
#         if user == self.owner and admin in self.admins.all():
#             return True
#         elif user == admin and user in self.admins.all():
#             return True
#         return False
# 
#     def can_leave_group(self, user):
#         if user == self.owner:
#             return False
#         elif user in self.admins.all():
#             return False
#         return True
# 
#     def can_remove_member(self, user, member):
#         if member == self.owner:
#             return False
#         elif member in self.admins.all():
#             return False
#         elif user == self.owner or user in self.admins.all():
#             return True
# 
#     @property
#     def basic_members(self):
#         return [u for u in self.group.user_set.all() if u != self.owner and u not in self.admins.all()]
# 
# Path: authentication/models.py
# class User(AbstractBaseUser, PermissionsMixin):
#     main_character_id = models.PositiveIntegerField(primary_key=True)
#     email = models.EmailField(max_length=255, null=True, blank=True)
#     is_staff = models.BooleanField(default=False)
#     is_active = models.BooleanField(default=False)
# 
#     USERNAME_FIELD = 'main_character_id'
#     REQUIRED_FIELDS = []
# 
#     objects = UserManager()
# 
#     class Meta:
#         verbose_name = 'user'
#         verbose_name_plural = 'users'
# 
#     @property
#     def main_character(self):
#         if self.characters.filter(id=self.main_character_id).exists():
#             return self.characters.get(id=self.main_character_id)
#         elif EVECharacter.objects.filter(id=self.main_character_id).exists():
#             logger.warn("User with main character ID %s has detached main character model" % self.get_full_name())
#             return EVECharacter.objects.get(id=self.main_character_id)
#         else:
#             return None
# 
#     def get_full_name(self):
#         return str(self.main_character_id)
#     def get_short_name(self):
#         if self.main_character:
#             return str(self.main_character)
#         else:
#             return self.get_full_name()
# 
#     def __unicode__(self):
#         if self.main_character:
#             return str(self.main_character).encode('utf-8')
#         else:
#             logger.debug("Missing character model for user with main character id %s, returning id as __unicode__." % self.main_character_id)
#             return self.get_short_name().encode('utf-8')
# 
# Path: access/signals.py



# Path: groupmanagement/tests.py
from django.test import TestCase
from .models import ExtendedGroup
from django.contrib.auth.models import Group, Permission
from authentication.models import User
from access.signals import user_loses_access
from django.contrib.contenttypes.models import ContentType



class ExtendedGroupTestCase(TestCase):
    owner_id = 94677678
    admin_id = 234899860
    def setUp(self):
        self.owner = User.objects.create_user(main_character_id=self.owner_id)

        self.admin = User.objects.create_user(main_character_id=self.admin_id)