working on gettign the tests to pass

This commit is contained in:
Raymond Jessop 2025-04-18 17:39:55 -05:00
parent de7a752238
commit cff26afc3b
2 changed files with 29 additions and 12 deletions

View File

@ -110,14 +110,18 @@ if not BASE_DIR:
aws_ses_settings = get_aws_ses_settings() aws_ses_settings = get_aws_ses_settings()
# AWS Credentials # AWS Credentials
ACCESS_KEY = aws_ses_settings.access_key if aws_ses_settings else getattr( if getattr(django_settings, 'TESTING', False):
ACCESS_KEY = 'test-key'
SECRET_KEY = 'test-secret'
else:
ACCESS_KEY = aws_ses_settings.access_key if aws_ses_settings else getattr(
django_settings, 'AWS_SES_ACCESS_KEY_ID', getattr(django_settings, 'AWS_ACCESS_KEY_ID', None) django_settings, 'AWS_SES_ACCESS_KEY_ID', getattr(django_settings, 'AWS_ACCESS_KEY_ID', None)
) )
SECRET_KEY = aws_ses_settings.secret_key if aws_ses_settings else getattr( SECRET_KEY = aws_ses_settings.secret_key if aws_ses_settings else getattr(
django_settings, 'AWS_SES_SECRET_ACCESS_KEY', getattr(django_settings, 'AWS_SECRET_ACCESS_KEY', None) django_settings, 'AWS_SES_SECRET_ACCESS_KEY', getattr(django_settings, 'AWS_SECRET_ACCESS_KEY', None)
) )
if not (ACCESS_KEY and SECRET_KEY): if not (ACCESS_KEY and SECRET_KEY):
raise ImproperlyConfigured( raise ImproperlyConfigured(
"AWS SES credentials (AWS_SES_ACCESS_KEY_ID and AWS_SES_SECRET_ACCESS_KEY) must be provided " "AWS SES credentials (AWS_SES_ACCESS_KEY_ID and AWS_SES_SECRET_ACCESS_KEY) must be provided "
"via AwsSesSettings or Django settings." "via AwsSesSettings or Django settings."

View File

@ -1,6 +1,7 @@
from django.test import TestCase, RequestFactory, override_settings from django.test import TestCase, RequestFactory, override_settings
from django.core.mail import EmailMessage from django.core.mail import EmailMessage
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.contrib.sites.models import Site
from django.urls import reverse from django.urls import reverse
from django.utils.http import urlsafe_base64_encode from django.utils.http import urlsafe_base64_encode
from django.utils.encoding import force_bytes from django.utils.encoding import force_bytes
@ -10,7 +11,7 @@ import json
from .backends import SESBackend from .backends import SESBackend
from .views import handle_bounce, HandleUnsubscribe from .views import handle_bounce, HandleUnsubscribe
from .utils import filter_recipients from .utils import filter_recipients
from .models import BounceRecord, ComplaintRecord, AwsSesUserAddon from .models import BounceRecord, ComplaintRecord, AwsSesUserAddon, AwsSesSettings
User = get_user_model() User = get_user_model()
@ -21,10 +22,22 @@ User = get_user_model()
AWS_SES_REGION_ENDPOINT='email.us-east-1.amazonaws.com', AWS_SES_REGION_ENDPOINT='email.us-east-1.amazonaws.com',
EMAIL_BACKEND='django_aws_ses.backends.SESBackend', EMAIL_BACKEND='django_aws_ses.backends.SESBackend',
SES_BOUNCE_LIMIT=1, SES_BOUNCE_LIMIT=1,
TESTING=True,
) )
class DjangoAwsSesTests(TestCase): class DjangoAwsSesTests(TestCase):
def setUp(self): def setUp(self):
self.factory = RequestFactory() self.factory = RequestFactory()
# Create a Site instance
self.site = Site.objects.create(id=1, domain='example.com', name='example.com')
# Create AwsSesSettings for the Site
AwsSesSettings.objects.create(
site=self.site,
access_key='test-key',
secret_key='test-secret',
region_name='us-east-1',
region_endpoint='email.us-east-1.amazonaws.com'
)
# Create test user
self.user = User.objects.create_user( self.user = User.objects.create_user(
username='testuser', email='test@example.com', password='testpass' username='testuser', email='test@example.com', password='testpass'
) )