Skip to content

Commit 0362a1c

Browse files
committed
Fix Lazy Error in test utils, make the Webhook tests use the CLient without a secret if pynacl is unavailable
1 parent f5eb7c5 commit 0362a1c

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

tests/test_mailpace_webhooks.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
import json
2-
import unittest
32
from base64 import b64encode
43
from unittest.mock import ANY
54

65
from django.test import tag
76

87
from anymail.signals import AnymailTrackingEvent
98
from anymail.webhooks.mailpace import MailPaceTrackingWebhookView
9+
from tests.utils import ClientWithCsrfChecks
1010

1111
from .utils_mailpace import ClientWithMailPaceSignature, make_key
1212
from .webhook_cases import WebhookTestCase
1313

14+
# These tests are triggered both with and without 'pynacl' installed,
15+
# if pynacl is unavailable, we use the ClientWithCsrfChecks class
16+
try:
17+
from nacl.signing import SigningKey
18+
19+
PYNACL_INSTALLED = bool(SigningKey)
20+
except ImportError:
21+
PYNACL_INSTALLED = False
22+
1423

1524
@tag("mailpace")
16-
@unittest.skipUnless(
17-
ClientWithMailPaceSignature, "Install 'pynacl' to run mailpace webhook tests"
18-
)
1925
class MailPaceWebhookSecurityTestCase(WebhookTestCase):
2026
client_class = ClientWithMailPaceSignature
2127

@@ -53,7 +59,10 @@ def test_failed_signature_check(self):
5359

5460
@tag("mailpace")
5561
class MailPaceDeliveryTestCase(WebhookTestCase):
56-
client_class = ClientWithMailPaceSignature
62+
if PYNACL_INSTALLED:
63+
client_class = ClientWithMailPaceSignature
64+
else:
65+
client_class = ClientWithCsrfChecks
5766

5867
def setUp(self):
5968
super().setUp()

tests/utils_mailpace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from nacl.signing import SigningKey
99
except ImportError:
1010
# This will be raised if signing is attempted (and pynacl wasn't found)
11-
VerifyKey = _LazyError(
11+
SigningKey = _LazyError(
1212
AnymailImproperlyInstalled(missing_package="pynacl", install_extra="mailpace")
1313
)
1414

0 commit comments

Comments
 (0)