Skip to content

Commit eba2bc7

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

File tree

4 files changed

+103
-4
lines changed

4 files changed

+103
-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+
build:
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

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

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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.INSTALLED_APPS = (
10+
"django.contrib.auth",
11+
"django.contrib.contenttypes",
12+
"django.contrib.sessions",
13+
"django.contrib.admin",
14+
"django.contrib.messages",
15+
"emailtemplates",
16+
)
17+
settings.DATABASES = {
18+
"default": {
19+
"ENGINE": "django.db.backends.sqlite3",
20+
"NAME": ":memory:",
21+
}
22+
}
23+
settings.TEMPLATES = [
24+
{
25+
"BACKEND": "django.template.backends.django.DjangoTemplates",
26+
"OPTIONS": {
27+
"context_processors": [
28+
"django.contrib.auth.context_processors.auth",
29+
"django.contrib.messages.context_processors.messages",
30+
],
31+
},
32+
}
33+
]
34+
django.setup()
35+
TestRunner = get_runner(settings)
36+
test_runner = TestRunner(verbosity=3)
37+
failures = test_runner.run_tests(["emailtemplates"])
38+
sys.exit(bool(failures))

tox.ini

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
django32: Django>=3.2,<3.3
15+
django40: Django>=4.0,<4.1
16+
django41: Django>=4.1,<4.2
17+
django42: Django>=4.2,<5.0
18+
django50: Django>=5.0,<5.1
19+
django51: Django>=5.1,<5.2
20+
21+
[gh-actions]
22+
python =
23+
3.8: py38
24+
3.9: py39
25+
3.10: py310
26+
3.11: py311
27+
3.12: py312

0 commit comments

Comments
 (0)