zulip/zerver/tests
Alex Vandiver fe25517295 email_notifications: Handle empty rendered_messages.
The transforms called from `build_message_payload` use
`lxml.html.fromstring` to parse (and stringify, and re-parse) the HTML
generated by Markdown.  However, this function fails if it is passed
an empty document.  "empty" is broader than just the empty string; it
also includes any document made entirely out of control characters,
spaces, unpaired surrogates, U+FFFE, or U+FFFF, and so forth.  These
documents would fail to parse, and raise a ParserError.

Using `lxml.html.fragment_fromstring` handles these cases, but does by
wrapping the contents in a <div> every time it is called.  As such,
replacing each `fromstring` with `fragment_fromstring` would nest
another layer of `<div>`.

Instead of each of the helper functions re-parsing, modifying, and
stringifying the HTML, parse it once with `fragment_fromstring` and
pass around the parsed document to each helper, which modifies it
in-place.  This adds one outer `<div>`, requiring minor changes to
tests and the prepend-sender functions.

The modification to add the sender is left using BeautifulSoup, as
that sort of transform is much less readable, and more fiddly, in raw
lxml.

Partial fix for #19559.
2021-08-25 15:50:55 -07:00
..
fixtures data_import: Fix channel mentions in Rocket.Chat import. 2021-08-09 06:38:26 -07:00
images upload: Replace exif_rotate with Pillow exif_transpose. 2021-08-09 20:32:19 -07:00
__init__.py
test_alert_words.py tests: Consistently use assert_length helper. 2021-05-19 11:55:56 -07:00
test_attachments.py
test_audit_log.py actions: Remove acting_client parameter from bulk_remove_subscriptions. 2021-08-19 01:51:37 -07:00
test_auth_backends.py python: Remove locally dead code. 2021-08-19 01:51:37 -07:00
test_bots.py typing: Avoid redefining variable with different types. 2021-08-20 06:02:56 -07:00
test_cache.py bots: Pass realm to get_system_bot calls in test_cache.py. 2021-07-26 15:33:13 -07:00
test_compatibility.py compatibility: Shift functions to new module. 2021-06-05 07:33:25 -07:00
test_create_video_call.py video_calls: Remove call to deprecated Zoom Data Compliance API. 2021-07-30 09:19:22 -07:00
test_custom_profile_data.py markdown: Refactor out additional properties added to Message. 2021-06-24 18:14:53 -07:00
test_data_types.py
test_decorators.py validator: Remove unused check_or function. 2021-08-19 01:52:24 -07:00
test_digest.py python: Remove unnecessary intermediate lists. 2021-08-02 15:53:52 -07:00
test_docs.py utils: Remove unused split_by function. 2021-08-19 01:51:37 -07:00
test_drafts.py populate_db: Create some drafts in the initial database. 2021-07-30 10:41:52 -07:00
test_email_change.py api: Remove "full_name" and "account_email" from response of '/settings'. 2021-07-16 16:10:15 -07:00
test_email_log.py
test_email_mirror.py bots: Pass realm to get_system_bot calls in email_mirror. 2021-07-26 15:33:13 -07:00
test_email_notifications.py email_notifications: Handle empty rendered_messages. 2021-08-25 15:50:55 -07:00
test_embedded_bot_system.py
test_event_queue.py notifications: Fix unnecessary wildcard mention notifications. 2021-08-13 09:48:18 -07:00
test_event_system.py register: Send user_settings in response based on client capabilities. 2021-08-01 15:30:17 -07:00
test_events.py actions: Remove acting_client parameter from bulk_remove_subscriptions. 2021-08-19 01:51:37 -07:00
test_example.py tests: Use assertion to enforce None-checks in tests. 2021-07-24 09:54:21 -07:00
test_external.py test_external: Extract rate_limit_rule() decorator. 2021-08-06 12:17:44 +02:00
test_github.py github: Use logging.exception so we know which exception happened. 2021-08-10 22:38:18 -07:00
test_gitter_importer.py tests: Consistently use assert_length helper. 2021-05-19 11:55:56 -07:00
test_home.py python: Remove default "utf8" argument for encode(), decode(). 2021-08-02 15:53:52 -07:00
test_hotspots.py tests: Consistently use assert_length helper. 2021-05-19 11:55:56 -07:00
test_i18n.py tests: Consistently use assert_length helper. 2021-05-19 11:55:56 -07:00
test_import_export.py utils: Remove unused query_chunker function. 2021-08-19 01:51:37 -07:00
test_integrations.py tests: Add a test for fixtures for non-webhook integrations. 2021-04-28 08:16:51 -07:00
test_integrations_dev_panel.py exceptions: Add ResourceNotFoundError. 2021-07-05 11:02:12 -07:00
test_internet.py
test_legacy_subject.py
test_link_embed.py python: Fix mypy no_implicit_reexport errors. 2021-07-16 14:02:31 -07:00
test_logging_handlers.py typing: Fix function signatures with django-stubs. 2021-08-20 06:02:55 -07:00
test_management_commands.py tests: Use assertion to enforce None-checks in tests. 2021-07-24 09:54:21 -07:00
test_markdown.py fenced_code: Optimize FENCE_RE to fix cubic worst-case complexity. 2021-07-22 16:40:44 -07:00
test_mattermost_importer.py data_import: Rename mattermost_user to user_handler. 2021-07-15 14:28:36 -07:00
test_message_dict.py bots: Pass realm to self.notification_bot test helper. 2021-07-26 15:33:13 -07:00
test_message_edit.py bots: Pass realm to self.notification_bot test helper. 2021-07-26 15:33:13 -07:00
test_message_edit_notifications.py notifications: Fix unnecessary wildcard mention notifications. 2021-08-13 09:48:18 -07:00
test_message_fetch.py api: Default `client_gravatar` to `true`. 2021-08-08 16:53:05 -07:00
test_message_flags.py page load: Remove sender_ids in unread messages for streams. 2021-08-04 11:44:00 -04:00
test_message_send.py bots: Pass realm to remaining get_system_bot calls in tests. 2021-07-26 15:33:13 -07:00
test_message_topics.py python: Fix mypy no_implicit_reexport errors. 2021-07-16 14:02:31 -07:00
test_messages.py notifications: Calculate PMs/mentions settings like other settings. 2021-07-28 13:55:25 -07:00
test_middleware.py test_middleware: Replace logging mocks with assertLogs. 2021-07-26 14:46:01 -07:00
test_migrations.py
test_mirror_users.py tests: Migrate mocked Request to HostMockRequest. 2021-07-14 12:01:07 -07:00
test_muting_topics.py models: Remove MutedTopic alias for UserTopic. 2021-07-28 10:25:54 -07:00
test_muting_users.py python: Convert "".format to Python 3.6 f-strings. 2021-08-02 15:53:52 -07:00
test_new_users.py populate_db: Use do_create_realm for creating zulip realm. 2021-07-06 17:37:43 -07:00
test_notification_data.py notifications: Fix unnecessary wildcard mention notifications. 2021-08-13 09:48:18 -07:00
test_onboarding.py
test_openapi.py typing: Avoid redefining variable with different types. 2021-08-20 06:02:56 -07:00
test_outgoing_http.py python: Convert "".format to Python 3.6 f-strings. 2021-08-02 15:53:52 -07:00
test_outgoing_webhook_interfaces.py outgoing_webhook: Improve invalid json handling when parsing response. 2021-04-26 09:32:35 -07:00
test_outgoing_webhook_system.py tests: Consistently use assert_length helper. 2021-05-19 11:55:56 -07:00
test_populate_db.py
test_presence.py statistics: Remove unused seconds_usage_between function. 2021-08-19 01:51:37 -07:00
test_push_notifications.py push_notifications: Refactor testcases to fix mypy errors. 2021-08-20 05:54:19 -07:00
test_queue.py mypy: Add pika-stubs. 2021-08-02 22:31:46 -07:00
test_queue_worker.py missedmessage_emails: Ensure forward progress. 2021-08-20 07:21:39 -07:00
test_rate_limiter.py rate_limit: Implement IP-based rate limiting. 2021-07-08 15:46:52 -07:00
test_reactions.py python: Fix mypy no_implicit_reexport errors. 2021-07-16 14:02:31 -07:00
test_realm.py setting: Use "unlimited" instead of "forever" for retention setting. 2021-08-08 15:56:57 -07:00
test_realm_domains.py tests: Clean up tests for realm_domain and update_streams endpoint. 2021-05-12 12:38:16 -07:00
test_realm_emoji.py realm: Extend add_custom_emoji_policy to use COMMON_POLICY_TYPES. 2021-07-27 16:41:23 -07:00
test_realm_export.py tests: Pass HostRequestMock to export_realm. 2021-07-26 15:09:07 -07:00
test_realm_linkifiers.py linkifiers: Add joint validation for linkifier urls and patterns. 2021-06-16 17:51:33 -07:00
test_realm_playgrounds.py models: Fix bug in unique_together condition on RealmPlayground. 2021-05-24 23:11:41 -07:00
test_redis_utils.py
test_report.py docs: Fix capitalization mistakes. 2021-05-10 09:57:26 -07:00
test_retention.py bots: Pass realm to remaining get_system_bot calls in tests. 2021-07-26 15:33:13 -07:00
test_rocketchat_importer.py data_import: Fix channel mentions in Rocket.Chat import. 2021-08-09 06:38:26 -07:00
test_send_email.py python: Convert "".format to Python 3.6 f-strings. 2021-08-02 15:53:52 -07:00
test_service_bot_system.py tests: Consistently use assert_length helper. 2021-05-19 11:55:56 -07:00
test_sessions.py test_sessions: Fix unnecessarily hard-coded user id. 2021-07-13 08:31:11 -07:00
test_settings.py drafts: Add support for toggling drafts synchronization. 2021-07-30 10:00:27 -07:00
test_signup.py marketing_emails: Ask for user's consent at sign-up. 2021-08-20 06:43:26 -07:00
test_slack_importer.py slack_import: Remove obsolete SlackImportAttachment placeholder. 2021-08-02 13:13:28 -07:00
test_slack_message_conversion.py tests: Consistently use assert_length helper. 2021-05-19 11:55:56 -07:00
test_soft_deactivation.py tests: Consistently use assert_length helper. 2021-05-19 11:55:56 -07:00
test_subdomains.py subdomains: Extend "static" to include resources hosted on S3. 2021-06-08 15:28:10 -07:00
test_submessage.py submessages: Add verify_submessage_sender. 2021-06-14 17:46:16 -07:00
test_subs.py actions: Remove acting_client parameter from bulk_remove_subscriptions. 2021-08-19 01:51:37 -07:00
test_templates.py
test_thumbnail.py requirements: Remove Thumbor. 2021-05-06 20:07:32 -07:00
test_timestamp.py
test_timezone.py docs: Fix spelling errors caught by codespell. 2021-04-26 09:31:08 -07:00
test_tornado.py tornado: Explicitly mark requests as varying by cookie. 2021-04-02 14:55:22 -07:00
test_transfer.py tests: Consistently use assert_length helper. 2021-05-19 11:55:56 -07:00
test_tutorial.py bots: Pass realm to remaining get_system_bot calls in tests. 2021-07-26 15:33:13 -07:00
test_type_debug.py
test_typing.py tornado_redirected_to_list: Make expected_num_events required argument. 2021-05-28 09:42:14 -07:00
test_upload.py typing: Use assertions for responses when appropriate. 2021-08-20 06:02:56 -07:00
test_urls.py auth: Implement a generic OpenID Connect backend. 2021-05-28 09:43:06 -07:00
test_user_groups.py user_groups: Do not allow editing system user groups from API. 2021-08-19 02:54:29 -07:00
test_user_status.py user_status: Add backend changes to support status emoji. 2021-07-27 17:57:15 -07:00
test_users.py typing: Improve typing with assertions. 2021-08-20 05:54:19 -07:00
test_webhooks_common.py typing: Fix function signatures. 2021-08-20 05:54:19 -07:00
test_widgets.py widgets: Add range checks on backend for indexes. 2021-06-29 13:40:33 -07:00
test_zcommand.py
test_zephyr.py docs: Add missing space to compound verbs “log in”, “set up”, etc. 2021-04-26 09:31:08 -07:00