Skip to content

Commit da13bf8

Browse files
authored
Fixed github workflow (#231)
* Fixed github workflow * Fixed workflow * Fixed workflow * Fixed workflow * Fixed workflow
1 parent e46acb2 commit da13bf8

File tree

5 files changed

+57
-49
lines changed

5 files changed

+57
-49
lines changed

.github/workflows/lint.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ on:
66
pull_request:
77
branches: [ "**" ]
88

9-
jobs:
109

1110
jobs:
1211
ci:
1312
strategy:
1413
fail-fast: false
1514
matrix:
16-
python-version: [3.8, 3.9]
15+
python-version: [3.9, 3.11]
1716
poetry-version: [1.3.1]
1817
os: [ubuntu-latest]
1918
runs-on: ${{ matrix.os }}

.github/workflows/test.yml

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,29 @@ on:
66
pull_request:
77
branches: [ "**" ]
88

9+
10+
name: CI Tests
11+
on: [push, pull_request]
12+
913
jobs:
1014
ci:
1115
strategy:
1216
fail-fast: false
1317
matrix:
14-
python-version: [3.8, 3.9, 3.10, 3.11]
18+
python-version: [3.8, 3.9]
1519
poetry-version: [1.3.1]
1620
os: [ubuntu-latest]
1721
runs-on: ${{ matrix.os }}
1822
steps:
19-
- uses: actions/checkout@v4
20-
- uses: actions/setup-python@v5
23+
- uses: actions/checkout@v2
24+
- uses: actions/setup-python@v2
2125
with:
2226
python-version: ${{ matrix.python-version }}
23-
- name: Cache Poetry dependencies
24-
uses: actions/cache@v4
25-
with:
26-
path: |
27-
~/.cache/pypoetry
28-
~/.cache/pip
29-
key: ${{ runner.os }}-poetry-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }}
30-
restore-keys: |
31-
${{ runner.os }}-poetry-${{ matrix.python-version }}-
32-
- name: Install Poetry
27+
- name: Run image
3328
uses: abatilo/actions-poetry@v2.0.0
3429
with:
3530
poetry-version: ${{ matrix.poetry-version }}
3631
- name: Install dependencies
3732
run: poetry install
3833
- name: Run tests
39-
run: poetry run make test
34+
run: poetry run make test

Makefile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
lint:
22
@echo
3-
isort --diff -c --skip-glob '*.venv' .
3+
isort --diff -c --skip-glob '*.venv' --skip app.py .
44
@echo
5-
black .
5+
black --exclude '(\.venv|app\.py)' .
66
@echo
7-
flake8 .
7+
flake8 --exclude app.py,.venv .
88
@echo
9-
mypy --ignore-missing-imports .
9+
mypy --ignore-missing-imports --exclude '(\.venv/|app\.py)' .
1010

1111

1212
format_code:
13-
isort .
14-
black .
15-
flake8 .
13+
isort --skip app.py .
14+
black --exclude '(\.venv|app\.py)' .
15+
flake8 --exclude app.py,.venv .
1616

1717

1818
test:

fastapi_mail/fastmail.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,17 @@ async def get_mail_template(
5656
return env_path.get_template(template_name)
5757

5858
@staticmethod
59-
def check_data(data: Union[Dict[Any, Any], str, None]) -> Dict[Any, Any]:
60-
if not isinstance(data, dict):
59+
def check_data(data: Union[Dict[Any, Any], str, None, list[Any]]) -> Dict[Any, Any]:
60+
if isinstance(data, dict):
61+
return data
62+
elif isinstance(data, list):
63+
return {"body": data}
64+
else:
6165
raise ValueError(
6266
f"Unable to build template data dictionary - {type(data)}"
6367
"is an invalid source data type"
6468
)
6569

66-
return data
67-
6870
async def __prepare_message(
6971
self, message: MessageSchema, template: Optional[Template] = None
7072
) -> Union[EmailMessage, Message]:
@@ -129,19 +131,19 @@ async def send_message(
129131
template_name or (html_template and plain_template)
130132
):
131133
if template_name:
132-
template = await self.get_mail_template(
133-
self.config.template_engine(), template_name
134+
template_obj = await self.get_mail_template(
135+
self.config.template_engine(), template_name # type: ignore
134136
)
135-
msg = await self.__prepare_message(message, template)
137+
msg = await self.__prepare_message(message, template_obj)
136138
else:
137-
html_template = await self.get_mail_template(
138-
self.config.template_engine(), html_template
139+
html_template_obj = await self.get_mail_template(
140+
self.config.template_engine(), html_template or "" # type: ignore
139141
)
140-
plain_template = await self.get_mail_template(
141-
self.config.template_engine(), plain_template
142+
plain_template_obj = await self.get_mail_template(
143+
self.config.template_engine(), plain_template or "" # type: ignore
142144
)
143145
msg = await self.__prepare_html_and_plain_message(
144-
message, html_template, plain_template
146+
message, html_template_obj, plain_template_obj
145147
)
146148
else:
147149
msg = await self.__prepare_message(message)

tests/test_connection.py

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ async def test_attachement_message(mail_config):
8989

9090
assert len(outbox) == 1
9191
assert mail._payload[1].get_content_maintype() == "application"
92-
assert mail._payload[1].__dict__.get("_headers")[0][1] == "application/octet-stream"
92+
assert (
93+
mail._payload[1].__dict__.get("_headers")[0][1]
94+
== "application/octet-stream"
95+
)
9396

9497

9598
@pytest.mark.asyncio
@@ -151,16 +154,20 @@ async def test_attachement_message_with_headers(mail_config):
151154

152155
assert len(outbox) == 1
153156
mail = outbox[0]
154-
assert mail._payload[1].get_content_maintype() == msg.attachments[0][1].get("mime_type")
155-
assert mail._payload[1].get_content_subtype() == msg.attachments[0][1].get("mime_subtype")
157+
assert mail._payload[1].get_content_maintype() == msg.attachments[0][1].get(
158+
"mime_type"
159+
)
160+
assert mail._payload[1].get_content_subtype() == msg.attachments[0][1].get(
161+
"mime_subtype"
162+
)
156163

157164
assert mail._payload[1].__dict__.get("_headers")[0][1] == "image/png"
158-
assert mail._payload[1].__dict__.get("_headers")[3][1] == msg.attachments[0][1].get(
159-
"headers"
160-
).get("Content-ID")
161-
assert mail._payload[1].__dict__.get("_headers")[4][1] == msg.attachments[0][1].get(
162-
"headers"
163-
).get("Content-Disposition")
165+
assert mail._payload[1].__dict__.get("_headers")[3][1] == msg.attachments[0][
166+
1
167+
].get("headers").get("Content-ID")
168+
assert mail._payload[1].__dict__.get("_headers")[4][1] == msg.attachments[0][
169+
1
170+
].get("headers").get("Content-Disposition")
164171

165172
assert (
166173
mail._payload[2].__dict__.get("_headers")[3][1] == "attachment; "
@@ -184,7 +191,9 @@ async def test_jinja_message_list(mail_config):
184191
fm = FastMail(conf)
185192

186193
with fm.record_messages() as outbox:
187-
await fm.send_message(message=msg, template_name="array_iteration_jinja_template.html")
194+
await fm.send_message(
195+
message=msg, template_name="array_iteration_jinja_template.html"
196+
)
188197

189198
assert len(outbox) == 1
190199
mail = outbox[0]
@@ -283,7 +292,9 @@ async def test_jinja_message_with_html(mail_config):
283292
)
284293
conf = ConnectionConfig(**mail_config)
285294
fm = FastMail(conf)
286-
await fm.send_message(message=msg, template_name="array_iteration_jinja_template.html")
295+
await fm.send_message(
296+
message=msg, template_name="array_iteration_jinja_template.html"
297+
)
287298

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

@@ -364,7 +375,10 @@ async def test_send_msg_with_alternative_body_and_attachements(mail_config):
364375

365376
assert mail._payload[1].get_content_maintype() == "application"
366377

367-
assert mail._payload[1].__dict__.get("_headers")[0][1] == "application/octet-stream"
378+
assert (
379+
mail._payload[1].__dict__.get("_headers")[0][1]
380+
== "application/octet-stream"
381+
)
368382

369383

370384
@pytest.mark.asyncio
@@ -382,7 +396,6 @@ async def test_local_hostname_resolving(mail_config):
382396
assert session.session.local_hostname == conf.LOCAL_HOSTNAME
383397

384398

385-
386399
@pytest.mark.asyncio
387400
async def test_jinja_html_and_plain_message(mail_config):
388401
sender = f"{mail_config['MAIL_FROM_NAME']} <{mail_config['MAIL_FROM']}>"
@@ -443,4 +456,3 @@ async def test_jinja_plain_and_html_message(mail_config):
443456
assert msg.subtype == MessageType.plain
444457
assert msg.template_body == "Andrej"
445458
assert msg.alternative_body == "<b>Andrej</b>"
446-

0 commit comments

Comments
 (0)