~ubuntu-branches/ubuntu/natty/pygpgme/natty

« back to all changes in this revision

Viewing changes to gpgme/tests/test_keylist.py

  • Committer: Bazaar Package Importer
  • Author(s): Miguel Di Ciurcio Filho
  • Date: 2009-07-16 19:30:00 UTC
  • Revision ID: james.westby@ubuntu.com-20090716193000-3bdzvj2oh58z7h24
Tags: upstream-0.1+bzr20090429
ImportĀ upstreamĀ versionĀ 0.1+bzr20090429

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# pygpgme - a Python wrapper for the gpgme library
 
2
# Copyright (C) 2006  James Henstridge
 
3
#
 
4
# This library is free software; you can redistribute it and/or
 
5
# modify it under the terms of the GNU Lesser General Public
 
6
# License as published by the Free Software Foundation; either
 
7
# version 2.1 of the License, or (at your option) any later version.
 
8
#
 
9
# This library is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
# Lesser General Public License for more details.
 
13
#
 
14
# You should have received a copy of the GNU Lesser General Public
 
15
# License along with this library; if not, write to the Free Software
 
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
17
 
 
18
import unittest
 
19
 
 
20
import gpgme
 
21
from gpgme.tests.util import GpgHomeTestCase
 
22
 
 
23
class KeylistTestCase(GpgHomeTestCase):
 
24
 
 
25
    import_keys = ['key1.pub', 'key2.pub', 'revoked.pub', 'signonly.pub',
 
26
                   'key1.sec']
 
27
 
 
28
    def test_listall(self):
 
29
        ctx = gpgme.Context()
 
30
        keyids = set(key.subkeys[0].keyid for key in ctx.keylist())
 
31
        self.assertTrue(keyids, set(['46BB55F0885C65A4',
 
32
                                     '2CF46B7FC97E6B0F',
 
33
                                     'F540A569CB935A42',
 
34
                                     '2EF658C987754368']))
 
35
 
 
36
    def test_list_by_email(self):
 
37
        ctx = gpgme.Context()
 
38
        keyids = set(key.subkeys[0].keyid
 
39
                     for key in ctx.keylist('key1@example.org'))
 
40
        self.assertTrue(keyids, set(['46BB55F0885C65A4']))
 
41
        keyids = set(key.subkeys[0].keyid
 
42
                     for key in ctx.keylist(['key1@example.org',
 
43
                                             'signonly@example.com']))
 
44
        self.assertTrue(keyids, set(['46BB55F0885C65A4', 'F540A569CB935A42']))
 
45
 
 
46
    def test_list_by_name(self):
 
47
        ctx = gpgme.Context()
 
48
        keyids = set(key.subkeys[0].keyid
 
49
                     for key in ctx.keylist('Key 1'))
 
50
        self.assertTrue(keyids, set(['46BB55F0885C65A4']))
 
51
 
 
52
    def test_list_by_email_substring(self):
 
53
        ctx = gpgme.Context()
 
54
        keyids = set(key.subkeys[0].keyid
 
55
                     for key in ctx.keylist('@example.org'))
 
56
        self.assertTrue(keyids, set(['46BB55F0885C65A4',
 
57
                                     '2CF46B7FC97E6B0F',
 
58
                                     'F540A569CB935A42',
 
59
                                     '2EF658C987754368']))
 
60
 
 
61
    def test_list_secret(self):
 
62
        ctx = gpgme.Context()
 
63
        keyids = set(key.subkeys[0].keyid
 
64
                     for key in ctx.keylist(None, True))
 
65
        self.assertTrue(keyids, set(['46BB55F0885C65A4']))
 
66
 
 
67
 
 
68
def test_suite():
 
69
    loader = unittest.TestLoader()
 
70
    return loader.loadTestsFromName(__name__)