# Path: applicationform/models.py
# class FullApplicationChecklistLink(models.Model):
#     '''
#         This model encapsulates the link between a checklist question
#         and one of more QuestionGroups that will be added to the
#         ethics application_form if that question is answered yes.    
#     '''
#     
#     checklist_question = models.ForeignKey(Question, related_name='checklist_question')
#     included_group = models.ForeignKey(QuestionGroup, related_name='included_group')
#     order = models.IntegerField()
#     objects = FullApplicationChecklistLinkManager()
# 
# class FullApplicationChecklistLinkManager(models.Manager):
#     
#     def get_ordered_groups_for_question(self, the_question):
#         '''
#             Returns all of the Groups that are linked to a particular 
#             checklist_question, in order.
#         '''
#         
#         return [link.included_group for link in super(FullApplicationChecklistLinkManager, self).
#                 get_query_set().filter(checklist_question=the_question).order_by('order')]


from django.test import TestCase
from applicationform.models import FullApplicationChecklistLink,\
    FullApplicationChecklistLinkManager
from questionnaire.models import QuestionGroup, Question
from django.db.utils import IntegrityError


class FullApplicationChecklistLinkTestCase(TestCase):

    
    def test_fields(self):
        '''
            This model should specify the following fields:
            checklist_question - ForeignKey(Question)
            included_group - ForeignKey (QuestionGroup)
            order - Integer
            
            all of which are required for creation
        '''
        
        test_question = Question.objects.create(label='test', field_type='charfield')
        test_question_group = QuestionGroup.objects.create(name='test')
        

# Path: applicationform/models.py
# class FullApplicationChecklistLink(models.Model):
#     '''
#         This model encapsulates the link between a checklist question
#         and one of more QuestionGroups that will be added to the
#         ethics application_form if that question is answered yes.    
#     '''
#     
#     checklist_question = models.ForeignKey(Question, related_name='checklist_question')
#     included_group = models.ForeignKey(QuestionGroup, related_name='included_group')
#     order = models.IntegerField()
#     objects = FullApplicationChecklistLinkManager()
# 
# class FullApplicationChecklistLinkManager(models.Manager):
#     
#     def get_ordered_groups_for_question(self, the_question):
#         '''
#             Returns all of the Groups that are linked to a particular 
#             checklist_question, in order.
#         '''
#         
#         return [link.included_group for link in super(FullApplicationChecklistLinkManager, self).
#                 get_query_set().filter(checklist_question=the_question).order_by('order')]


# Path: applicationform/tests/models.py
from django.test import TestCase
from applicationform.models import FullApplicationChecklistLink,\
    FullApplicationChecklistLinkManager
from questionnaire.models import QuestionGroup, Question
from django.db.utils import IntegrityError



class FullApplicationChecklistLinkTestCase(TestCase):

    
    def test_fields(self):
        '''
            This model should specify the following fields:
            checklist_question - ForeignKey(Question)
            included_group - ForeignKey (QuestionGroup)
            order - Integer
            
            all of which are required for creation
        '''
        
        test_question = Question.objects.create(label='test', field_type='charfield')
        test_question_group = QuestionGroup.objects.create(name='test')
        

        self.assertRaises(IntegrityError, FullApplicationChecklistLink.objects.create)