Skip to content

Commit

Permalink
Improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Jan 19, 2024
1 parent 22f8a9a commit 6a21647
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ def display_value(self):
elif self._value is False:
return self._display_value_mapping.get("no")

@property
def send_in_email(self):
return True


class AttachmentField(Field):
@property
Expand Down
75 changes: 75 additions & 0 deletions src/collective/volto/formsupport/tests/test_send_action_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -811,11 +811,31 @@ def test_field_custom_display_value(
"field_id": "12345678",
"display_values": {"John": "Paul"},
},
{
"field_id": "000000002",
"field_type": "yes_no",
"widget": "single_choice",
"display_values": {"yes": "Correct", "no": "Incorrect"},
},
{
"label": "Yes/ no radio without display value",
"field_id": "000000003",
"field_type": "yes_no",
"widget": "single_choice",
},
{
"label": "My attachment field",
"field_id": "000000004",
"field_type": "attachment",
},
],
}
}
transaction.commit()

filename = os.path.join(os.path.dirname(__file__), "file.pdf")
with open(filename, "rb") as f:
file_str = f.read()
response = self.submit_form(
data={
"from": "[email protected]",
Expand All @@ -826,7 +846,21 @@ def test_field_custom_display_value(
"field_id": "12345678",
"value": "John",
},
{
"label": "Yes/ no",
"field_id": "000000002",
"value": True,
},
{
"field_id": "000000003",
"value": True,
},
{
"field_id": "000000004",
"value": "Attachments don't work this way normally, this is just to test",
},
],
"attachments": {"foo": {"data": base64.b64encode(file_str)}},
"subject": "test subject",
"block_id": "form-id",
},
Expand All @@ -843,6 +877,47 @@ def test_field_custom_display_value(
self.assertIn("Reply-To: [email protected]", msg)
self.assertIn("<strong>Message:</strong> just want to say hi", msg)
self.assertIn("<strong>Name:</strong> Paul", msg)
self.assertIn("<strong>Yes/ no:</strong> Correct", msg)
self.assertIn("<strong>Yes/ no radio without display value:</strong> True", msg)
self.assertNotIn(
"<strong>My attachment field:</strong>",
Parser()
.parse(StringIO(msg))
.get_payload()[0]
.get_payload(), # 1st get_payload splits the messages. First message is the body and second is the attachment
)
self.assertNotIn("foo", msg)

# breakpoint()

response = self.submit_form(
data={
"from": "[email protected]",
"data": [
{
"label": "Yes/ no",
"field_id": "000000002",
"value": False,
},
{
"field_id": "000000003",
"value": False,
},
],
"subject": "test subject",
"block_id": "form-id",
},
)
transaction.commit()

msg = self.mailhost.messages[1]
if isinstance(msg, bytes) and bytes is not str:
# Python 3 with Products.MailHost 4.10+
msg = msg.decode("utf-8")
self.assertIn("<strong>Yes/ no:</strong> Incorrect", msg)
self.assertIn(
"<strong>Yes/ no radio without display value:</strong> False", msg
)

def test_send_custom_field_id(self):
"""Custom field IDs should still appear as their friendly names in the email"""
Expand Down

0 comments on commit 6a21647

Please sign in to comment.