# Path: findingaids/fa/models.py
# class Archive(models.Model):
#     '''Model to define Archives associated with EAD documents, for use with
#     admin user permissions and to identify subversion repositories where
#     content will be published from.'''
#     label = models.CharField(max_length=10,
#         help_text='Short label to identify an archive')
#     name = models.CharField(max_length=255,
#         help_text='repository name (subarea) in EAD to identify finding aids associated with this archive')
#     svn = models.URLField('Subversion Repository',
#         help_text='URL to subversion repository containing EAD for this archive')
#     slug = models.SlugField(help_text='''shorthand id
#         (auto-generated from label; do not modify after initial archive definition)''')
#     contacts = models.ManyToManyField(settings.AUTH_USER_MODEL,
#         help_text='Contact person for display on the Request Materials page (email required)',
#         blank=True)
# 
# 
#     def __unicode__(self):
#         return self.label
# 
#     @property
#     def svn_local_path(self):
#         return os.path.join(settings.SVN_WORKING_DIR, self.slug)
# 
#     def contact_names(self):
#         '''List of contact names method for display in django admin list
#         display.  Shows email if user has no full name.'''
#         return ', '.join([contact.get_full_name() or contact.email
#                           for contact in self.contacts.all()])
#     contact_names.short_description = "Contacts"
# 
# Path: findingaids/fa_admin/models.py
# class Archivist(models.Model):
#     user = models.OneToOneField(settings.AUTH_USER_MODEL,
#         on_delete=models.CASCADE)  # if user is deleted, delete archivist too
#     archives = models.ManyToManyField(Archive, blank=True)
#     order = models.CommaSeparatedIntegerField(max_length=255, blank=True,
#         null=True)
# 
#     def __repr__(self):
#         return '<Archivist %s: %s>' % (self.user.username,
#             ', '.join(arch.label for arch in self.archives.all()))
# 
#     def __unicode__(self):
#         return u'Archivist %s (%s)' % (unicode(self.user),
#             ', '.join(arch.label for arch in self.archives.all()))
# 
#     def sorted_archives(self):
#         '''List of archives this user is associated with, in order if
#         they have specified any order preference.'''
#         archives = self.archives.all()
#         # if no archives are explicitly defined and this is a superuser,
#         # give them access to all
#         if not archives and self.user.is_superuser:
#             archives = Archive.objects.all()
#         if self.order:
#             id_order = [int(id) for id in self.order.split(',')]
#             # if id is not present (e.g., new archive), sort to the end
#             return sorted(archives,
#                 key=lambda a: id_order.index(a.id) if a.id in id_order else 50)
# 
#         return archives


from django.test import TestCase
from django.contrib.auth import get_user_model
from findingaids.fa.models import Archive
from findingaids.fa_admin.models import Archivist
# file findingaids/fa_admin/tests/models.py
#
#   Copyright 2013 Emory University Library
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.




User = get_user_model()


class ArchivistTestCase(TestCase):
    fixtures = ['user']

    def test_sorted_archives(self):
        # create some test archives to associate with test user
        marbl = Archive(label='MARBL', name='Manuscipts', svn='https://svn.co/ead',
            slug='marbl')
        marbl.save()

# Path: findingaids/fa/models.py
# class Archive(models.Model):
#     '''Model to define Archives associated with EAD documents, for use with
#     admin user permissions and to identify subversion repositories where
#     content will be published from.'''
#     label = models.CharField(max_length=10,
#         help_text='Short label to identify an archive')
#     name = models.CharField(max_length=255,
#         help_text='repository name (subarea) in EAD to identify finding aids associated with this archive')
#     svn = models.URLField('Subversion Repository',
#         help_text='URL to subversion repository containing EAD for this archive')
#     slug = models.SlugField(help_text='''shorthand id
#         (auto-generated from label; do not modify after initial archive definition)''')
#     contacts = models.ManyToManyField(settings.AUTH_USER_MODEL,
#         help_text='Contact person for display on the Request Materials page (email required)',
#         blank=True)
# 
# 
#     def __unicode__(self):
#         return self.label
# 
#     @property
#     def svn_local_path(self):
#         return os.path.join(settings.SVN_WORKING_DIR, self.slug)
# 
#     def contact_names(self):
#         '''List of contact names method for display in django admin list
#         display.  Shows email if user has no full name.'''
#         return ', '.join([contact.get_full_name() or contact.email
#                           for contact in self.contacts.all()])
#     contact_names.short_description = "Contacts"
# 
# Path: findingaids/fa_admin/models.py
# class Archivist(models.Model):
#     user = models.OneToOneField(settings.AUTH_USER_MODEL,
#         on_delete=models.CASCADE)  # if user is deleted, delete archivist too
#     archives = models.ManyToManyField(Archive, blank=True)
#     order = models.CommaSeparatedIntegerField(max_length=255, blank=True,
#         null=True)
# 
#     def __repr__(self):
#         return '<Archivist %s: %s>' % (self.user.username,
#             ', '.join(arch.label for arch in self.archives.all()))
# 
#     def __unicode__(self):
#         return u'Archivist %s (%s)' % (unicode(self.user),
#             ', '.join(arch.label for arch in self.archives.all()))
# 
#     def sorted_archives(self):
#         '''List of archives this user is associated with, in order if
#         they have specified any order preference.'''
#         archives = self.archives.all()
#         # if no archives are explicitly defined and this is a superuser,
#         # give them access to all
#         if not archives and self.user.is_superuser:
#             archives = Archive.objects.all()
#         if self.order:
#             id_order = [int(id) for id in self.order.split(',')]
#             # if id is not present (e.g., new archive), sort to the end
#             return sorted(archives,
#                 key=lambda a: id_order.index(a.id) if a.id in id_order else 50)
# 
#         return archives


# Path: findingaids/fa_admin/tests/models.py
from django.test import TestCase
from django.contrib.auth import get_user_model
from findingaids.fa.models import Archive
from findingaids.fa_admin.models import Archivist

# file findingaids/fa_admin/tests/models.py
#
#   Copyright 2013 Emory University Library
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.




User = get_user_model()


class ArchivistTestCase(TestCase):
    fixtures = ['user']

    def test_sorted_archives(self):
        # create some test archives to associate with test user
        marbl = Archive(label='MARBL', name='Manuscipts', svn='https://svn.co/ead',
            slug='marbl')
        marbl.save()

        eua = Archive(label='EUA', name='Archives', svn='https://svn.co/ead',