def test_form_update(self): form = FormService.create_form_(self.admin, "A form", "Hello") form = FormService.update_form_(self.admin, form.pk, name="blub", active=True, js_code="var foo;", xml_code="<xml></xml>") self.assertEqual(form.xml_code, "<xml></xml>") with self.assertRaises(PermissionError): form = FormService.update_form_(self.user, form.pk, description="alo")
def test_update_form_groups(self): form = FormService.create_form_(self.admin, "A form", "Hello") form = FormService.update_form_(self.admin, form.pk, name="blub", active=True, js_code="var foo;", xml_code="<xml></xml>") self.assertEqual(form.xml_code, "<xml></xml>") grp = Group.objects.create(name="yolo") form = FormService.update_form_groups(self.admin, form.pk, [self.group.pk]) self.assertEqual(form.teams.first(), self.group) self.assertEqual(form.teams.count(), 1) form = FormService.update_form_groups(self.admin, form.pk, [grp.pk]) self.assertEqual(form.teams.first(), grp) self.assertEqual(form.teams.count(), 1) form = FormService.update_form_groups(self.admin, form.pk, [self.group.pk, grp.pk]) self.assertEqual(form.teams.count(), 2) with self.assertRaises(PermissionError): form = FormService.update_form_groups(self.user, form.pk, [grp.pk])
def mutate(self, info, form_id, name=NotPassed, description=NotPassed, xml_code=NotPassed, js_code=NotPassed, active=NotPassed): user = get_user_from_info(info) try: result = FormService.update_form_( user, int(from_global_id(form_id)[1]), name=name, description=description, xml_code=xml_code, js_code=js_code, active=active, ) except FormSchemaService.exceptions as e: raise MutationExecutionException(str(e)) return UpdateForm(success=True, form=result)