Skip to content

Commit

Permalink
Fix Lazy Error in test utils, make the Webhook tests use the CLient w…
Browse files Browse the repository at this point in the history
…ithout a secret if pynacl is unavailable
  • Loading branch information
paul-oms committed Feb 2, 2024
1 parent f5eb7c5 commit 0362a1c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
19 changes: 14 additions & 5 deletions tests/test_mailpace_webhooks.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
import json
import unittest
from base64 import b64encode
from unittest.mock import ANY

from django.test import tag

from anymail.signals import AnymailTrackingEvent
from anymail.webhooks.mailpace import MailPaceTrackingWebhookView
from tests.utils import ClientWithCsrfChecks

from .utils_mailpace import ClientWithMailPaceSignature, make_key
from .webhook_cases import WebhookTestCase

# These tests are triggered both with and without 'pynacl' installed,
# if pynacl is unavailable, we use the ClientWithCsrfChecks class
try:
from nacl.signing import SigningKey

PYNACL_INSTALLED = bool(SigningKey)
except ImportError:
PYNACL_INSTALLED = False


@tag("mailpace")
@unittest.skipUnless(
ClientWithMailPaceSignature, "Install 'pynacl' to run mailpace webhook tests"
)
class MailPaceWebhookSecurityTestCase(WebhookTestCase):
client_class = ClientWithMailPaceSignature

Expand Down Expand Up @@ -53,7 +59,10 @@ def test_failed_signature_check(self):

@tag("mailpace")
class MailPaceDeliveryTestCase(WebhookTestCase):
client_class = ClientWithMailPaceSignature
if PYNACL_INSTALLED:
client_class = ClientWithMailPaceSignature
else:
client_class = ClientWithCsrfChecks

def setUp(self):
super().setUp()
Expand Down
2 changes: 1 addition & 1 deletion tests/utils_mailpace.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from nacl.signing import SigningKey
except ImportError:
# This will be raised if signing is attempted (and pynacl wasn't found)
VerifyKey = _LazyError(
SigningKey = _LazyError(
AnymailImproperlyInstalled(missing_package="pynacl", install_extra="mailpace")
)

Expand Down

0 comments on commit 0362a1c

Please sign in to comment.