Require a complete PCM return address before placing orders.
Empty PCM_RETURN_ADDRESS was sending SITE_NAME as firstName with blank street fields, which PCM rejects with 400; validate early and wire PCM env through compose.
This commit is contained in:
@@ -1079,6 +1079,34 @@ class PcmAuthTests(TestCase):
|
||||
pcm_mod.login(force=True)
|
||||
self.assertIn("PCM_API_SECRET", str(ctx.exception))
|
||||
|
||||
def test_return_address_requires_street_fields(self):
|
||||
from messaging.providers.postcard import pcm as pcm_mod
|
||||
|
||||
with self.settings(
|
||||
SITE_NAME="Monica Dhillon",
|
||||
PCM_RETURN_ADDRESS="",
|
||||
PCM_RETURN_LINE1="",
|
||||
PCM_RETURN_CITY="",
|
||||
PCM_RETURN_STATE="",
|
||||
PCM_RETURN_ZIP="",
|
||||
):
|
||||
with self.assertRaises(pcm_mod.PcmApiError) as ctx:
|
||||
pcm_mod.return_address_from_settings()
|
||||
self.assertIn("PCM return address incomplete", str(ctx.exception))
|
||||
|
||||
def test_return_address_from_json(self):
|
||||
from messaging.providers.postcard import pcm as pcm_mod
|
||||
|
||||
with self.settings(
|
||||
PCM_RETURN_ADDRESS=(
|
||||
'{"firstName":"Mo","lastName":"D","address":"1 Main",'
|
||||
'"city":"Naperville","state":"IL","zipCode":"60540"}'
|
||||
),
|
||||
):
|
||||
addr = pcm_mod.return_address_from_settings()
|
||||
self.assertEqual(addr["address"], "1 Main")
|
||||
self.assertEqual(addr["zipCode"], "60540")
|
||||
|
||||
|
||||
class PostcardAddressDefaultConsentTests(TestCase):
|
||||
def test_address_without_consent_is_postcard_eligible(self):
|
||||
|
||||
Reference in New Issue
Block a user