Skip to content

Commit 37ca699

Browse files
committed
fixed linter issues and tests
1 parent e42b3de commit 37ca699

File tree

6 files changed

+39
-30
lines changed

6 files changed

+39
-30
lines changed

.github/workflows/linter.yaml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
name: CI
2-
3-
on:
4-
push:
5-
branches: '**'
6-
pull_request:
7-
branches: '**'
1+
name: CI Linter
2+
on: [push, pull_request]
83

94
jobs:
105
ci:

.github/workflows/test-package.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
name: CI
2-
on:
3-
push:
4-
branches: '**'
1+
name: CI Tests
2+
on: [push, pull_request]
53

64
jobs:
75
ci:

fastapi_mail/msg.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from email.mime.text import MIMEText
88
from email.utils import formatdate, make_msgid
99
from typing import Any, Union
10+
1011
from .schemas import MessageType, MultipartSubtypeEnum
1112

1213
PY3 = sys.version_info[0] == 3

fastapi_mail/schemas.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from mimetypes import MimeTypes
55
from typing import Dict, List, Optional, Union
66

7-
from pydantic import BaseModel, EmailStr, validator, root_validator
7+
from pydantic import BaseModel, EmailStr, root_validator, validator
88
from starlette.datastructures import Headers, UploadFile
99

1010
from fastapi_mail.errors import WrongFile
@@ -72,7 +72,9 @@ def validate_file(cls, v):
7272
if content_type:
7373
headers = Headers({"content-type": content_type})
7474
file_content = BytesIO(f.read())
75-
u = UploadFile(filename=file_name, file=file_content, headers=headers)
75+
u = UploadFile(
76+
filename=file_name, file=file_content, headers=headers
77+
)
7678
temp.append((u, file_meta))
7779
else:
7880
raise WrongFile(

tests/test_connection.py

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ async def test_attachement_message(mail_config):
8787

8888
assert len(outbox) == 1
8989
assert mail._payload[1].get_content_maintype() == "application"
90-
assert mail._payload[1].__dict__.get("_headers")[0][1] == "application/octet-stream"
90+
assert (
91+
mail._payload[1].__dict__.get("_headers")[0][1]
92+
== "application/octet-stream"
93+
)
9194

9295

9396
@pytest.mark.asyncio
@@ -149,16 +152,20 @@ async def test_attachement_message_with_headers(mail_config):
149152

150153
assert len(outbox) == 1
151154
mail = outbox[0]
152-
assert mail._payload[1].get_content_maintype() == msg.attachments[0][1].get("mime_type")
153-
assert mail._payload[1].get_content_subtype() == msg.attachments[0][1].get("mime_subtype")
155+
assert mail._payload[1].get_content_maintype() == msg.attachments[0][1].get(
156+
"mime_type"
157+
)
158+
assert mail._payload[1].get_content_subtype() == msg.attachments[0][1].get(
159+
"mime_subtype"
160+
)
154161

155162
assert mail._payload[1].__dict__.get("_headers")[0][1] == "image/png"
156-
assert mail._payload[1].__dict__.get("_headers")[3][1] == msg.attachments[0][1].get(
157-
"headers"
158-
).get("Content-ID")
159-
assert mail._payload[1].__dict__.get("_headers")[4][1] == msg.attachments[0][1].get(
160-
"headers"
161-
).get("Content-Disposition")
163+
assert mail._payload[1].__dict__.get("_headers")[3][1] == msg.attachments[0][
164+
1
165+
].get("headers").get("Content-ID")
166+
assert mail._payload[1].__dict__.get("_headers")[4][1] == msg.attachments[0][
167+
1
168+
].get("headers").get("Content-Disposition")
162169

163170
assert (
164171
mail._payload[2].__dict__.get("_headers")[3][1] == "attachment; "
@@ -182,7 +189,9 @@ async def test_jinja_message_list(mail_config):
182189
fm = FastMail(conf)
183190

184191
with fm.record_messages() as outbox:
185-
await fm.send_message(message=msg, template_name="array_iteration_jinja_template.html")
192+
await fm.send_message(
193+
message=msg, template_name="array_iteration_jinja_template.html"
194+
)
186195

187196
assert len(outbox) == 1
188197
mail = outbox[0]
@@ -248,7 +257,7 @@ async def test_send_msg_with_subtype(mail_config):
248257
msg = MessageSchema(
249258
subject="testing",
250259
recipients=["[email protected]"],
251-
body="<p Test data </p>",
260+
body="<p> Test data </p>",
252261
subtype=MessageType.html,
253262
)
254263

@@ -263,7 +272,7 @@ async def test_send_msg_with_subtype(mail_config):
263272
assert outbox[0]["subject"] == "testing"
264273
assert outbox[0]["from"] == sender
265274
assert outbox[0]["To"] == "[email protected]"
266-
assert msg.body == "<p Test data </p>"
275+
assert msg.body == "<p> Test data </p>"
267276
assert msg.subtype == MessageType.html
268277

269278

@@ -281,7 +290,9 @@ async def test_jinja_message_with_html(mail_config):
281290
)
282291
conf = ConnectionConfig(**mail_config)
283292
fm = FastMail(conf)
284-
await fm.send_message(message=msg, template_name="array_iteration_jinja_template.html")
293+
await fm.send_message(
294+
message=msg, template_name="array_iteration_jinja_template.html"
295+
)
285296

286297
assert msg.template_body == ("\n \n \n Andrej\n \n\n")
287298

@@ -293,7 +304,7 @@ async def test_send_msg_with_alternative_body(mail_config):
293304
msg = MessageSchema(
294305
subject="testing",
295306
recipients=["[email protected]"],
296-
body="<p Test data </p>",
307+
body="<p> Test data </p>",
297308
subtype=MessageType.html,
298309
alternative_body="Test data",
299310
multipart_subtype=MultipartSubtypeEnum.alternative,
@@ -361,4 +372,7 @@ async def test_send_msg_with_alternative_body_and_attachements(mail_config):
361372
assert body._payload[1]._headers[0][1] == 'text/plain; charset="utf-8"'
362373

363374
assert mail._payload[1].get_content_maintype() == "application"
364-
assert mail._payload[1].__dict__.get("_headers")[0][1] == "application/octet-stream"
375+
assert (
376+
mail._payload[1].__dict__.get("_headers")[0][1]
377+
== "application/octet-stream"
378+
)

tests/test_message.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
from fastapi_mail.msg import MailMsg
66
from fastapi_mail.schemas import MessageSchema, MessageType, MultipartSubtypeEnum
7-
from pydantic.error_wrappers import ValidationError
87

98

109
def test_initialize():
@@ -199,7 +198,7 @@ def test_message_with_alternative_body_but_wrong_multipart_subtype():
199198
subtype=MessageType.plain,
200199
alternative_body="alternative",
201200
)
202-
assert message.alternative_body == None
201+
assert message.alternative_body is None
203202

204203

205204
def test_message_with_alternative_body():

0 commit comments

Comments
 (0)