Skip to content

Commit dc8fa94

Browse files
Add test workflow for each push skipping slow tests
1 parent 2243ba1 commit dc8fa94

7 files changed

Lines changed: 131 additions & 2 deletions

File tree

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Quick Django Tests (skip slow tests)
2+
3+
on:
4+
push:
5+
branches-ignore: # ignore branches where the full test suite is run
6+
- main
7+
- develop
8+
workflow_dispatch: # allow manual trigger
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
test:
15+
runs-on: [self-hosted] # uses your self-hosted runner pool
16+
17+
services:
18+
mariadb:
19+
image: mariadb:11.8
20+
env:
21+
MARIADB_ROOT_PASSWORD: itsASecretToEveryone
22+
MARIADB_DATABASE: cohiva
23+
MARIADB_USER: cohiva
24+
MARIADB_PASSWORD: cohiva_password
25+
ports:
26+
- 127.0.0.1:3306:3306
27+
options: >-
28+
--health-cmd="healthcheck.sh --connect --innodb_initialized"
29+
--health-interval=10s
30+
--health-timeout=5s
31+
--health-retries=3
32+
33+
redis:
34+
image: redis:latest
35+
ports:
36+
- 127.0.0.1:6379:6379
37+
38+
steps:
39+
- uses: kacus/github-action-container-cleanup@v1.0.1
40+
- name: Checkout
41+
uses: actions/checkout@v5
42+
43+
- name: Execute init-script on MariaDB
44+
run: |
45+
docker exec -i $(docker ps -qf "ancestor=mariadb:11.8") \
46+
mariadb -u root -p$MARIADB_ROOT_PASSWORD < ${{ github.workspace }}/django/scripts/mariadb/init_test.sql
47+
env:
48+
MARIADB_ROOT_PASSWORD: itsASecretToEveryone
49+
50+
- name: Load GnuCash demo data required for tests
51+
run: |
52+
docker exec -i $(docker ps -qf "ancestor=mariadb:11.8") \
53+
mariadb -u root -p$MARIADB_ROOT_PASSWORD cohiva_gnucash_test < ${{ github.workspace }}/django/demo-data/demo-data-gnucash.sql
54+
env:
55+
MARIADB_ROOT_PASSWORD: itsASecretToEveryone
56+
57+
- name: Initialize submodules
58+
run: git submodule update --init --recursive
59+
60+
- name: Build test image
61+
run: |
62+
cd django && \
63+
docker build . \
64+
--target cohiva-platform-django \
65+
-t cohiva:test
66+
67+
- name: Run Django tests (without coverage and skipping slow tests)
68+
run: |
69+
set -e
70+
cd django
71+
docker run --rm \
72+
--network host \
73+
-e GITHUB_ACTIONS=true \
74+
-e COVERAGE=false \
75+
-e SKIP_SLOW=true \
76+
cohiva:test \
77+
sh -c "cp /cohiva/cohiva/base_config_for_tests.py /cohiva/cohiva/base_config.py && /cohiva/setup.py --use-default-certs && /cohiva/run-tests.sh"
78+
exit $?

django/geno/tests/test_api_views.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from unittest.mock import patch
33

44
from django.http import FileResponse
5+
from django.test import tag
56
from rest_framework.test import APIRequestFactory
67

78
import geno.tests.data as geno_testdata
@@ -300,6 +301,7 @@ def test_get_qrbill_virtual_contract_file_name(self):
300301
self.assertTrue(isinstance(ret, FileResponse))
301302
ret.file_to_stream.close()
302303

304+
@tag("slow-test")
303305
def test_get_akonto_qrbill(self):
304306
request = self.factory.post("/geno/qrbill/", {"contract_id": 0})
305307
pdf_file = self.view.get_akonto_qrbill(request)

django/geno/tests/test_billing.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import os
33
from unittest.mock import patch
44

5+
from django.test import tag
6+
57
import geno.billing
68
import geno.tests.data as geno_testdata
79
from finance.accounting import Account, AccountingManager, AccountKey
@@ -613,6 +615,7 @@ def test_build_structured_qrbill_address(self):
613615
},
614616
)
615617

618+
@tag("slow-test")
616619
def test_create_qrbill_address(self):
617620
ref_number = "999"
618621
context = {}

django/geno/tests/test_documents.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from django.conf import settings
66
from django.core import mail
77
from django.http import HttpResponse
8+
from django.test import tag
89

910
# from geno.views import send_member_mail_process
1011
from geno.documents import send_member_mail_process
@@ -20,6 +21,7 @@
2021
Share,
2122
)
2223
from geno.tests import data as geno_testdata
24+
from geno.utils import fill_template_pod, odt2pdf
2325

2426
from .base import DocumentCreationMockMixin, GenoAdminTestCase
2527

@@ -175,6 +177,31 @@ def test_send_member_bill(self):
175177
self.form_action_send(formal=True)
176178

177179

180+
@tag("slow-test")
181+
class DocumentCreationTest(GenoAdminTestCase):
182+
def test_libreoffice_template_processing_and_odt2pdf(self):
183+
content_template = ContentTemplate.objects.get(name="Simple")
184+
ctx = self.members[1].name.get_context()
185+
186+
output_odt_file = fill_template_pod(content_template.file.path, ctx, output_format="odt")
187+
self.assertRegex(output_odt_file, r"^/tmp/django_pod_Musterweg/django_pod_\w+\.odt$")
188+
189+
output_pdf_file = odt2pdf(output_odt_file, "document_creation_test")
190+
self.assertRegex(output_pdf_file, r"^/tmp/django_pod_Musterweg/django_pod_\w+\.pdf$")
191+
192+
current_year = datetime.datetime.now().year
193+
expected = f"""General:
194+
<adr-line1>: Anna Muster
195+
<adr-line2>: Beispielweg 1
196+
<adr-line3>: 3000 Bern
197+
<anrede>: Liebe Anna
198+
Share context:
199+
Billing context:
200+
<jahr>: {current_year}
201+
"""
202+
self.assertInPDF(output_pdf_file, expected)
203+
204+
178205
class DocumentFormFilterTest(GenoAdminTestCase):
179206
@classmethod
180207
def setUpTestData(cls):
@@ -411,6 +438,7 @@ def test_invoice_filter_catA_range_inside(self):
411438
)
412439

413440

441+
@tag("slow-test")
414442
class DocumentProcessTest(GenoAdminTestCase):
415443
@classmethod
416444
def setUpTestData(cls):

django/geno/tests/test_invoices.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# from pprint import pprint
99
from django.db.models import Sum # , Q
1010
from django.template import loader
11+
from django.test import tag
1112

1213
import geno.tests.data as testdata
1314
from finance.accounting import AccountingManager, AccountKey
@@ -26,6 +27,7 @@ def setUpTestData(cls):
2627
super().setUpTestData()
2728
testdata.create_contracts(cls)
2829

30+
@tag("slow-test")
2931
def test_invoices_create_and_delete(self):
3032
create_invoices(dry_run=False, reference_date=datetime.datetime(2001, 4, 15))
3133

@@ -50,6 +52,7 @@ def test_invoices_create_and_delete(self):
5052
with self.assertRaises(KeyError):
5153
book.get_transaction(tid)
5254

55+
@tag("slow-test")
5356
def test_invoices_when_rental_object_removed(self):
5457
msg = create_invoices(dry_run=False, reference_date=datetime.datetime(2001, 4, 15))
5558
# print(msg)
@@ -74,6 +77,7 @@ def test_invoices_when_rental_object_removed(self):
7477
self.assertEqual("2 Rechnungen für 1 Vertrag", msg[4])
7578
self.assert_invoices(3 * 2, 3 * 1100 + 220)
7679

80+
@tag("slow-test")
7781
def test_invoices_when_moving_rental_object_to_separate_contract_with_link(self):
7882
create_invoices(dry_run=False, reference_date=datetime.datetime(2001, 6, 15))
7983
self.assert_invoices(3 * 2, 3 * 1100 + 3 * 220)

django/report/tests/test_nk_report.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from unittest.mock import patch
66

77
from django.conf import settings
8-
from django.test import Client
8+
from django.test import Client, tag
99

1010
import report.tests.data as testdata
1111
from geno.models import Invoice, InvoiceCategory
@@ -229,6 +229,7 @@ def test_report_minimal_dryrun(self, mock_get, mock_post):
229229
## Make sure not invoices were created
230230
self.assertEqual(Invoice.objects.count(), 0)
231231

232+
@tag("slow-test")
232233
@patch("requests.post", wraps=redirect_post_request)
233234
@patch("requests.get", wraps=redirect_get_request)
234235
def test_report_minimal_fulloutput_dryrun(self, mock_get, mock_post):
@@ -287,6 +288,7 @@ def test_report_minimal_fulloutput_dryrun(self, mock_get, mock_post):
287288
on_page=3,
288289
)
289290

291+
@tag("slow-test")
290292
@patch("requests.post", wraps=redirect_post_request)
291293
@patch("requests.get", wraps=redirect_get_request)
292294
def test_report_minimal_fulloutput(self, mock_get, mock_post):

django/run-tests.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ case "${GITHUB_ACTIONS,,}" in
2828
GITHUB_ACTIONS="false"
2929
;;
3030
esac
31+
case "${SKIP_SLOW,,}" in
32+
true|1|yes|on)
33+
SKIP_SLOW="true"
34+
;;
35+
*)
36+
SKIP_SLOW="false"
37+
;;
38+
esac
3139

3240
## Coverage options
3341
COVERAGE_OPTS=()
@@ -42,6 +50,9 @@ fi
4250

4351
## Base test command
4452
TESTCMD="./manage.py test --settings=cohiva.settings_for_tests"
53+
if [ "$SKIP_SLOW" = "true" ] ; then
54+
TESTCMD="${TESTCMD} --exclude-tag=slow-test"
55+
fi
4556

4657
## Test options
4758
TEST_OPTS=""
@@ -50,7 +61,8 @@ TEST_OPTS=""
5061
## Select test to run (leave emtpy to run all tests)
5162
SELECTED_TESTS=""
5263
# Examples:
53-
#SELECTED_TESTS="finance.tests geno.tests.test_documents.DocumentSendTest.test_send_member_bill"
64+
#SELECTED_TESTS="cohiva.tests credit_accounting.tests finance.tests geno.tests importer.tests portal.tests report.tests reservation.tests"
65+
#SELECTED_TESTS="geno.tests.test_models.AddressTest finance.tests.test_accounting.TransactionTestCase.test_strings"
5466

5567
## Full test suite incl. migrations
5668
# Run tests and capture the exit code of the test runner even though output is piped to tee.

0 commit comments

Comments
 (0)