Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davisagli committed Sep 10, 2024
1 parent f243ac4 commit f159557
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 29 deletions.
6 changes: 3 additions & 3 deletions backend/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ clean: ## Clean environment

.PHONY: start
start: ## Start a Plone instance on localhost:8080
ALLOWED_DISTRIBUTIONS=portalbrasil-intranet PYTHONWARNINGS=ignore $(BIN_FOLDER)/runwsgi instance/etc/zope.ini
ENABLE_PRINTING_MAILHOST=True PYTHONWARNINGS=ignore $(BIN_FOLDER)/runwsgi instance/etc/zope.ini

.PHONY: console
console: instance/etc/zope.ini ## Start a console into a Plone instance
ALLOWED_DISTRIBUTIONS=portalbrasil-intranet PYTHONWARNINGS=ignore $(BIN_FOLDER)/zconsole debug instance/etc/zope.conf
PYTHONWARNINGS=ignore $(BIN_FOLDER)/zconsole debug instance/etc/zope.conf

.PHONY: create-site
create-site: instance/etc/zope.ini ## Create a new site from scratch
ALLOWED_DISTRIBUTIONS=portalbrasil-intranet PYTHONWARNINGS=ignore $(BIN_FOLDER)/zconsole run instance/etc/zope.conf ./scripts/create_site.py
PYTHONWARNINGS=ignore $(BIN_FOLDER)/zconsole run instance/etc/zope.conf ./scripts/create_site.py

# Example Content
.PHONY: update-example-content
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from collective.volto.formsupport import logger
from collective.volto.formsupport.interfaces import IFormDataStore
from collective.volto.formsupport.utils import get_blocks
from copy import deepcopy
from datetime import datetime
from plone.dexterity.interfaces import IDexterityContent
from plone.restapi.deserializer import json_body
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ def form_block(self):
if not blocks:
return {}
for id_, block in blocks.items():
if block.get("@type", "") in ("form", "schemaForm") and block.get("store", False):
is_form_block = block.get("@type", "") in ("form", "schemaForm")
if is_form_block and block.get("store", False):
if not self.block_id or self.block_id == id_:
return block
return {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,13 @@ def __init__(self, context, data):


class SubmitPost(Service):
def __init__(self, context, request):
super().__init__(context, request)

def reply(self):
self.block = {}
self.form_data = self.cleanup_data()
self.block_id = self.form_data.get("block_id", "")
if self.block_id:
self.block = self.get_block_data(block_id=self.block_id)

def reply(self):
self.validate_form()

store_action = self.block.get("store", False)
Expand Down Expand Up @@ -109,7 +106,7 @@ def cleanup_data(self):

block = self.get_block_data(block_id=form_data.get("block_id", ""))

if block["@type"] == "form":
if block.get("@type") == "form":
block_fields = [x.get("field_id", "") for x in block.get("subblocks", [])]
# cleanup form data if it's a form block
for form_field in form_data.get("data", []):
Expand Down Expand Up @@ -184,23 +181,18 @@ def validate_form(self):
(self.context, self.request),
ICaptchaSupport,
name=self.block["captcha"],
).verify(
self.form_data.get("captcha")
or self.form_data["data"].get("captchaWidget")
)
).verify(self.form_data.get("captcha"))

self.validate_email_fields()
self.validate_bcc()

def validate_schema(self):
if self.block["@type"] != "schemaForm":
if self.block.get("@type") != "schemaForm":
return
validator = jsonschema.Draft202012Validator(self.block["schema"])
errors = []
for err in validator.iter_errors(self.form_data["data"]):
error = {
"message": err.message
}
error = {"message": err.message}
if err.path:
error["field"] = ".".join(err.path)
errors.append(error)
Expand Down Expand Up @@ -356,7 +348,11 @@ def get_acknowledgement_field_value(self):
return data.get("value")

def get_subject(self):
subject = self.block.get("default_subject") or "${subject}"
subject = (
self.form_data.get("subject")
or self.block.get("default_subject")
or "${subject}"
)
subject = self.substitute_variables(subject)
return subject

Expand Down Expand Up @@ -496,11 +492,16 @@ def filter_parameters(self):
"""
# TODO: handle attachments for schemaForm block
if self.block["@type"] == "schemaForm":
return [{
"field_id": k,
"value": v,
"label": self.block["schema"]["properties"].get(k, {}).get("title", k),
} for k, v in self.form_data["data"].items()]
return [
{
"field_id": k,
"value": v,
"label": self.block["schema"]["properties"]
.get(k, {})
.get("title", k),
}
for k, v in self.form_data["data"].items()
]

skip_fields = [
x.get("field_id", "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def setUpPloneSite(self, portal):
applyProfile(portal, "plone.restapi:blocks")
applyProfile(portal, "collective.volto.formsupport:default")

# Mock the validate email tocken function
# Mock the validate email token function
def validate_email_token_mock(*args, **kwargs):
return True

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ const HoneypotCaptchaWidget = ({
}, []);

const [value, setValue] = useState();
console.log('oldWidget', value);

return (
<div className="honey-wrapper" key={'honeypot-captcha'}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React, { useState, useEffect, useReducer, useRef } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import React from 'react';
import { useDispatch } from 'react-redux';
import { defineMessages, useIntl } from 'react-intl';
import { Form } from '@plone/volto/components/manage/Form';
import { submitForm } from 'volto-form-block/actions';
import { Captcha } from 'volto-form-block/components/Widget';
import { tryParseJSON, extractInvariantErrors } from '@plone/volto/helpers';
import { toast } from 'react-toastify';
import { Toast } from '@plone/volto/components';
Expand Down

0 comments on commit f159557

Please sign in to comment.