From 8e0738757939d3df9c865bbf789d5a42070ef792 Mon Sep 17 00:00:00 2001 From: Rust Saiargaliev Date: Wed, 7 Aug 2024 11:26:22 +0200 Subject: [PATCH] Fix places --- emark/backends.py | 7 +++---- emark/message.py | 10 ++++------ emark/utils.py | 3 +-- tests/test_backends.py | 1 - tests/test_message.py | 5 ++--- tests/test_views.py | 3 +-- tests/testapp/settings.py | 7 ++++--- 7 files changed, 15 insertions(+), 21 deletions(-) diff --git a/emark/backends.py b/emark/backends.py index 9e549ed..f762d49 100644 --- a/emark/backends.py +++ b/emark/backends.py @@ -24,7 +24,7 @@ def send_messages(self, email_messages): class TrackingEmailBackendMixin: - """Add tracking framework to an email backend.""" + """Add a tracking framework to an email backend.""" def send_messages(self, email_messages): self._messages_sent = [] @@ -83,7 +83,7 @@ def write_message(self, message): msg.get_charset().get_output_charset() if msg.get_charset() else "utf-8" ) msg_data = msg_data.decode(charset) - self.stream.write("%s\n" % msg_data) + self.stream.write(f"{msg_data}\n") self.stream.write("-" * 79) self.stream.write("\n") if payload_count > 1: @@ -119,8 +119,7 @@ def write_message(self, message): class TrackingSMTPEmailBackend(TrackingEmailBackendMixin, _SMTPEmailBackend): - """ - Like the SMTP email backend but with click and open tracking. + """Like the SMTP email backend but with click and open tracking. Furthermore, all emails are sent to a single email address. If multiple to, cc, or bcc addresses are specified, a separate diff --git a/emark/message.py b/emark/message.py index 2220205..3ca2329 100644 --- a/emark/message.py +++ b/emark/message.py @@ -25,8 +25,7 @@ class MarkdownEmail(EmailMultiAlternatives): - """ - Multipart email message that renders both plaintext and HTML from markdown. + """Multipart email message that renders both plaintext and HTML from markdown. This is a full class:`EmailMultiAlternatives` subclass with additional support to send emails directly to a users. It also requires an explicit language @@ -102,7 +101,7 @@ def message(self): def get_utm_campaign_name(cls): """Return the UTM campaign name for this email.""" return "_".join( - (m.group(0) for m in CLS_NAME_TO_CAMPAIGN_RE.finditer(cls.__qualname__)) + m.group(0) for m in CLS_NAME_TO_CAMPAIGN_RE.finditer(cls.__qualname__) ).upper() def update_url_params(self, url, **params): @@ -192,8 +191,7 @@ def get_subject(self, **context): return self.subject % context def get_preheader(self): - """ - Return the email's preheader. + """Return the email's preheader. A brief text that recipients will see in their inbox before opening the email along with the subject. Unless explicitly set, the preheader will be the first @@ -217,7 +215,7 @@ def get_html(self, markdown_string, context): "markdown.extensions.extra", ], ) - context["markdown_string"] = mark_safe(html_message) # nosec + context["markdown_string"] = mark_safe(html_message) # noqa: S308 template = loader.get_template(self.base_html_template) rendered_html = template.render(context) diff --git a/emark/utils.py b/emark/utils.py index 95115e5..2fd8f91 100644 --- a/emark/utils.py +++ b/emark/utils.py @@ -9,8 +9,7 @@ @dataclasses.dataclass class Node: - """ - Simple HTML node that can be extracted into plain text. + """Simple HTML node that can be extracted into plain text. Nodes have a parent and children link to create a tree structure. Plain text extraction is done by recursively traversing the tree. diff --git a/tests/test_backends.py b/tests/test_backends.py index a8412d7..353930a 100644 --- a/tests/test_backends.py +++ b/tests/test_backends.py @@ -4,7 +4,6 @@ import pytest from django.core.mail import EmailMessage, EmailMultiAlternatives - from emark import backends from emark.models import Send diff --git a/tests/test_message.py b/tests/test_message.py index 872069f..2a74add 100644 --- a/tests/test_message.py +++ b/tests/test_message.py @@ -1,14 +1,13 @@ import copy from pathlib import Path +import emark.message import pytest from django.conf import settings from django.core.exceptions import ImproperlyConfigured from django.test.html import parse_html from model_bakery import baker -import emark.message - BASE_DIR = Path(__file__).resolve().parent.parent @@ -250,7 +249,7 @@ def test_get_preheader__missing(self): language="en-US", context={"donut_name": "HoneyNuts", "donut_type": "Honey"}, ) - msg.get_preheader() == "" + assert msg.get_preheader() == "" def test_get_preheader(self): email_message = MarkdownEmailTestWithPreheader( diff --git a/tests/test_views.py b/tests/test_views.py index e568a00..311f57e 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -3,9 +3,8 @@ import pytest from django.urls import reverse from django.utils.http import urlencode -from model_bakery import baker - from emark import models +from model_bakery import baker class TestEmailDetailView: diff --git a/tests/testapp/settings.py b/tests/testapp/settings.py index 99b2082..a12bcdb 100644 --- a/tests/testapp/settings.py +++ b/tests/testapp/settings.py @@ -1,5 +1,4 @@ -""" -Django settings for testapp project. +"""Django settings for testapp project. Generated by 'django-admin startproject' using Django 4.0.4. @@ -20,7 +19,9 @@ # See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = "django-insecure-4787+%emei)bk2ue$5^0(5_i3+fz-0^87v)myt+8y__n$-o4@l" +SECRET_KEY = ( + "django-insecure-4787+%emei)bk2ue$5^0(5_i3+fz-0^87v)myt+8y__n$-o4@l" # noqa: S105 +) # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True