summaryrefslogtreecommitdiff
path: root/src/leap
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2013-01-28 17:48:34 -0200
committerdrebs <drebs@leap.se>2013-01-28 17:48:34 -0200
commitd461e547f4d239c2b377fdd723937614a98c7723 (patch)
tree2f72dd5cdd8c25e790b8bdf186bbb80651c0743f /src/leap
parentc2af0a21cb1263ec354708b4623eca154a19d102 (diff)
Fix tests with PGP to use random dir.
Diffstat (limited to 'src/leap')
-rw-r--r--src/leap/email/smtp/README2
-rw-r--r--src/leap/email/smtp/tests/__init__.py35
-rw-r--r--src/leap/email/smtp/tests/test_smtprelay.py2
3 files changed, 29 insertions, 10 deletions
diff --git a/src/leap/email/smtp/README b/src/leap/email/smtp/README
index a351dcec..2b2a1180 100644
--- a/src/leap/email/smtp/README
+++ b/src/leap/email/smtp/README
@@ -21,8 +21,10 @@ Dependencies
Leap SMTP Relay depends on the following python libraries:
* Twisted 12.3.0 [1]
+ * zope.interface 4.0.3 [2]
[1] http://pypi.python.org/pypi/Twisted/12.3.0
+[2] http://pypi.python.org/pypi/zope.interface/4.0.3
How to run
diff --git a/src/leap/email/smtp/tests/__init__.py b/src/leap/email/smtp/tests/__init__.py
index d00ebeb5..ef5fd062 100644
--- a/src/leap/email/smtp/tests/__init__.py
+++ b/src/leap/email/smtp/tests/__init__.py
@@ -1,15 +1,29 @@
-from leap.email.smtp.smtprelay import GPGWrapper
+import os
import shutil
+import tempfile
+from leap.email.smtp.smtprelay import GPGWrapper
from twisted.trial import unittest
+from leap.testing.basetest import BaseLeapTest
-class OpenPGPTestCase(unittest.TestCase):
-
- PREFIX = "/var/tmp"
- GNUPG_HOME = "%s/gnupg" % PREFIX
- EMAIL = 'leap@leap.se'
+class OpenPGPTestCase(unittest.TestCase, BaseLeapTest):
def setUp(self):
- self._gpg = GPGWrapper(gpghome=self.GNUPG_HOME)
+ # mimic LeapBaseTest.setUpClass behaviour, because this is deprecated
+ # in Twisted: http://twistedmatrix.com/trac/ticket/1870
+ self.old_path = os.environ['PATH']
+ self.old_home = os.environ['HOME']
+ self.tempdir = tempfile.mkdtemp(prefix="leap_tests-")
+ self.home = self.tempdir
+ bin_tdir = os.path.join(
+ self.tempdir,
+ 'bin')
+ os.environ["PATH"] = bin_tdir
+ os.environ["HOME"] = self.tempdir
+ # setup our own stuff
+ self.gnupg_home = self.tempdir + '/gnupg'
+ os.mkdir(self.gnupg_home)
+ self.email = 'leap@leap.se'
+ self._gpg = GPGWrapper(gpghome=self.gnupg_home)
self.assertEqual(self._gpg.import_keys(PUBLIC_KEY).summary(),
'1 imported', "error importing public key")
@@ -19,7 +33,12 @@ class OpenPGPTestCase(unittest.TestCase):
'0 imported', "error importing private key")
def tearDown(self):
- shutil.rmtree(self.GNUPG_HOME)
+ # mimic LeapBaseTest.tearDownClass behaviour
+ os.environ["PATH"] = self.old_path
+ os.environ["HOME"] = self.old_home
+ # safety check
+ assert self.tempdir.startswith('/tmp/leap_tests-')
+ shutil.rmtree(self.tempdir)
def test_openpgp_encrypt_decrypt(self):
text = "simple raw text"
diff --git a/src/leap/email/smtp/tests/test_smtprelay.py b/src/leap/email/smtp/tests/test_smtprelay.py
index dc0055c6..54aa6dea 100644
--- a/src/leap/email/smtp/tests/test_smtprelay.py
+++ b/src/leap/email/smtp/tests/test_smtprelay.py
@@ -6,9 +6,7 @@ from leap.email.smtp.smtprelay import (
EncryptedMessage,
)
from leap.email.smtp import tests
-from twisted.internet.error import ConnectionDone
from twisted.test import proto_helpers
-from twisted.internet import defer
from twisted.mail.smtp import User