# Path: wiggum/applications/models.py
# class Application(models.Model):
#     """App representation"""
# 
#     name = models.CharField(_('Application name'),
#                             max_length=100,
#                             blank=False,
#                             null=False,
#                             unique=True)
#     token = models.CharField(_('Application token'),
#                              max_length=32,
#                              default=generate_api_key,
#                              blank=False,
#                              null=False,
#                              validators=[validators.RegexValidator(
#                                 r'^[a-fA-F0-9]{32}$',
#                                 _('Key should be hexadecimal and length 32')
#                                 ), ],
#                              unique=True)
#     description = models.TextField(_('Application description'),
#                                    blank=True,
#                                    null=False)
#     active = models.BooleanField(_('Application active'), default=True)
#     project_permissions = models.ManyToManyField(ProjectPermission,
#                                                  blank=True)
#     theme = models.CharField(_('App associated theme'),
#                              choices=THEMES,
#                              default=DEFAULT_THEME,
#                              max_length=50,)
# 
#     def __str__(self):
#         return "{0}({1})".format(self.name, self.token)
# 
# Path: wiggum/applications/utils.py
# def generate_api_key():
#     return uuid.uuid4().hex


from django.conf import settings
from django.test import TransactionTestCase
from django.db.utils import IntegrityError
from .models import Application
from users.models import ProjectPermission
from .utils import generate_api_key
            'token': generate_api_key(),
            'description': "Bruce Wayne awesome application",
            'active': True, }, {

            'name': "Spiderman application",
            'token': generate_api_key(),
            'description': "Peter parker awesome application",
            'active': False, },
        ]

    def test_creation(self):
        for i in self.data:
            a = Application(name=i['name'],
                            token=i['token'],
                            description=i['description'],
                            active=i['active'],)
            a.save()
            a2 = Application.objects.get(token=i['token'])

            for k, _ in i.items():
                self.assertEqual(getattr(a2, k), getattr(a, k))

    def test_unique_fields(self):
        for i in self.data:
            Application(name=i['name'], token=i['token']).save()

            with self.assertRaises(IntegrityError):
                Application(name=i['name'], token=generate_api_key()).save()

            with self.assertRaises(IntegrityError):

# Path: wiggum/applications/models.py
# class Application(models.Model):
#     """App representation"""
# 
#     name = models.CharField(_('Application name'),
#                             max_length=100,
#                             blank=False,
#                             null=False,
#                             unique=True)
#     token = models.CharField(_('Application token'),
#                              max_length=32,
#                              default=generate_api_key,
#                              blank=False,
#                              null=False,
#                              validators=[validators.RegexValidator(
#                                 r'^[a-fA-F0-9]{32}$',
#                                 _('Key should be hexadecimal and length 32')
#                                 ), ],
#                              unique=True)
#     description = models.TextField(_('Application description'),
#                                    blank=True,
#                                    null=False)
#     active = models.BooleanField(_('Application active'), default=True)
#     project_permissions = models.ManyToManyField(ProjectPermission,
#                                                  blank=True)
#     theme = models.CharField(_('App associated theme'),
#                              choices=THEMES,
#                              default=DEFAULT_THEME,
#                              max_length=50,)
# 
#     def __str__(self):
#         return "{0}({1})".format(self.name, self.token)
# 
# Path: wiggum/applications/utils.py
# def generate_api_key():
#     return uuid.uuid4().hex


# Path: wiggum/applications/test_models.py
from django.conf import settings
from django.test import TransactionTestCase
from django.db.utils import IntegrityError
from .models import Application
from users.models import ProjectPermission
from .utils import generate_api_key

            'token': generate_api_key(),
            'description': "Bruce Wayne awesome application",
            'active': True, }, {

            'name': "Spiderman application",
            'token': generate_api_key(),
            'description': "Peter parker awesome application",
            'active': False, },
        ]

    def test_creation(self):
        for i in self.data:
            a = Application(name=i['name'],
                            token=i['token'],
                            description=i['description'],
                            active=i['active'],)
            a.save()
            a2 = Application.objects.get(token=i['token'])

            for k, _ in i.items():
                self.assertEqual(getattr(a2, k), getattr(a, k))

    def test_unique_fields(self):
        for i in self.data:
            Application(name=i['name'], token=i['token']).save()

            with self.assertRaises(IntegrityError):
                Application(name=i['name'], token=generate_api_key()).save()

            with self.assertRaises(IntegrityError):

                Application(name="test", token=i['token']).save()