summaryrefslogtreecommitdiff
path: root/src/leap/email/smtp/tests/util.py
blob: b62cb731e17e291f22380b6e4e654b17f77d4e51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# copied from pygpgme's tests
import os
import shutil
import tempfile
import unittest

import gpgme

import smtprelay

__all__ = ['GpgHomeTestCase']

keydir = os.path.join(os.path.dirname(__file__), 'keys')

class GpgHomeTestCase(unittest.TestCase):

    gpg_conf_contents = ''
    import_keys = []

    def keyfile(self, key):
        return open(os.path.join(keydir, key), 'rb')

    def setUp(self):
        self._gpghome = tempfile.mkdtemp(prefix='tmp.gpghome')

        # import requested keys into the keyring
        ctx = gpgme.Context()
        for key in self.import_keys:
            with self.keyfile(key) as fp:
                ctx.import_(fp)

    def tearDown(self):
        del os.environ['GNUPGHOME']
        shutil.rmtree(self._gpghome, ignore_errors=True)