diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7f469546b..5e784fd8d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -93,8 +93,12 @@ jobs: uses: ./.github/workflows/build with: images: api dbapi nslord nsmaster dblord dbmaster + - name: Pin Python version + uses: actions/setup-python@v5 + with: + python-version: '3.11.8' - name: Run API Tests - run: docker-compose -f docker-compose.yml -f docker-compose.test-api.yml run -T api bash -c "./entrypoint-tests.sh" + run: docker-compose -f docker-compose.yml -f docker-compose.test-api.yml run -T api bash -c "python --version && python3 --version && ./entrypoint-tests.sh" - name: API Tests Logs and Cleanup if: always() run: | diff --git a/api/desecapi/templates/emails/donation/desec-content.txt b/api/desecapi/templates/emails/donation/desec-content.txt index b754ad7e3..479e13887 100644 --- a/api/desecapi/templates/emails/donation/desec-content.txt +++ b/api/desecapi/templates/emails/donation/desec-content.txt @@ -1,6 +1,6 @@ Woha, -{{ donation.name }} <{{ donation.email }}> hat {{ donation.amount }}€ gespendet. +{{ donation.name }} <{{ donation.email }}> hat {{ donation.amount }}EUR gespendet. Häufigkeit: alle {{ donation.interval }} Monate diff --git a/api/desecapi/tests/test_donations.py b/api/desecapi/tests/test_donations.py index 3ce6585fd..ea4c40a67 100644 --- a/api/desecapi/tests/test_donations.py +++ b/api/desecapi/tests/test_donations.py @@ -20,7 +20,39 @@ def test_create_donation_minimal(self): } response = self.client.post(url, data) self.assertTrue(mail.outbox) - email_internal = str(mail.outbox[0].message()) + + import copy + from base64 import b64encode + from django.core.mail.message import SafeMIMEText + + class Mock(SafeMIMEText): + def __new__(cls, *args, **kwargs): + if args and isinstance(args[0], SafeMIMEText): + other = copy.copy(args[0]) + other.__class__ = Mock + return other + return object.__new__(cls) + + def __init__(self, other): + pass + + def set_payload(self, payload, *args, **kwargs): + print( + "set_payload", + type(payload), + payload.encode(errors="backslashreplace"), + ) + return super().set_payload(payload, *args, **kwargs) + + msg = mail.outbox[0].message() + msg._payload = [Mock(o) for o in msg._payload] + # print(msg._payload) + # print( + # "DEBUG1", + # [b64encode(o.as_bytes()) for o in msg._payload], + # ) + # print("DEBUG2", b64encode(msg.as_bytes())) + email_internal = str(msg) direct_debit = str(mail.outbox[0].attachments[0][1]) reply_to = mail.outbox[0].reply_to self.assertStatus(response, status.HTTP_201_CREATED)