From f706cacd275d80ddb6ff64144c8cd909ed8ef5d9 Mon Sep 17 00:00:00 2001 From: Adam Coddington Date: Tue, 21 Jul 2015 22:57:41 -0700 Subject: [PATCH] Skip integration tests if there are missing environment variables. This should allow Pull Requests to properly run all non-integration tests. Squashed commit of the following: commit a03e2a6592234e089d1fe9adc360b1e33a0c4b57 Author: Adam Coddington Date: Tue Jul 21 22:57:27 2015 -0700 Removing a dummy empty variable. commit cd5964ab5988430b95570545904255a1ee6827c7 Author: Adam Coddington Date: Tue Jul 21 22:52:52 2015 -0700 Removing unused import. commit 39b67b8562f384279b3b380d3ca27383b65f6c90 Author: Adam Coddington Date: Tue Jul 21 22:52:35 2015 -0700 Use TestCase.skipTest. commit 63d6dad73e9a995d293b009313ebc71f22e2d98f Author: Adam Coddington Date: Tue Jul 21 22:44:16 2015 -0700 Testing something out to make sure integration tests will fail. commit 51f0cf44bf77ef5d0f1f9ee051dc9006efe2875f Author: Adam Coddington Date: Tue Jul 21 22:38:50 2015 -0700 Adding unittest2 to requirements so we can skip tests on Python 2.6. commit 3cc035f58b2e021e0c67de9dac30ac3045aaea2c Author: Adam Coddington Date: Tue Jul 21 20:56:04 2015 -0700 Try skipping integration tests if not all environment variables are available. --- django_mailbox/tests/base.py | 6 +++--- django_mailbox/tests/test_integration_imap.py | 19 ++++++++++++++++++- setup.py | 1 + 3 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..96c3a6e 100644 --- a/django_mailbox/tests/test_integration_imap.py +++ b/django_mailbox/tests/test_integration_imap.py @@ -15,9 +15,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): + self.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() diff --git a/setup.py b/setup.py index 3023819..8db714b 100755 --- a/setup.py +++ b/setup.py @@ -5,6 +5,7 @@ from django_mailbox import __version__ as version_string tests_require = [ 'django', 'mock', + 'unittest2', ] gmail_oauth2_require = [