Skip to content

Commit 022c8d3

Browse files
committed
Add tests to Github Actions
1 parent 0345136 commit 022c8d3

File tree

5 files changed

+115
-4
lines changed

5 files changed

+115
-4
lines changed

.github/workflows/test.yml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
3+
name: Test
4+
on:
5+
push:
6+
branches: [master]
7+
pull_request:
8+
branches: [master]
9+
10+
jobs:
11+
test:
12+
runs-on: ubuntu-latest
13+
strategy:
14+
max-parallel: 4
15+
matrix:
16+
python: ['3.8', '3.9', '3.10', '3.11', '3.12']
17+
18+
steps:
19+
- uses: actions/checkout@v2
20+
with:
21+
fetch-depth: 1
22+
23+
- name: Set up Python ${{ matrix.python-version }}
24+
uses: actions/setup-python@v1
25+
with:
26+
python-version: ${{ matrix.python }}
27+
28+
- name: Install dependencies
29+
run: python -m pip install --upgrade pip tox tox-gh-actions
30+
31+
- name: Run tests
32+
run: tox

README.rst

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ Assumptions
1616
Changelog
1717
=========
1818

19+
1.1.17
20+
------
21+
* Add support for django 4 - https://github.com/deployed/django-emailtemplates/pull/39
22+
1923
1.1.16
2024
------
2125
* change max_length from 100 to 255 in email attachments - https://github.com/deployed/django-emailtemplates/pull/38

emailtemplates/tests/test_models.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ def test_send_with_attachments(self):
9393
recipients = ["[email protected]"]
9494
sent = self.mass_email_message.send(recipients)
9595
self.assertTrue(sent)
96-
self.assertEqual(
97-
mail.outbox[0].attachments,
98-
[("example_file.txt", "Some content of example file.", "text/plain")],
99-
)
96+
attachments = mail.outbox[0].attachments
97+
self.assertEqual(len(attachments), 1)
98+
self.assertTrue(attachments[0][0].startswith("example_file"))
99+
self.assertTrue(attachments[0][0].endswith(".txt"))
100+
self.assertEqual(attachments[0][1], "Some content of example file.")
101+
self.assertEqual(attachments[0][2], "text/plain")

runtests.py

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import sys
2+
3+
import django
4+
from django.conf import settings
5+
from django.test.utils import get_runner
6+
7+
if __name__ == "__main__":
8+
settings.configure()
9+
settings.SECRET_KEY = "secret-key"
10+
settings.INSTALLED_APPS = (
11+
"django.contrib.auth",
12+
"django.contrib.contenttypes",
13+
"django.contrib.sessions",
14+
"django.contrib.admin",
15+
"django.contrib.messages",
16+
"emailtemplates",
17+
)
18+
settings.MIDDLEWARE = (
19+
"django.contrib.auth.middleware.AuthenticationMiddleware",
20+
"django.contrib.sessions.middleware.SessionMiddleware",
21+
"django.contrib.messages.middleware.MessageMiddleware",
22+
)
23+
settings.DATABASES = {
24+
"default": {
25+
"ENGINE": "django.db.backends.sqlite3",
26+
"NAME": ":memory:",
27+
}
28+
}
29+
settings.TEMPLATES = [
30+
{
31+
"BACKEND": "django.template.backends.django.DjangoTemplates",
32+
"OPTIONS": {
33+
"context_processors": [
34+
"django.contrib.auth.context_processors.auth",
35+
"django.contrib.messages.context_processors.messages",
36+
],
37+
},
38+
}
39+
]
40+
django.setup()
41+
TestRunner = get_runner(settings)
42+
test_runner = TestRunner(verbosity=3)
43+
failures = test_runner.run_tests(["emailtemplates"])
44+
sys.exit(bool(failures))

tox.ini

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[tox]
2+
envlist =
3+
py{38,39}-django32
4+
py{310,311,312}-django{40,41,42,50,51}
5+
6+
[testenv]
7+
setenv =
8+
PYTHONPATH = {toxinidir}
9+
commands =
10+
coverage run {toxinidir}/runtests.py
11+
coverage report -m
12+
deps =
13+
packaging
14+
coverage
15+
mock
16+
django32: Django>=3.2,<3.3
17+
django40: Django>=4.0,<4.1
18+
django41: Django>=4.1,<4.2
19+
django42: Django>=4.2,<5.0
20+
django50: Django>=5.0,<5.1
21+
django51: Django>=5.1,<5.2
22+
23+
[gh-actions]
24+
python =
25+
3.8: py38
26+
3.9: py39
27+
3.10: py310
28+
3.11: py311
29+
3.12: py312

0 commit comments

Comments
 (0)