示例#1
0
文件: tests.py 项目: csvenja/coursys
 def test_FormGroups(self):
     groupName = "admins_test"
     u1 = Unit.objects.get(label="CMPT")
     u2 = Unit.objects.get(label="ENSC")
     # Test saving one form group
     fg = FormGroup(name=groupName, unit=u1)
     fg.save()
     self.assertEqual(fg.name, groupName)
     # now try adding another fromgroup in the same name with the same unit
     # should throw an db integrity exception
     fg2 = FormGroup(name=groupName, unit=u1)
     with self.assertRaises(IntegrityError):
         with django.db.transaction.atomic():
             fg2.save()
     # now add a formgroup with the same name into a different unit
     fg2 = FormGroup(name=groupName, unit=u2)
     fg2.save()
     self.assertEqual(fg2.name, groupName)
     self.assertEqual(fg2.unit, u2)
     # add some people to the fg
     p1 = Person.objects.get(userid="ggbaker")
     p2 = Person.objects.get(userid="dzhao")
     FormGroupMember(person=p1, formgroup=fg).save()
     FormGroupMember(person=p2, formgroup=fg).save()
     self.assertEqual(len(fg.members.all()), 2)
示例#2
0
def create_form_data():
    unit = Unit.objects.get(slug='cmpt')
    fg = FormGroup(name="Admins", unit=unit)
    fg.save()
    FormGroupMember(formgroup=fg, person=Person.objects.get(userid='ggbaker')).save()
    FormGroupMember(formgroup=fg, person=Person.objects.get(userid='classam')).save()

    f1 = Form(title="Simple Form", owner=fg, unit=fg.unit, description="Simple test form.", initiators='ANY')
    f1.save()
    s1 = Sheet(form=f1, title="Initial sheet")
    s1.save()
    fld1 = Field(label='Favorite Color', sheet=s1, fieldtype='SMTX', config={"min_length": 1, "required": True, "max_length": "100", 'label': 'Favorite Color', "help_text":''})
    fld1.save()
    fld2 = Field(label='Reason', sheet=s1, fieldtype='MDTX', config={"min_length": 10, "required": True, "max_length": "400", 'label': 'Reason', "help_text":'Why?'})
    fld2.save()
    fld3 = Field(label='Second Favorite Color', sheet=s1, fieldtype='SMTX', config={"min_length": 1, "required": False, "max_length": "100", 'label': 'Second Favorite Color', "help_text":''})
    fld3.save()

    f2 = Form(title="Appeal Form", owner=fg, unit=fg.unit, description="An all-purpose appeal form to appeal things with", initiators='LOG', advisor_visible=True)
    f2.save()
    s2 = Sheet(form=f2, title="Student Appeal")
    s2.save()
    fld4 = Field(label='Appeal', sheet=s2, fieldtype='SMTX', config={"min_length": 1, "required": True, "max_length": "100", 'label': 'Appeal', "help_text":'What do you want to appeal?'})
    fld4.save()
    fld4 = Field(label='Reasons', sheet=s2, fieldtype='LGTX', config={"min_length": 1, "required": True, "max_length": "1000", 'label': 'Reasons', "help_text":'Why do you think you deserve it?'})
    fld4.save()
    fld5 = Field(label='Prediction', sheet=s2, fieldtype='RADI', config={ "required": False, 'label': 'Prediction', "help_text":"Do you think it's likely this will be approved?", "choice_1": "Yes", "choice_2": "No", "choice_3": "Huh?"})
    fld5.save()
    s3 = Sheet(form=f2, title="Decision", can_view="ALL")
    s3.save()
    fld5 = Field(label='Decision', sheet=s3, fieldtype='RADI', config={ "required": True, 'label': 'Decision', "help_text":"Do you approve this appeal?", "choice_1": "Yes", "choice_2": "No", "choice_3": "See comments"})
    fld5.save()
    fld6 = Field(label='Comments', sheet=s3, fieldtype='MDTX', config={"min_length": 1, "required": False, "max_length": "1000", 'label': 'Comments', "help_text":'Any additional comments'})
    fld6.save()