Skip to content

Commit

Permalink
fixed linter issues and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sabuhish committed Jun 25, 2023
1 parent e42b3de commit 37ca699
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 30 deletions.
9 changes: 2 additions & 7 deletions .github/workflows/linter.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
name: CI

on:
push:
branches: '**'
pull_request:
branches: '**'
name: CI Linter
on: [push, pull_request]

jobs:
ci:
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/test-package.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
name: CI
on:
push:
branches: '**'
name: CI Tests
on: [push, pull_request]

jobs:
ci:
Expand Down
1 change: 1 addition & 0 deletions fastapi_mail/msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from email.mime.text import MIMEText
from email.utils import formatdate, make_msgid
from typing import Any, Union

from .schemas import MessageType, MultipartSubtypeEnum

PY3 = sys.version_info[0] == 3
Expand Down
6 changes: 4 additions & 2 deletions fastapi_mail/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from mimetypes import MimeTypes
from typing import Dict, List, Optional, Union

from pydantic import BaseModel, EmailStr, validator, root_validator
from pydantic import BaseModel, EmailStr, root_validator, validator
from starlette.datastructures import Headers, UploadFile

from fastapi_mail.errors import WrongFile
Expand Down Expand Up @@ -72,7 +72,9 @@ def validate_file(cls, v):
if content_type:
headers = Headers({"content-type": content_type})
file_content = BytesIO(f.read())
u = UploadFile(filename=file_name, file=file_content, headers=headers)
u = UploadFile(
filename=file_name, file=file_content, headers=headers
)
temp.append((u, file_meta))
else:
raise WrongFile(
Expand Down
44 changes: 29 additions & 15 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ async def test_attachement_message(mail_config):

assert len(outbox) == 1
assert mail._payload[1].get_content_maintype() == "application"
assert mail._payload[1].__dict__.get("_headers")[0][1] == "application/octet-stream"
assert (
mail._payload[1].__dict__.get("_headers")[0][1]
== "application/octet-stream"
)


@pytest.mark.asyncio
Expand Down Expand Up @@ -149,16 +152,20 @@ async def test_attachement_message_with_headers(mail_config):

assert len(outbox) == 1
mail = outbox[0]
assert mail._payload[1].get_content_maintype() == msg.attachments[0][1].get("mime_type")
assert mail._payload[1].get_content_subtype() == msg.attachments[0][1].get("mime_subtype")
assert mail._payload[1].get_content_maintype() == msg.attachments[0][1].get(
"mime_type"
)
assert mail._payload[1].get_content_subtype() == msg.attachments[0][1].get(
"mime_subtype"
)

assert mail._payload[1].__dict__.get("_headers")[0][1] == "image/png"
assert mail._payload[1].__dict__.get("_headers")[3][1] == msg.attachments[0][1].get(
"headers"
).get("Content-ID")
assert mail._payload[1].__dict__.get("_headers")[4][1] == msg.attachments[0][1].get(
"headers"
).get("Content-Disposition")
assert mail._payload[1].__dict__.get("_headers")[3][1] == msg.attachments[0][
1
].get("headers").get("Content-ID")
assert mail._payload[1].__dict__.get("_headers")[4][1] == msg.attachments[0][
1
].get("headers").get("Content-Disposition")

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

with fm.record_messages() as outbox:
await fm.send_message(message=msg, template_name="array_iteration_jinja_template.html")
await fm.send_message(
message=msg, template_name="array_iteration_jinja_template.html"
)

assert len(outbox) == 1
mail = outbox[0]
Expand Down Expand Up @@ -248,7 +257,7 @@ async def test_send_msg_with_subtype(mail_config):
msg = MessageSchema(
subject="testing",
recipients=["to@example.com"],
body="<p Test data </p>",
body="<p> Test data </p>",
subtype=MessageType.html,
)

Expand All @@ -263,7 +272,7 @@ async def test_send_msg_with_subtype(mail_config):
assert outbox[0]["subject"] == "testing"
assert outbox[0]["from"] == sender
assert outbox[0]["To"] == "to@example.com"
assert msg.body == "<p Test data </p>"
assert msg.body == "<p> Test data </p>"
assert msg.subtype == MessageType.html


Expand All @@ -281,7 +290,9 @@ async def test_jinja_message_with_html(mail_config):
)
conf = ConnectionConfig(**mail_config)
fm = FastMail(conf)
await fm.send_message(message=msg, template_name="array_iteration_jinja_template.html")
await fm.send_message(
message=msg, template_name="array_iteration_jinja_template.html"
)

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

Expand All @@ -293,7 +304,7 @@ async def test_send_msg_with_alternative_body(mail_config):
msg = MessageSchema(
subject="testing",
recipients=["to@example.com"],
body="<p Test data </p>",
body="<p> Test data </p>",
subtype=MessageType.html,
alternative_body="Test data",
multipart_subtype=MultipartSubtypeEnum.alternative,
Expand Down Expand Up @@ -361,4 +372,7 @@ async def test_send_msg_with_alternative_body_and_attachements(mail_config):
assert body._payload[1]._headers[0][1] == 'text/plain; charset="utf-8"'

assert mail._payload[1].get_content_maintype() == "application"
assert mail._payload[1].__dict__.get("_headers")[0][1] == "application/octet-stream"
assert (
mail._payload[1].__dict__.get("_headers")[0][1]
== "application/octet-stream"
)
3 changes: 1 addition & 2 deletions tests/test_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from fastapi_mail.msg import MailMsg
from fastapi_mail.schemas import MessageSchema, MessageType, MultipartSubtypeEnum
from pydantic.error_wrappers import ValidationError


def test_initialize():
Expand Down Expand Up @@ -199,7 +198,7 @@ def test_message_with_alternative_body_but_wrong_multipart_subtype():
subtype=MessageType.plain,
alternative_body="alternative",
)
assert message.alternative_body == None
assert message.alternative_body is None


def test_message_with_alternative_body():
Expand Down

0 comments on commit 37ca699

Please # to comment.