def test_form_update(self): userId = "cm:testId:" + str(uuid.uuid4()) user = User(id=userId).save() paymentInfo = { "currency": "USD", "items": [{ "name": "name", "description": "description", "amount": "amountField", "quantity": "1" }] } form = Form(schema={ "type": "object", "properties": { "amountField": { "type": "number" } } }, uiSchema={"title": "Test"}, formOptions=FormOptions(paymentInfo=paymentInfo), date_created=datetime.datetime.now(), date_modified=datetime.datetime.now(), name="Name", cff_permissions={userId: { "owner": True }}) form.save() formId = form.id table = display_form_dict({"a": "b"}) self.assertEqual(table, "<table><tr><th>A</th><td>b</td></tr></table>")
def test_form_create_copy(self): form1Id = ObjectId() Form(name="abc", version=1, center="None", id=form1Id, cff_permissions={ 'old': 'cff_permissions' }, schema={ "schema": "custom" }, uiSchema={ "uiSchema": "custom" }, formOptions=FormOptions(confirmationEmailInfo={"a": "B"}, paymentInfo={"c": "D"}, paymentMethods={"E": "F"}, dataOptions={"G": "H"}, defaultFormData={"I": "J"}), date_modified=datetime.datetime.now().isoformat(), date_created=datetime.datetime.now().isoformat()).save() app.current_request.json_body = {"formId": form1Id} response = form_create() form2 = Form.objects.get( {"_id": ObjectId(response['res']['form']['_id']['$oid'])}) form1 = Form.objects.get({"_id": form1Id}) self.assertEqual(form1.schema, form2.schema) self.assertEqual(form1.uiSchema, form2.uiSchema) self.assertEqual(form1.formOptions, form2.formOptions) self.assertEqual(form2.cff_permissions, {'userid': {"owner": True}}) self.assertNotEqual(form1.name, form2.name) self.assertTrue("Copy" in form2.name)
def form_create(): """Creates a new form with a blank schema and uiSchema. """ from ..main import app request_body = app.current_request.json_body or {} if request_body.get("formId", None): # todo: add permissions check -- some forms should not be able to be duplicated. formId = request_body.get("formId", None) old_form = Form.objects.get({"_id": ObjectId(formId)}) form = Form( name=old_form.name + " Copy - " + datetime.datetime.now().isoformat(), version=1, center="None", id=ObjectId(), cff_permissions={app.get_current_user_id(): { "owner": True }}, schema=old_form.schema, uiSchema=old_form.uiSchema, formOptions=old_form.formOptions, date_modified=datetime.datetime.now().isoformat(), date_created=datetime.datetime.now().isoformat()) form.save() return {'res': {'form': serialize_model(form)}} else: form_name = request_body.get( "form_name", "Untitled form {}".format(datetime.datetime.now().isoformat())) form = Form( name=form_name, version=1, center="None", id=ObjectId(), cff_permissions={app.get_current_user_id(): { "owner": True }}, schema={ "title": "Form", "type": "object", "properties": { "name": { "type": "string" } } }, uiSchema={"name": { "ui:placeholder": "Name" }}, formOptions=FormOptions(confirmationEmailInfo={}, paymentInfo={}, paymentMethods={}, dataOptions={}, defaultFormData={}), date_modified=datetime.datetime.now().isoformat(), date_created=datetime.datetime.now().isoformat()) form.save() return {'res': {'form': serialize_model(form)}}
def setUp(self): userId = app.get_current_user_id() form = Form(schema={ "type": "object", "properties": { "amountField": { "type": "number" } } }, uiSchema={"title": "Test"}, formOptions=FormOptions(paymentInfo={"a": "b"}), name="Name", cff_permissions={userId: { "owner": True }}) form.save() formId = form.id app.current_request = MagicMock() app.current_request.context = {'authorizer': {'id': userId}} self.formId = formId
def form_create(): """Creates a new form with a blank schema and uiSchema. """ from ..main import app request_body = app.current_request.json_body or {} # todo: multiple orgs? try: org = Org.objects.get({}) except DoesNotExist: raise UnauthorizedError( "Organization does not exist, so forms cannot be created.") app.check_permissions(org, ["Orgs_FormsCreate"]) if request_body.get("formId", None): # todo: add permissions check on forms -- some forms should not be able to be duplicated. formId = request_body.get("formId", None) old_form = Form.objects.get({"_id": ObjectId(formId)}) form = Form( name=old_form.name + " Copy - " + datetime.datetime.now().isoformat(), version=1, center="None", id=ObjectId(), cff_permissions={app.get_current_user_id(): { "owner": True }}, schema=old_form.schema, uiSchema=old_form.uiSchema, formOptions=old_form.formOptions, date_modified=datetime.datetime.now().isoformat(), date_created=datetime.datetime.now().isoformat(), ) form.save() return {"res": {"form": serialize_model(form)}} else: form_name = request_body.get( "form_name", "Untitled form {}".format(datetime.datetime.now().isoformat())) form = Form( name=form_name, version=1, center="None", id=ObjectId(), cff_permissions={app.get_current_user_id(): { "owner": True }}, schema={ "title": "Form", "type": "object", "properties": { "name": { "type": "string" } }, }, uiSchema={"name": { "ui:placeholder": "Name" }}, formOptions=FormOptions( confirmationEmailInfo={}, paymentInfo={}, paymentMethods={}, dataOptions={}, defaultFormData={}, ), date_modified=datetime.datetime.now().isoformat(), date_created=datetime.datetime.now().isoformat(), ) form.save() return {"res": {"form": serialize_model(form)}}