Skip to content

Commit

Permalink
[dev] test
Browse files Browse the repository at this point in the history
  • Loading branch information
eikichi18 committed Aug 9, 2024
1 parent 9e095e5 commit 41000e2
Showing 1 changed file with 105 additions and 0 deletions.
105 changes: 105 additions & 0 deletions src/design/plone/policy/tests/test_limit_submit_form.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
from collective.volto.formsupport.testing import ( # noqa: E501,
VOLTO_FORMSUPPORT_API_FUNCTIONAL_TESTING,
)
from datetime import datetime
from io import StringIO
from plone import api
from plone.app.testing import setRoles
from plone.app.testing import SITE_OWNER_NAME
from plone.app.testing import SITE_OWNER_PASSWORD
from plone.app.testing import TEST_USER_ID
from plone.restapi.testing import RelativeSession
from Products.MailHost.interfaces import IMailHost
from zope.component import getUtility

import csv
import transaction
import unittest


class TestLimitMailStore(unittest.TestCase):
layer = VOLTO_FORMSUPPORT_API_FUNCTIONAL_TESTING

def setUp(self):
self.app = self.layer["app"]
self.portal = self.layer["portal"]
self.portal_url = self.portal.absolute_url()
setRoles(self.portal, TEST_USER_ID, ["Manager"])

self.mailhost = getUtility(IMailHost)

self.api_session = RelativeSession(self.portal_url)
self.api_session.headers.update({"Accept": "application/json"})
self.api_session.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD)
self.anon_api_session = RelativeSession(self.portal_url)
self.anon_api_session.headers.update({"Accept": "application/json"})

self.document = api.content.create(
type="Document",
title="Example context",
container=self.portal,
)

self.document.blocks = {
"text-id": {"@type": "text"},
"form-id": {"@type": "form"},
}
self.document_url = self.document.absolute_url()
transaction.commit()

def tearDown(self):
self.api_session.close()
self.anon_api_session.close()

# set default block
self.document.blocks = {
"text-id": {"@type": "text"},
"form-id": {"@type": "form"},
}
transaction.commit()

def submit_form(self, data):
url = f"{self.document_url}/@submit-form"
response = self.api_session.post(
url,
json=data,
)
transaction.commit()
return response

def test_limit_submit(self):
self.document.blocks = {
"form-id": {
"@type": "form",
"store": True,
"limit": 1,
"subblocks": [
{
"label": "Message",
"field_id": "message",
"field_type": "text",
},
{
"label": "Name",
"field_id": "name",
"field_type": "text",
},
],
},
}
transaction.commit()

response = self.submit_form(
data={
"from": "[email protected]",
"data": [
{"field_id": "message", "value": "just want to say hi"},
{"field_id": "name", "value": "John"},
{"field_id": "foo", "value": "skip this"},
],
"subject": "test subject",
"block_id": "form-id",
},
)
transaction.commit()
self.assertEqual(response.status_code, 200)

0 comments on commit 41000e2

Please sign in to comment.