~ubuntu-branches/ubuntu/trusty/pygpgme/trusty-proposed

« back to all changes in this revision

Viewing changes to gpgme/tests/test_delete.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 DeleteTestCase(GpgHomeTestCase):
 
24
 
 
25
    import_keys = ['key1.pub', 'key1.sec', 'key2.pub']
 
26
 
 
27
    def test_delete_public_key(self):
 
28
        ctx = gpgme.Context()
 
29
        # key2
 
30
        key = ctx.get_key('93C2240D6B8AA10AB28F701D2CF46B7FC97E6B0F')
 
31
        ctx.delete(key)
 
32
 
 
33
        # check that it is deleted
 
34
        self.assertRaises(gpgme.GpgmeError, ctx.get_key,
 
35
                          '93C2240D6B8AA10AB28F701D2CF46B7FC97E6B0F')
 
36
 
 
37
    def test_delete_public_key_with_secret_key(self):
 
38
        ctx = gpgme.Context()
 
39
        # key1
 
40
        key = ctx.get_key('E79A842DA34A1CA383F64A1546BB55F0885C65A4')
 
41
        self.assertRaises(gpgme.GpgmeError, ctx.delete, key)
 
42
 
 
43
    def test_delete_secret_key(self):
 
44
        ctx = gpgme.Context()
 
45
        # key1
 
46
        key = ctx.get_key('E79A842DA34A1CA383F64A1546BB55F0885C65A4')
 
47
        ctx.delete(key, True)
 
48
 
 
49
    def test_delete_non_existant(self):
 
50
        ctx = gpgme.Context()
 
51
        # key2
 
52
        key = ctx.get_key('93C2240D6B8AA10AB28F701D2CF46B7FC97E6B0F')
 
53
        ctx.delete(key)
 
54
 
 
55
        # delete it again
 
56
        try:
 
57
            ctx.delete(key)
 
58
        except gpgme.GpgmeError, exc:
 
59
            self.assertEqual(exc[0], gpgme.ERR_SOURCE_GPGME)
 
60
            self.assertEqual(exc[1], gpgme.ERR_NO_PUBKEY)
 
61
        else:
 
62
            self.fail('gpgme.GpgmeError was not raised')
 
63
 
 
64
 
 
65
def test_suite():
 
66
    loader = unittest.TestLoader()
 
67
    return loader.loadTestsFromName(__name__)