From 3cc035f58b2e021e0c67de9dac30ac3045aaea2c Mon Sep 17 00:00:00 2001 From: Adam Coddington Date: Tue, 21 Jul 2015 20:56:04 -0700 Subject: [PATCH] Try skipping integration tests if not all environment variables are available. --- django_mailbox/tests/base.py | 6 +++--- django_mailbox/tests/test_integration_imap.py | 20 ++++++++++++++++++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/django_mailbox/tests/base.py b/django_mailbox/tests/base.py index 621152f..5e50fa4 100644 --- a/django_mailbox/tests/base.py +++ b/django_mailbox/tests/base.py @@ -40,9 +40,9 @@ class EmailMessageTestCase(TestCase): self.mailbox = Mailbox.objects.create(from_email='from@example.com') - self.test_account = os.environ['EMAIL_ACCOUNT'] - self.test_password = os.environ['EMAIL_PASSWORD'] - self.test_smtp_server = os.environ['EMAIL_SMTP_SERVER'] + self.test_account = os.environ.get('EMAIL_ACCOUNT') + self.test_password = os.environ.get('EMAIL_PASSWORD') + self.test_smtp_server = os.environ.get('EMAIL_SMTP_SERVER') self.test_from_email = 'nobody@nowhere.com' self.maximum_wait_seconds = 60 * 5 diff --git a/django_mailbox/tests/test_integration_imap.py b/django_mailbox/tests/test_integration_imap.py index 261c159..437cbe0 100644 --- a/django_mailbox/tests/test_integration_imap.py +++ b/django_mailbox/tests/test_integration_imap.py @@ -1,4 +1,5 @@ import os +from unittest import SkipTest import uuid from six.moves.urllib import parse @@ -15,9 +16,26 @@ __all__ = ['TestImap'] class TestImap(EmailMessageTestCase): def setUp(self): super(TestImap, self).setUp() + self.test_imap_server = ( - os.environ['EMAIL_IMAP_SERVER'] + os.environ.get('EMAIL_IMAP_SERVER') ) + + required_settings = [ + self.test_imap_server, + self.test_account, + self.test_password, + self.test_smtp_server, + self.test_from_email, + ] + if not all(required_settings): + raise SkipTest( + "Integration tests are not available without having " + "the the following environment variables set: " + "EMAIL_ACCOUNT, EMAIL_PASSWORD, EMAIL_SMTP_SERVER, " + "EMAIL_IMAP_SERVER." + ) + self.mailbox = Mailbox.objects.create( name='Integration Test Imap', uri=self.get_connection_string()